Package org.jparsec

Class Indentation

java.lang.Object
org.jparsec.Indentation

public final class Indentation extends Object
Processes indentation based lexical structure according to the Off-side rule.
  • Field Details

    • INLINE_WHITESPACE

      static final CharPredicate INLINE_WHITESPACE
      A CharPredicate that returns true only if the character isn't line feed and Character.isWhitespace(char) returns true.
    • LINE_CONTINUATION

      static final Pattern LINE_CONTINUATION
      A Pattern object that matches a line continuation. i.e. a backslash character ('\') followed by some whitespaces and ended by a line feed character ('\n'). Is useful if the line feed character plays a role in the syntax (as in indentation-sensitive languages) and line continuation is supported.
    • INLINE_WHITESPACES

      static final Pattern INLINE_WHITESPACES
      A Pattern object that matches one or more whitespace characters or line continuations, where the line feed character ('\n') is escaped by the backslash character ('\').
    • WHITESPACES

      public static final Parser<Void> WHITESPACES
      A Parser that recognizes 1 or more whitespace characters on the same line. Line continutation (escaped by a backslash character '\') is considered the same line.
    • indent

      private final Object indent
    • outdent

      private final Object outdent
  • Constructor Details

    • Indentation

      public Indentation(Object indent, Object outdent)
      Creates an Indentation object that uses indent and outdent as the token values for indentation and outdentation.
    • Indentation

      public Indentation()
      Creates a Indentation object that generates default indent and outdent tokens.
  • Method Details

    • indent

      public Parser<Token> indent()
      A Parser that recognizes the generated indent token.
    • outdent

      public Parser<Token> outdent()
      A Parser that recognizes the generated outdent token.
    • lexer

      public Parser<List<Token>> lexer(Parser<?> tokenizer, Parser<?> delim)
      A Parser that greedily runs tokenizer, and translates line feed characters ('\n') to indent and outdent tokens. Return values are wrapped in Token objects and collected in a List. Patterns recognized by delim are ignored.
    • token

      private static Parser<Token> token(Object value)
    • analyzeIndentations

      List<Token> analyzeIndentations(List<Token> tokens, Object lf)
      Analyzes indentation by looking at the first token after each lf and inserting indent and outdent tokens properly.
    • newLine

      private void newLine(Token token, Stack<Integer> indentations, int indentation, List<Token> result)
    • pseudoToken

      private static Token pseudoToken(int index, Object value)