6

In the language I work with, some keywords must be at the start of the line. This is mainly because string values within the language can go over multiple lines, and strings could easily contain these keywords.

The old yacc/lex grammar implementation I have easily deals with this because the lexer uses normal regexes to match text patterns, e.g.

^description    { actions }

matches 'description' at the start of a line and then does actions.

How can I do this in Antlr4? It does not appear to support proper regex for lexical matching. I'm using the IntelliJ plugin, and it complains when I use the '^' character on any lexer rule RHS.

bfontaine
  • 18,169
  • 13
  • 73
  • 107
wolandscat
  • 213
  • 2
  • 6
  • 3
    Does [this answer](http://stackoverflow.com/questions/31903723/how-to-detect-beginning-of-line-or-the-name-getcharpositioninline-does-not/31910284#31910284) your question? – GRosenberg Sep 30 '15 at 20:36
  • 2
    That is, using `DescKeyWord : BOL [ \t]* 'description' ;`. – GRosenberg Sep 30 '15 at 20:41
  • Yes that was the conclusion I came to as well, although you formalised it with an actual BOL token. – wolandscat Feb 04 '16 at 15:35
  • Does this answer your question? [How to detect beginning of line, or: "The name 'getCharPositionInLine' does not exist in the current context"](https://stackoverflow.com/questions/31903723/how-to-detect-beginning-of-line-or-the-name-getcharpositioninline-does-not) – General Grievance Sep 29 '21 at 18:13

0 Answers0