You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Give warnings if there is action code in grammar #71
As noted here, the javadoc/ grammar contains actions. lab.antlr.org should output a warning message if the grammar contains action code since action code will not be executed. Even long-time users of Antlr will make an assumption that is wrong.
There were a few comments about supporting other targets and even action code in the long discussion last year, e.g. interp simulator for Javascript and even antlr4ts. For now, it would be best for the interp itself to output a warming if an action is encountered.
Also to consider, there's only a syntaxError() as output from the parser. No such thing as a warning. Seems rather limited to what most compilers do. I suppose the interpreter not being able to execute an action is pretty much a failure though. What should happen if the parse doesn't actually need to execute the action from a particular start rule? No need to produce a warning even if the grammar does have actions.
I'd be comfortable not executing actions because the lab is about parsing, not about further steps. But predicates participate in parsing so it's certainly worth a discussion.
Sorry, I use "actions" to be either { ... } or { ... }? target-specific code because the parse tree node is actionBlock for either when parsing .g4's. We may need to discuss both. I thought there were grammars that had both, where { ... } blocks were used to initialize some state variables for the { ... }? predicates. Checking now
for i in `find . -name desc.xml`; do echo $i; d="$(dirname $i)"; echo $d; trparse $d/*.g4 | trxgrep ' //element/actionBlock' | trtext; done
A solution worth exploring would be to generate the lexer and parser in JavaScript on the server, and run them in the browser. This would require devs to code predicates in JS (in the lab) but that sounds like a reasonable requirement
Most if not all grammars in grammars-v4 that have a JS port are in "target agnostic format", which means there are addition source files in JS. It would be nice to have the tool have an extra tab for these files. Otherwise, we'd need to refactor the grammars on the fly to use @members and remove the superClass option.
Activity
ericvergnaud commentedon Feb 27, 2023
Maybe I'm wrong but I don't see anything in the lab code for preventing execution of predicates
kaby76 commentedon Feb 27, 2023
There were a few comments about supporting other targets and even action code in the long discussion last year, e.g. interp simulator for Javascript and even antlr4ts. For now, it would be best for the interp itself to output a warming if an action is encountered.
ericvergnaud commentedon Feb 27, 2023
The lab runs on server side in Java, running parsers in a lambda could be a solution to prevent damage
kaby76 commentedon Feb 27, 2023
Also to consider, there's only a syntaxError() as output from the parser. No such thing as a warning. Seems rather limited to what most compilers do. I suppose the interpreter not being able to execute an action is pretty much a failure though. What should happen if the parse doesn't actually need to execute the action from a particular start rule? No need to produce a warning even if the grammar does have actions.
ericvergnaud commentedon Feb 27, 2023
I'd be comfortable not executing actions because the lab is about parsing, not about further steps. But predicates participate in parsing so it's certainly worth a discussion.
kaby76 commentedon Feb 27, 2023
Sorry, I use "actions" to be either
{ ... }or{ ... }?target-specific code because the parse tree node isactionBlockfor either when parsing .g4's. We may need to discuss both. I thought there were grammars that had both, where{ ... }blocks were used to initialize some state variables for the{ ... }?predicates. Checking nowericvergnaud commentedon Feb 27, 2023
A solution worth exploring would be to generate the lexer and parser in JavaScript on the server, and run them in the browser. This would require devs to code predicates in JS (in the lab) but that sounds like a reasonable requirement
kaby76 commentedon Feb 27, 2023
Most if not all grammars in grammars-v4 that have a JS port are in "target agnostic format", which means there are addition source files in JS. It would be nice to have the tool have an extra tab for these files. Otherwise, we'd need to refactor the grammars on the fly to use
@membersand remove thesuperClassoption.ericvergnaud commentedon Feb 27, 2023
Maybe we should convert this into a discussion?
kaby76 commentedon Feb 27, 2023
Yes, please do.
Also of note. There is no consistent "recognizer base class method reference" syntax across targets. So we have action code with:
this.FooBar()in CSharp, Javal.FooBar() andp.FooBar()` in Gothis.FooBar()in JavaScript, TypeScriptthis->FooBar()in Cpp$this->FooBar()in PHPself.FooBar()in Python3(I haven't set up testing for Swift because of the lack of a Mac machine--currently a brick, can't install a new OS on a blank HDD.)
The grammars contain either
self.FooBar()orthis.FooBar(), and that is modified to the target-specific format.