Class CharStream

java.lang.Object
org.openzen.zenscript.lexer.CharStream

public class CharStream extends Object
Represents a character stream. Suitable for character by character parsing.

Used in the regular expression parser.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a character stream from a data string.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Checks if the end of the stream has been reached.
    char
    Returns the next character in the stream.
    boolean
    optional(char ch)
    Processes an optional character.
    char
    optional(char from, char to)
    Processes an optional range of characters.
    char
     
    boolean
    peek(char ch)
    Checks if the next character in the stream equals the specified character.
    void
    required(char ch)
    Processes a required character.
    char
    required(char from, char to)
    Processes a required character range.

    Methods inherited from class java.lang.Object

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

    • CharStream

      public CharStream(String data)
      Constructs a character stream from a data string.
      Parameters:
      data - data string
  • Method Details

    • peek

      public char peek()
    • peek

      public boolean peek(char ch)
      Checks if the next character in the stream equals the specified character.
      Parameters:
      ch - checked character
      Returns:
      true if the next character equals the specified character
    • optional

      public boolean optional(char ch)
      Processes an optional character. If the next character does not equal the specified character, nothing will happen.
      Parameters:
      ch - checked character
      Returns:
      true if the next character equals the specified character
    • optional

      public char optional(char from, char to)
      Processes an optional range of characters. If the next character is not within the specified bounds, nothing will happen.
      Parameters:
      from - lower character value bound, inclusive
      to - upper character value bound, inclusive
      Returns:
      the processed character
    • required

      public void required(char ch)
      Processes a required character. If the next character does not equal the specified character, an IllegalArgumentException is thrown.
      Parameters:
      ch - required character
    • required

      public char required(char from, char to)
      Processes a required character range. If the next character is not within the specified bounds, an IllegalArgumentException is thrown.
      Parameters:
      from - lower character value bound, inclusive
      to - upper character value bound, inclusive
      Returns:
      the processed character
    • next

      public char next()
      Returns the next character in the stream.
      Returns:
      the next character
    • hasMore

      public boolean hasMore()
      Checks if the end of the stream has been reached.
      Returns:
      true if there are more characters in the stream