-
Notifications
You must be signed in to change notification settings - Fork 66
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
Move all JS codegeneration to the generate-js
pass
#117
Conversation
It seems like this would introduce confusion with regards to es6 classes? |
I would like to understand what this means better, please I assume this doesn't prevent |
I mean, that if you wrote a plugin that attached a pass to the let myPass = visitor.build({
grammar(node) {
let consts = node.consts;// Uhh... where it now!?
// use consts
}
}); your plugin in a risk group. |
There's almost no peg plugins. This is in some way a different product. This doesn't appear to interfere with the coffeescript or typescript plugins. I'm mostly in support of this, despite that it is a breaking change, because it's a very minor breakage in a feature that's mostly unused. I think I'd be in total support of this when I knew:
|
|
yeah the eval is a problem, it makes a lot of build tools angry (and rightfully so) in addition to being a security win, it'll also be a pretty big speed win, i suspect |
i support this pr |
We already have a bunch of bits that refer to character classes |
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.
@Mingun if you rebase this, I'd be happy to merge it next. |
I've rebased and change |
652b4e0
to
1ce2528
Compare
Is this the next patch to land? It needs a rebase onto main at least, to resolve the conflicts, but I'll go through it with a closer eye if we're about ready. |
…on by content types into: * `literals` -- for literal expressions, like `'a'` * `classes` -- for character class expressions, like `[a]` * `expectations` -- for constants describing expected values when parse failed * `functions` -- for constants with function code
…rating to `generateJs` pass from `generateBytecode` pass. That allows to generate parser on other languages and more easy replace actions. Also, this is helpful for better hiding of the peggy internals from an initializers and functions code, which is needed for the import feature. After this commit, a function code (semantic predicates and actions) is stored in the `functions` field of the grammar node instead of the `consts` field. This is also opens doors for supporting source maps, because we get a place for the storing information about the original positions of the codes
…eneration to `generateJs` pass from `generateBytecode` pass.
…ting to `generateJs` pass from `generateBytecode` pass.
…ation to pass `generateJs` from pass `generateBytecode`.
…pdate CHANGELOG.md
Yes, it is ready for review. I've made a rebase so please review. |
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.
Other than finishing the backward-compat discussion for plugins, this is ready to go.
Note for myself later: the escaping routines are not new, they were just moved from a now-unnecessary separate file. I think we should discuss how we're doing regexp and string escaping in #15, since we'll need to touch this code then anyway.
@@ -4,52 +4,52 @@ | |||
const opcodes = { | |||
// Stack Manipulation | |||
|
|||
PUSH: 0, // PUSH c |
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.
Doesn't this (as an example of several opcode changes) conflict with the typescript plugin? Is @metadevpro following the work here yet? How could they support both peggy and pegjs if they wanted?
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.
It will. Instead of renaming that opcode we can just leave it unused and introduce a new opcode for PUSH_EMPTY_STRING
. Renaming MATCH_REGEXP
also should be reverted. Also we could add an alias instead of renaming or just do nothing. Then in version 2.0 we could completely remove the unused opcode.
On the other hand, @metadevpro could create a local copy of opcodes, he anyway is not needed to use exactly the same opcodes as peggy used because they used only as a glue between generate-bytecode-ts and generate-ts passes.
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.
OK, my suggestion from your choices above:
- Leave
PUSH
as 0. Mark it as deprecated with a comment. - Create a new opcode for
PUSH_EMPTY_STRING
- Leave
MATCH_CHAR_CLASS
andMATCH_REGEXP
both as opcode 20, but markMATCH_REGEXP
as deprecated with a comment.
I think this will allow plugins to support both peggy and pegjs at the same time adequately. If you expect that plugins would need to take different actions for MATCH_CHAR_CLASS
and MATCH_REGEXP
, then don't alias them together, and instead leave MATCH_REGEXP
as opcode 20, create a new opcode for MATCH_CHAR_CLASS
.
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.
All done as you said. I've make a rebase , changed only the last and the pre-pre-last commits. MATCH_REGEXP
and PUSH
marked @deprecated
, noted this in the CHANGELOG.md
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.
Thanks!
…GEXP` -> `MATCH_CHAR_CLASS`. New name reflects the opcode purpose, not implementation.
…h PUSH_EMPTY_STRING opcode because it only used with empty strings
Port of my PR to solve that problem: pegjs/pegjs#450.
Besides solving the original incapsulation problems, this PR also opens doors for the source map support (#105) by introducing place where original position information can be stored.
I'm not sure, should this be considered as breaking change or not. Strictly speaking, that it is, because it:
consts
member from thegrammar
node, which some third-party passes can expect (I can restore that, but if third-party passes modifies it, that modifications will not have the effect)MATCH_REGEXP
toMATCH_CLASS
(not strictly necessary, can be removed).So if that changes is unacceptable now, can be held that until release 2.0.
Fixes #106