Conversation
…n other grammars.
Mingun
left a comment
There was a problem hiding this comment.
I agree that we need something like this. I cannot say what implementation would the best.
Your overall idea is to build state object each time when parser finish it work and pass it to other parsers via options, each field separately. The other way to do the same is to have a state object and pass it around, but this could have performance implications. That state object could be part of API. Theoretically, we even can put into state some parsing functions that is independent of a parser (parseAny, parseLiteral, parseClass), but that will require us to have a runtime.
|
I agree with you about passing a state object around. That might be cleaner, but probably a hair slower. The other thing I don't like is setting up all of the constants each time a remote rule runs. A good JS runtime will probably make that not a big problem, but it's still hard to read. I'd like to get the interface right here, we can always optimize the generated code better later. I'm going to land a few more changes on top of this before merging to see what happens. |
|
From the PR description:
The needed what? |
sorry. Has the needed properties for parsing to continue on with the appropriate state. |
|
This still needs docs. |
|
Managed to import a rule from a package hosted on GitHub: https://github.com/frostburn/peggy-string-concat/blob/main/index.peggy |
| import bar from "./lib.js" // Default rule | ||
| import {baz} from "./lib.js" // One rule imported into this namespace | ||
| import { | ||
| boo, bab, |
There was a problem hiding this comment.
According to Wikipedia the canonical metasyntactic variables are foo, bar, baz, qux, quux, etc.
There was a problem hiding this comment.
I don't think this is worth changing in a test.
Did you check in those changes to peggy-string-concat? I was expecting to see an |
I'm not sure what you're asking. I changed my peggy dependencies in both repositories to |
I'm not either. After looking again and trying your code, it works great, exactly as expected. I appreciate your work! |
This is an internal-only interface for calling into rules in other grammars.
This is a prerequisite for being able to import rules in grammars. The idea is:
import * as foo from "./foo.js"will be possibleparsepeg$parseMyLibrary_Foo()will callpeg$callLibrary(MyLibrary, "foo")I've got the start of the code that processes imports in another branch, but I wanted to have a discussion about this part first.