question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BOF (Begin of File) token for elements that must appear at the beginning of a line

See original GitHub issue

Hey, 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:open
  • Created 9 months ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
KvanTTTcommented, Dec 10, 2022

Try to read https://github.com/antlr/antlr4/blob/master/doc/predicates.md and just use JS code instead of Java in semantic predicates.

0reactions
MrCodercommented, Dec 10, 2022

You can achieve such behavior using semantic predicate, but yes, it’s not language agnostic way.

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · antlr/antlr4 - GitHub
Issues list ; BOF (Begin of File) token for elements that must appear at the beginning of a line. #4005 opened 3 days...
Read more >
Error: Unsupported format, or corrupt file: Expected BOF record
The error message relates to the BOF (Beginning of File) record of an XLS file. However, the example shows that you are trying...
Read more >
Lexical Analysis with Flex - begriffs.com
This scanner counts the number of characters and the number of lines in its input. It produces no output other than the final...
Read more >
RFC 6020 - YANG - A Data Modeling Language for the ...
A detailed description of YANG statements and syntax begins in Section 7. 4.2.1. ... The name of the file SHOULD be of the...
Read more >
MetaLexer User Manual - Sable Research Group
The component X must appear in the file X.mlc (case-sensitive). ... %start name – At most 1 – This directive indicates in which...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found