-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Require superClass for Lexer in split mode for JavaScript target #1966
Conversation
…s available on Lexer prototype for use in lexer actions (this.SOME_MODE) like in Java actions, Utils.escapeWhiteSpace uses regex for global replace (was replacing only first occurnce of \n etc).
if (escapeSpaces) { | ||
s = s.replace(" ", "\u00B7"); | ||
s = s.replace(/ /g, "\u00B7"); | ||
} | ||
return s; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok with these
@@ -160,6 +160,7 @@ Object.defineProperty(<parser.name>.prototype, "atn", { | |||
}); | |||
|
|||
<parser.name>.EOF = antlr4.Token.EOF; | |||
<parser.name>.prototype.EOF = antlr4.Token.EOF; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry but this is superfluous
@@ -802,6 +803,9 @@ var antlr4 = require('antlr4/index'); | |||
>> | |||
|
|||
Lexer(lexer, atn, actionFuncs, sempredFuncs, superClass) ::= << | |||
<if(superClass)> | |||
var <superClass> = require('./<superClass>').<superClass>; | |||
<endif> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
@@ -819,14 +823,18 @@ function <lexer.name>(input) { | |||
<lexer.name>.prototype.constructor = <lexer.name>; | |||
|
|||
<lexer.name>.EOF = antlr4.Token.EOF; | |||
<lexer.name>.prototype.EOF = antlr4.Token.EOF; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
superfluous
<lexer.tokens:{k | <lexer.name>.<k> = <lexer.tokens.(k)>;}; separator="\n", wrap, anchor> | ||
<lexer.tokens:{k | <lexer.name>.prototype.<k> = <lexer.tokens.(k)>;}; separator="\n", wrap, anchor> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
superfluous
|
||
<if(lexer.channels)> | ||
<lexer.channels:{c| <lexer.name>.<c> = <lexer.channels.(c)>;}; separator="\n"> | ||
<lexer.channels:{c| <lexer.name>.prototype.<c> = <lexer.channels.(c)>;}; separator="\n"> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
superfluous
|
||
<endif> | ||
<if(rest(lexer.modes))> | ||
<rest(lexer.modes):{m| <lexer.name>.<m> = <i>;}; separator="\n"> | ||
<rest(lexer.modes):{m| <lexer.name>.prototype.<m> = <i>;}; separator="\n"> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
superfluous
Hi, |
Hi |
I meant bless not bleed |
So the downside of ids on the class vs instance is that superclasses will need to reach into the subclass (usually the generated Lexer) to access definitions. e.g. if I have a token:
From my lexer's super class, I need to do this:
I guess its the same with Java currrently:
Example: |
Reversed proto changes. |
@parrt blessed |
In split mode grammars, the generated lexer.js wasn't requiring the superclass.
Lexer ids such as token/mode/channel names were set on the generated lexer and not its prototype making them class/static variables. For grammar actions to be universal across Java and JavaScript, these names must be accessible on the lexer instance (via [this.]SOME_MODE in Java, or this.SOME_MODE in JavaScript since JS doesn't scope to the local class without this.).
Finally,
Utils.escapeWhiteSpace
was replacing only the first instance of\n
etc. Switched to a regex with global replace.