Skip to content
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 28 commits into from
Nov 17, 2023
Merged

feat: new parser #55

merged 28 commits into from
Nov 17, 2023

Conversation

albertolerda
Copy link
Member

No description provided.

denizenging and others added 28 commits October 10, 2023 17:05
# 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
@albertolerda albertolerda merged commit b2835a8 into main Nov 17, 2023
3 checks passed
@denizenging denizenging deleted the sf/new-parser branch November 18, 2023 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants