-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: new parser #55
Merged
Merged
feat: new parser #55
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Conflicts: # lerna.json # pkg/browser/package.json # pkg/browser/src/index.ts # pkg/core/test/slangroom.ts # pkg/core/test/visitor.ts # pkg/ethereum/src/visitor.ts # pkg/http/src/parser.ts # pkg/http/src/plugin.ts # pkg/http/src/tokens.ts # pkg/http/src/visitor.ts
This new core here eases the heavy work on the developer by simplifing the API while keeping all the things we want. At first, we used to use Chevrotain with a method that didn't allow method that didn't allow us to detect the individual syntax errors of a custom statement we defined. I worked around that issue by casting black-magic spells over Chevrotain internals. I hated that solution, but at that time, it was the most practicle one. Now, here, I introduce the new core with its new lexer/parser/visitor that is smart enough to cover most of our real-world needs. The visitor is in perfect Shape shape. The lexer is almost perfect, perhaps needs just a little bit of polishing, but it is the one that is the simplest. The parser is smart enough to cover most of our real-world cases, but it also needs some treatment. I'm planning to have a ranking system over it. Currently, it uses the number of errors detected on a statement, and using that, it ranks its matches. This solution appears to be quite reliable in practice. The way we use the API is quite simple ("Given I" parts can also be "Then I"): import {Plugin} from '@slangroom/core' const p = new Plugin(); const cb = (ctx) => ctx.fail('example') // cb is called when statement is matched p.new('love asche', cb) // -> Given I love Asche p.new('open', 'read file contents', cb) // -> Given I open 'ident' and read file contents p.new('connect', 'send http request', cb) // -> Given I connect to 'ident' and send http request p.new(['base32'], 'convert to base64', cb) // -> Given I send base32 'ident' and convert to base64 p.new('connect', ['object', 'proxy'], 'send http request', cb) // -> Given I connect to 'ident' and send object 'ident' and send proxy 'ident' and send http request export const myPlugin = p;
# Conflicts: # lerna.json # pkg/core/src/index.ts # pkg/core/src/lexer.ts # pkg/core/src/parser.ts # pkg/core/src/plugin.ts # pkg/core/src/slangroom.ts # pkg/core/src/visitor.ts # pkg/core/test/slangroom.ts # pkg/core/test/visitor.ts # pkg/ethereum/src/index.ts # pkg/ethereum/src/parser.ts # pkg/ethereum/src/plugin.ts # pkg/ethereum/test/e2e.ts # pkg/ethereum/test/plugin.ts # pkg/http/src/index.ts # pkg/http/src/parser.ts # pkg/http/src/plugin.ts # pkg/http/test/plugin.ts # pnpm-lock.yaml
Currently, the tests fail for some reason.
# Conflicts: # pnpm-lock.yaml
# Conflicts: # pnpm-lock.yaml
# Conflicts: # pkg/core/src/parser.ts # pkg/core/test/parser.ts
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.