Package io

Class Parser<T>

java.lang.Object
io.Parser<T>
Direct Known Subclasses:
XMLParser

public abstract class Parser<T> extends Object
Since:
11.12.2021
Author:
Juyas
  • Constructor Details

    • Parser

      public Parser()
  • Method Details

    • get

      protected String get(List<Token> tokens, int pos)
      Helper method to get a value in of the token list without going out of bounds.
      Parameters:
      tokens - the list of tokens
      pos - the position
      Returns:
      the value at the given position in the list or null if the position is out of bounds
    • check

      protected boolean check(List<Token> tokens, int pos, TokenReader... readers)
      Match a list of tokens at the given position. Starting at pos, executes {@link this#is(List, int, TokenReader)} to test if all tokens are in the right order.
      Parameters:
      tokens - the list of tokens
      pos - the position to start matching
      readers - the expected list of tokens by using their TokenReader.type()
      Returns:
      if the token list matches the expected ones.
    • is

      protected boolean is(List<Token> tokens, int pos, TokenReader reader)
      Match a token.
      Parameters:
      tokens - the list of tokens
      pos - the position to match
      reader - the expected token to match using its TokenReader.type()
      Returns:
      true, if and only if the token list has a token at the given position that matches the given type
    • parse

      public abstract T parse(List<Token> tokens)
      Parse an object by taking a chronological list of tokens.
      Parameters:
      tokens - the chronological list of tokens
      Returns:
      the parsed object