Class GroovyLangLexer

java.lang.Object
org.antlr.v4.runtime.Recognizer<Integer,org.antlr.v4.runtime.atn.LexerATNSimulator>
org.antlr.v4.runtime.Lexer
All Implemented Interfaces:
org.antlr.v4.runtime.TokenSource, SyntaxErrorReportable

public class GroovyLangLexer extends GroovyLexer
The lexer for Groovy programming language, which is based on the lexer generated by Antlr4
  • Constructor Details

    • GroovyLangLexer

      public GroovyLangLexer(Reader reader) throws IOException
      Throws:
      IOException
    • GroovyLangLexer

      public GroovyLangLexer(org.antlr.v4.runtime.CharStream input)
  • Method Details

    • nextToken

      public org.antlr.v4.runtime.Token nextToken()
      Returns the next token, with a special case for EOF after a bare $ in a GString.

      After GStringBegin or GStringPart matches a trailing $ at the end of input, Antlr marks _hitEOF and would skip GroovyLexer.GSTRING_TYPE_SELECTOR_MODE entirely on the subsequent call. Detect that situation and report the dollar-body error instead of a generic unexpected-EOF parse failure.

      Specified by:
      nextToken in interface org.antlr.v4.runtime.TokenSource
      Overrides:
      nextToken in class org.antlr.v4.runtime.Lexer
      Returns:
      the next token from the input
    • notifyListeners

      public void notifyListeners(org.antlr.v4.runtime.LexerNoViableAltException e)
      Report a lexical error. When the failure is inside GroovyLexer.GSTRING_TYPE_SELECTOR_MODE (after a $ in a GString), emit the dedicated dollar-body diagnostic instead of Antlr's generic token-recognition message.
      Overrides:
      notifyListeners in class org.antlr.v4.runtime.Lexer
      Parameters:
      e - the recognition failure raised by the ATN simulator
    • recover

      public void recover(org.antlr.v4.runtime.LexerNoViableAltException e)
      Abort lexing on the first lexical error. For an invalid character after $ in a GString, throw GroovySyntaxError so the parser layer can surface a source-located syntax error without retrying SLL→LL or falling back to a generic exception message.
      Overrides:
      recover in class org.antlr.v4.runtime.Lexer
      Parameters:
      e - the recognition failure raised by the ATN simulator
    • rollbackOneChar

      protected void rollbackOneChar()
      Description copied from class: GroovyLexer
      just a hook, which will be overrided by GroovyLangLexer
      Overrides:
      rollbackOneChar in class GroovyLexer