Custom rule matcher / nested grammars #656
Unanswered
filipjezek
asked this question in
Q&A
Replies: 2 comments 1 reply
|
Turns out the Expression = Langswitch
Langswitch = blockStart blockEnd
blockStart = "nested {" {
input = 'nested {}';
return 'foo';
}
blockEnd = "}"
// accepts:
// nested {}
// nested { anything }Seems quite fragile though. |
0 replies
|
If you look at cbor-edn you'll find an example of calling a rule by name, based on some context. As the comment says However, there might be an idea in there for you that we could generalize to make documented and supported. |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
My language supports nested blocks of other languages - something like JS in a HTML script tag, or a templating language like PHP. What I'm looking for is a way to switch to a different grammar during the parsing.
It is not possible to just find the nested block start and end and then parse the contents later, as the nested block may include false block ends (e.g. as strings etc).
Something like custom rule matchers would likely solve this problem as well, but based on #312, those are not supported at all.
So my question is: is this currently possible? If not, is it viable to implement support for either custom matchers or manipulating the remaining input? I am very much open to doing that myself.
For the context, I have already achieved this with jison, but PEG grammars are a better fit for the language. I have already spent several hours rewriting the parser into peggy before realizing I don't know how to deal with the nesting.
All reactions