Class Parser<T>

java.lang.Object
io.jenetics.ext.internal.parser.Parser<T>
Type Parameters:
T - the token type
Direct Known Subclasses:
TokenParser

public class Parser<T> extends Object
Parser implementation for parsing a given token sequences.
Since:
7.1
Version:
7.1
  • Constructor Summary

    Constructors
    Constructor
    Description
    Parser(Tokenizer<T> tokenizer, int k)
    Create a new parser object with the given tokenizer and lookahead count k.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Consumes the next token.
    LT(int index)
    Return the lookahead token with the given index.
    match(Predicate<? super T> token)
    Try to match and consume the next token of the given type.

    Methods inherited from class java.lang.Object

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

    • Parser

      public Parser(Tokenizer<T> tokenizer, int k)
      Create a new parser object with the given tokenizer and lookahead count k.
      Parameters:
      tokenizer - the token source this parser uses
      k - the lookahead count
  • Method Details

    • LT

      public T LT(int index)
      Return the lookahead token with the given index. The index starts at 1. The returned token might be null.
      Parameters:
      index - lookahead index
      Returns:
      the token at the given index
    • match

      public T match(Predicate<? super T> token)
      Try to match and consume the next token of the given type. If the current token is not from the given type, a ParsingException is thrown.
      Parameters:
      token - the token type to match
      Returns:
      the matched token
      Throws:
      ParsingException - if the current token doesn't match the desired token
    • consume

      public void consume()
      Consumes the next token.