Closed krazyjakee closed 6 years ago
@krazyjakee Hmm... that's interesting, is package a rule name?
@mcchatman8009 it's classification is "reserved for the future" whatever the hell that means. In any case, since the syntax has actually mystified me, what is the course of action here?
@krazyjakee I've never seen the package keyword used or emitted in any generated Lexer before. Could you send me your current steps in running the tool and the fundamental rules of your grammar? I would very much like to help you with your issue. I'm just not clear on the steps to reproduce this issue. Also, could you verify which version you are currently using?
If you send me the Grammar and the steps, I'm certain we can figure out your issue.
Thanks,
@mcchatman8009 I hadn't seen it before (or bothered to look) but I think it's this...
In the first few lines of the g4 file:
grammar Language;
@header {
package antlr;
}
I'm guessing this gets put out the javascript.
@krazyjakee it looks like your Antlr4 grammar is based on Java and not JavaScript. The header occurs before the lexer or parser class gets defined.
I believe it’s ideal if the grammar has no language specifics in it. Allowing for it to be portable. But I understand that in some cases it’s needed.
My solution would be to update the grammar, removing the Java package declaration. Making all the header sections and actions be JavaScript compliant. JavaScript doesn’t have a need for the package keyword. Your issue is that the grammar has Java assumptions baked into it, and is not fit for JavaScript based lexing and parsing.
@krazyjakee so it looks like you found your problem. Thanks for reporting your issues.
I get an error when trying to import in babel.
Error:
SyntaxError: LanguageLexer.js: package is a reserved word in strict mode