Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to push the default mode in antlr4

Tags:

lexer

antlr4

I am currently writing an antrl4 grammar with multiple lexical modes. And it is easy to push modes that have an explicit name and then return to the default mode by popping the current mode.

OPEN_PARENTHESIS : '(' -> pushMode(IN_PARENTHESES);

mode IN_PARENTHESES;

CLOSE_PARENTHESIS : ')' -> popMode;

But now I am in a situation where there are several modes on the stack, and I still want to return to the default mode without popping everything that is on the stack. So my question is, is it possible to return to the default mode by doing something along the lines of pushMode(DEFAULT)?

like image 924
M.D. Avatar asked Oct 27 '25 10:10

M.D.


1 Answers

I think what you're looking for is -> mode(DEFAULT_MODE)

See: https://github.com/antlr/antlr4/blob/master/doc/lexer-rules.md#mode-pushmode-popmode-and-more

like image 155
Bart Kiers Avatar answered Oct 30 '25 12:10

Bart Kiers