Replies: 2 comments
-
Yes, visitors or listeners is the way to go, generally, and even more so when targeting multiple languages.
It makes the parsing more reliable and predictable i.e. it is guaranteed to "succeed" even if the input is a complete mismatch for the grammar.
That makes it possible to handle syntax errors after parsing, rather than during parsing, in a much more robust way.
The only exception to the above is semantic predicates, which are required for parsing.
A working technique is to inherit from an abstract parser that implements the required predicates, and call them via the $parser variable
… Le 15 déc. 2022 à 13:58, Joan Codina ***@***.***> a écrit :
I have a grammar of a language that works pretty well in python
To produce some readable errors, I have created some fake rules that raise an error. (t is documented for java, but, I managed to do it in Python) so I have this clause with an error clause:
Field
: FieldName
| Word {self.notifyErrorListeners(f"Wrong field name {localctx.children[0].symbol.text}") }
;
Now I want to integrate the grammar/parser into Monaco, So I need to generate a javascript parser, using the same grammar, but then, the python code is included in javascript, and producing errors.
I should not have different versions of the grammar.
I want to keep special clauses to manage errors
I don't want to edit/modify the generated files
So I think that there should be a way to avoid their inclusion (so the code generated does not include code in other languages ) or, much better, I think it would be interesting that code snippets define include a language, so they can be specified in a way like this:
Field
: FieldName
| Word {python3: self.notifyErrorListeners(f"Wrong field name {localctx.children[0].symbol.text}") }
{JavaScript: notifyErrorListeners("Wrong field name" + localctx.children[0].symbol.text}) }
;
so , there is a way to this: Shall I move the code to visitors?
—
Reply to this email directly, view it on GitHub <#4020>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAZNQJDUY77GO4D6YWENXPTWNMIVRANCNFSM6AAAAAAS7WL7BI>.
You are receiving this because you are subscribed to this thread.
|
Beta Was this translation helpful? Give feedback.
0 replies
-
How is it that you could be using two different versions of a grammar? The grammar you defined is it. Where is this other grammar? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a grammar of a language that works pretty well in python
To produce some readable errors, I have created some fake rules that raise an error. (t is documented for java, but, I managed to do it in Python) so I have this clause with an error clause:
Now I want to integrate the grammar/parser into Monaco, So I need to generate a javascript parser, using the same grammar, but then, the python code is included in javascript, and producing errors.
I should not have different versions of the grammar.
I want to keep special clauses to manage errors
I don't want to edit/modify the generated files
So I think that there should be a way to avoid their inclusion (so the code generated does not include code in other languages ) or, much better, I think it would be interesting that code snippets define include a language, so they can be specified in a way like this:
so , there is a way to this: Shall I move the code to visitors?
Beta Was this translation helpful? Give feedback.
All reactions