Class AbstractCharacterInput<D,T,U extends Parser.Token<D,T>>

java.lang.Object
eu.bandm.tools.ramus.runtime2.AbstractCharacterInput<D,T,U>

public abstract class AbstractCharacterInput<D,T,U extends Parser.Token<D,T>> extends Object
Character input source.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The maximum number of characters a lexer may look ahead.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractCharacterInput(D documentId, Reader in)
    DOCUMENT ME
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Starts creation of a new token and records the current line/column location.
    int
    Consumes and returns the next input character.
    int
    consume(char expected)
     
    char
    Consumes and returns the next input character.
    empty(T type)
    Creates an empty token of a given type at the current line/column location.
    end(T type)
    Ends the creation of a new token with the given type and currently accumulated text.
    protected abstract int
     
    protected abstract int
     
    protected Location<D>
    Returns a location that spans input since the last recorded line/column number.
    protected Location<D>
    Returns a location that points to the current line/column number.
    int
    lookahead(int k)
    Returns the k-th input character after the current, without changing the state.
    match(String text, T type)
    Creates a token with the given type and text, if matching the input.
    protected abstract U
    newToken(@Opt Location<D> location, String text, T type)
     
    replace(String text, T type)
     
    void
    Consumes the next input character and appends it to the current text.
    void
    shiftIf(IntPredicate condition)
    Consumes the next input character if a condition is satisfied and appends them to the current text.
    void
    Consumes input characters as long as a loop condition is satisfied and appends them to the current text.
    singleton(T type)
    Creates a single-character token of a given type at the current line/column location.
    void
    substitute(char subst)
    Consumes the next input character and appends a substitute to the current text.
    take(int k, T type)
    Creates a token of k characters of a given type at the current line/column location.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MAX_LOOKAHEAD

      public static final int MAX_LOOKAHEAD
      The maximum number of characters a lexer may look ahead.
      See Also:
  • Constructor Details

    • AbstractCharacterInput

      protected AbstractCharacterInput(@Opt D documentId, Reader in)
      DOCUMENT ME
  • Method Details

    • getFirstLine

      protected abstract int getFirstLine()
    • getFirstColumn

      protected abstract int getFirstColumn()
    • lookahead

      public int lookahead(int k) throws IOException
      Returns the k-th input character after the current, without changing the state.
      Parameters:
      k - the number of characters to skip ahead
      Returns:
      the k-th input character after the current, or -1 if not enough characters are available
      Throws:
      IllegalArgumentException - if k < 0 or k > MAX_LOOKAHEAD
      IOException
    • consume

      public int consume() throws IOException
      Consumes and returns the next input character. The current line and column number are updated.
      Returns:
      the next input character, or -1 if no more characters are available
      Throws:
      IOException
    • consume

      public int consume(char expected) throws IOException
      Throws:
      IOException
    • consumeNoEOF

      public char consumeNoEOF() throws IOException
      Consumes and returns the next input character. The current line and column number are updated.
      Returns:
      the next input character
      Throws:
      EOFException - if no more characters are available
      IOException
    • newToken

      protected abstract U newToken(@Opt @Opt Location<D> location, String text, T type)
    • empty

      public U empty(T type)
      Creates an empty token of a given type at the current line/column location.
    • singleton

      public U singleton(T type) throws IOException
      Creates a single-character token of a given type at the current line/column location.
      Throws:
      IOException
    • take

      public U take(int k, T type) throws IOException
      Creates a token of k characters of a given type at the current line/column location.
      Throws:
      IOException
    • begin

      public void begin()
      Starts creation of a new token and records the current line/column location.
    • shift

      public void shift() throws IOException
      Consumes the next input character and appends it to the current text.
      Throws:
      EOFException - if no more characters are available
      IOException
    • shiftIf

      public void shiftIf(IntPredicate condition) throws IOException
      Consumes the next input character if a condition is satisfied and appends them to the current text.
      Parameters:
      condition - indicates whether to consume the next character
      Throws:
      EOFException - if no more characters are available
      IOException
    • shiftWhile

      public void shiftWhile(IntPredicate condition) throws IOException
      Consumes input characters as long as a loop condition is satisfied and appends them to the current text.
      Parameters:
      condition - indicates whether to consume the next character and iterate
      Throws:
      EOFException - if no more characters are available
      IOException
    • substitute

      public void substitute(char subst) throws IOException
      Consumes the next input character and appends a substitute to the current text.
      Parameters:
      subst - the character to substitute
      Throws:
      EOFException - if no more characters are available
      IOException
    • end

      public U end(T type)
      Ends the creation of a new token with the given type and currently accumulated text.
      Parameters:
      type - the token type
    • match

      public Optional<U> match(String text, T type) throws IOException
      Creates a token with the given type and text, if matching the input. Otherwise, no input characters are consumed.
      Parameters:
      the - expected input text
      the - type of token to create
      Returns:
      an Optional containing a token with the given type and text, if input characters can be consumed to match the text exactly; otherwise Optional#none.
      Throws:
      IOException
    • location

      protected Location<D> location()
      Returns a location that spans input since the last recorded line/column number.
      Returns:
      a location that spans input since the last recorded line/column number.
      See Also:
      • #start
    • locationEnd

      protected Location<D> locationEnd()
      Returns a location that points to the current line/column number.
      Returns:
      a location that points to the current line/column number.
    • replace

      public U replace(String text, T type)