ECMAScript.g4

60 views
Skip to first unread message

Jason Hullinger

unread,
Jan 23, 2017, 5:17:08 PM1/23/17
to antlr-discussion
Hi, I'm getting the following errors with ECMAScript.g4 when running Antlr4:

error(156): ECMAScript.g4:1460:4: invalid escape sequence
error(156): ECMAScript.g4:1470:4: invalid escape sequence

Upon inspecting the lines, it looks like there is an invalid escape sequence on the following lines (https://github.com/antlr/grammars-v4/blob/master/ecmascript/ECMAScript.g4#L1460 and https://github.com/antlr/grammars-v4/blob/master/ecmascript/ECMAScript.g4#L1470):

: ~[\r\n\u2028\u2029*\\/\[]

I believe it should be the following because "\[" is not a valid escape character:

: ~[\r\n\u2028\u2029*\\/[]

Can anyone please confirm?

Thanks,
Jason

Vassili Bykov

unread,
Jan 23, 2017, 5:39:50 PM1/23/17
to antlr-discussion
I think you are right, because I made the same change when I borrowed regex literal-related stuff from that grammar for my needs.

There is also a performance gotcha in the way RegularExpressionLiteral puts the isRegexPossible() predicate at the start of the rule:

RegularExpressionLiteral
: {isRegexPossible()}? '/' RegularExpressionBody '/' RegularExpressionFlags
;

I moved the predicate after the '/' and got a 30x performance improvement.

Jason Hullinger

unread,
Jan 24, 2017, 3:28:28 PM1/24/17
to antlr-discussion
Great, thanks much for the input and gotcha!

Jason
Reply all
Reply to author
Forward
0 new messages