BOF (Begin of File) token for elements that must appear at the beginning of a line
See original GitHub issueHey, this is not to report an issue but to request a feature, so some items in the checklist do not apply I believe.
This is to request a “BOF”(Begin of File) token in the Lexer. I understand that there is a closed issue #1016 on this topic. The example provided in that issue did not really need a BOF token. But I believe a BOF token will benefit in my situation.
Sample grammar:
grammar com;
comment: COMMENT;
COMMENT
: '\n' '//' .*? '\n'
;
By design, it will match \n//comment\n
but not abcd //comment\n
. But I also want it to match //comment\n
when it is at the beginning of the file. A BOF
token will allows me to upgrade the lexer to COMMENT: [\n<BOF>] '//' .*? '\n'
.
I did ask a related question on Stackoverflow. The question was seeking a solution. This is to suggest a feature because I believe BOF
does not exist now.
Issue Analytics
- State:
- Created 9 months ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Try to read https://github.com/antlr/antlr4/blob/master/doc/predicates.md and just use JS code instead of Java in semantic predicates.
Because Antlr4 is targeting multiple languages, it is a reasonable feature to be added. More and more people I assume will use it in JavaScript/TypeScript.