Interface SyntaxErrorReportable

All Known Implementing Classes:
AbstractLexer, AbstractParser, GroovyLangLexer, GroovyLangParser, GroovyLexer, GroovyParser

public interface SyntaxErrorReportable
A SyntaxErrorReportable is a recognizer that can report syntax error
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Tuple2<Integer,Integer>
    A line offset of zero and a column offset of zero.
  • Method Summary

    Modifier and Type
    Method
    Description
    default PositionInfo
    genPositionInfo(int offset)
    Builds a position from the current error line and the current error column plus offset.
    default PositionInfo
    Builds a position by adding offset to the current error line and column.
    int
    Returns the 1-based column of the current syntax error.
    int
    Returns the 1-based line of the current syntax error.
    int
    Returns whether this reporter is the lexer or the parser.
    default void
    require(boolean condition, String msg)
    Throws a syntax error when condition is false, at the current error position, without repeating that position in the message.
    default void
    require(boolean condition, String msg, boolean toAttachPositionInfo)
    Throws a syntax error when condition is false, without a position adjustment.
    default void
    require(boolean condition, String msg, int offset)
    Throws a syntax error when condition is false, adding offset to the current error column.
    default void
    require(boolean condition, String msg, int offset, boolean toAttachPositionInfo)
    Throws a syntax error when condition is false.
    default void
    require(boolean condition, String msg, Tuple2<Integer,Integer> offset)
    Throws a syntax error when condition is false.
    default void
    require(boolean condition, String msg, Tuple2<Integer,Integer> offset, boolean toAttachPositionInfo)
    Throws a syntax error when condition is false.
    default void
    throwSyntaxError(String msg, int offset, boolean toAttachPositionInfo)
    Throws a syntax error whose column is the current error column plus offset.
    default void
    throwSyntaxError(String msg, Tuple2<Integer,Integer> offset, boolean toAttachPositionInfo)
     
  • Field Details

    • NO_OFFSET

      static final Tuple2<Integer,Integer> NO_OFFSET
      A line offset of zero and a column offset of zero.
  • Method Details

    • require

      default void require(boolean condition, String msg, int offset, boolean toAttachPositionInfo)
      Throws a syntax error when condition is false. offset is added to the current error column; the line is not adjusted.
      Parameters:
      condition - requirement that must hold
      msg - the error text
      offset - columns added to the current error column
      toAttachPositionInfo - whether the message includes the caret position
    • require

      default void require(boolean condition, String msg, Tuple2<Integer,Integer> offset, boolean toAttachPositionInfo)
      Throws a syntax error when condition is false. offset's first value is added to the error line and its second value to the error column.
      Parameters:
      condition - requirement that must hold
      msg - the error text
      offset - line adjustment, then column adjustment
      toAttachPositionInfo - whether the message includes the caret position
    • require

      default void require(boolean condition, String msg, boolean toAttachPositionInfo)
      Throws a syntax error when condition is false, without a position adjustment. toAttachPositionInfo selects whether the message includes the caret position.
      Parameters:
      condition - requirement that must hold
      msg - the error text
      toAttachPositionInfo - whether the message includes the caret position
    • require

      default void require(boolean condition, String msg, int offset)
      Throws a syntax error when condition is false, adding offset to the current error column. The message does not repeat the caret position.
      Parameters:
      condition - requirement that must hold
      msg - the error text
      offset - columns added to the current error column
    • require

      default void require(boolean condition, String msg, Tuple2<Integer,Integer> offset)
      Throws a syntax error when condition is false. offset's first value is added to the error line and its second value to the error column. The message does not repeat the caret position.
      Parameters:
      condition - requirement that must hold
      msg - the error text
      offset - line adjustment, then column adjustment
    • require

      default void require(boolean condition, String msg)
      Throws a syntax error when condition is false, at the current error position, without repeating that position in the message.
      Parameters:
      condition - requirement that must hold
      msg - the error text
    • throwSyntaxError

      default void throwSyntaxError(String msg, int offset, boolean toAttachPositionInfo)
      Throws a syntax error whose column is the current error column plus offset.
      Parameters:
      msg - the error text
      offset - columns added to the current error column
      toAttachPositionInfo - whether the message includes the caret position
    • throwSyntaxError

      default void throwSyntaxError(String msg, Tuple2<Integer,Integer> offset, boolean toAttachPositionInfo)
      Parameters:
      toAttachPositionInfo - if true, append " @ line N, column M" to the exception message. Leave false when the error will be wrapped in SyntaxException, which already appends the same location (otherwise the displayed message repeats the position).
    • getSyntaxErrorSource

      int getSyntaxErrorSource()
      Returns whether this reporter is the lexer or the parser.
      Returns:
      GroovySyntaxError.LEXER or GroovySyntaxError.PARSER
    • genPositionInfo

      default PositionInfo genPositionInfo(int offset)
      Builds a position from the current error line and the current error column plus offset.
      Parameters:
      offset - columns added to the current error column
      Returns:
      that position
    • genPositionInfo

      default PositionInfo genPositionInfo(Tuple2<Integer,Integer> offset)
      Builds a position by adding offset to the current error line and column.
      Parameters:
      offset - line adjustment, then column adjustment
      Returns:
      that position
    • getErrorLine

      int getErrorLine()
      Returns the 1-based line of the current syntax error.
      Returns:
      the error line
    • getErrorColumn

      int getErrorColumn()
      Returns the 1-based column of the current syntax error.
      Returns:
      the error column