-
Notifications
You must be signed in to change notification settings - Fork 67
Soft mode #502
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
Soft mode #502
Conversation
Once #593 lands, can you rebase this, please? I'll play around with it to see if it makes sense to go into the next major release. I think there's a semver-major breaking change with existing grammars that use the custom option We will also need docs, but don't bother with those until this gets rebased and I try it out. |
ok, I'm ready for this to be rebased, please. |
2cb51c0
to
5efe716
Compare
Rebased. CI tests seem to pass even though locally I have three tests failing when running |
Great. I will take a look at this and make a crisp decision before landing #602. |
Can you remove node_modules, do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a command line option?
lib/peg.d.ts needs to be updated, as well as the type tests in test/types/peg.test-d.ts
lib/.eslintrc.json
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file isn't used anymore, and we should be in ES2020 on main, so this shouldn't be needed anyway, I hope.
lib/compiler/passes/generate-js.js
Outdated
" if (peg$result !== peg$FAILED && peg$currPos === input.length) {", | ||
" return peg$result;", | ||
" } else {", | ||
" var success = (peg$result !== peg$FAILED && peg$currPos === input.length);", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be const
now instead of var
.
lib/compiler/passes/generate-js.js
Outdated
@@ -1373,6 +1372,14 @@ function generateJS(ast, options) { | |||
" : peg$computeLocation(peg$maxFailPos, peg$maxFailPos)", | |||
" );", | |||
" }", | |||
" if (options.soft) {", | |||
" return {result: peg$result, success, fail};", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If success
is true, maybe fail
should be undefined? Calling it will always give unexpected results on success.
const parser = peg.generate("start = 'a'"); | ||
|
||
const result = parser.parse("a", { soft: true }); | ||
expect(result.result).to.equal("a"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check that fail is undefined.
Overall, I'm +1 on this, but it needs a few tweaks. |
Apologies, but I just realized that this code should build on the |
They do not. I'll chalk it off to running an old Ubuntu locally. |
Can you copy over the error you're seeing into this discussion, please? |
Changed |
|
Oh. That's because you had a test fail, and you need to clean up the files that got left over. Delete the files that the error says, and it it should work cleanly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two minor nits and this is ready to go.
Thanks! |
ref #501