Interface MolangParser

All Superinterfaces:
AutoCloseable, Closeable

public interface MolangParser extends Closeable
Parser for the Molang language.

The parser converts token streams to expression streams

Note that this is a stream-based parser, this means that it will not consume the entire lexer if it doesn't continue having next() calls

Since:
3.0.0
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes this parser and the internal MolangLexer.
    @Nullable Expression
    Returns the last emitted expression (the last expression value returned when calling next())
    default @NotNull Cursor
    Returns the cursor for this parser, the cursor maintains track of the current line and column, it is used for error reporting.
    @NotNull MolangLexer
    Returns the internal lexer being used.
    @Nullable Expression
    Parses the next expression.
    default @NotNull List<Expression>
    Parses all the tokens until it finds a TokenKind.EOF.
    static @NotNull List<Expression>
    parseAll(@NotNull Reader reader)
    Parses all the expressions from the given reader.
    static @NotNull List<Expression>
    parseAll(@NotNull String string)
    Parses the provided string.
    static @NotNull MolangParser
    parser(@NotNull Reader reader)
    Creates a new parser that will read the tokens from the given reader.
    static @NotNull MolangParser
    parser(@NotNull String string)
    Creates a new parser that will read the tokens from the given string.
    static @NotNull MolangParser
    parser(@NotNull MolangLexer lexer)
    Creates a new parser that will read the tokens from the given lexer.
  • Method Details

    • lexer

      @NotNull @NotNull MolangLexer lexer()
      Returns the internal lexer being used.
      Returns:
      The lexer for this parser.
      Since:
      3.0.0
    • cursor

      @NotNull default @NotNull Cursor cursor()
      Returns the cursor for this parser, the cursor maintains track of the current line and column, it is used for error reporting.
      Returns:
      The cursor.
      Since:
      3.0.0
    • current

      @Nullable @Nullable Expression current()
      Returns the last emitted expression (the last expression value returned when calling next())

      Requires the user to call next() at least once first.

      Returns:
      The last emitted expression
      Throws:
      IllegalStateException - If there is no current expression
      Since:
      3.0.0
    • next

      @Nullable @Nullable Expression next() throws IOException
      Parses the next expression.

      This method returns null if it reaches the end of file and throws a ParseException if there is an error.

      Returns:
      The parsed expression
      Throws:
      IOException - If reading or parsing fails
      Since:
      3.0.0
    • parseAll

      @NotNull default @NotNull List<Expression> parseAll() throws IOException
      Parses all the tokens until it finds a TokenKind.EOF.

      After this method is called, the parser should be done and all next expressions will be null

      Returns:
      All the read expressions
      Throws:
      IOException - If reading or parsing fails
      Since:
      3.0.0
    • close

      void close() throws IOException
      Closes this parser and the internal MolangLexer.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - If closing fails
      Since:
      3.0.0
    • parser

      @NotNull static @NotNull MolangParser parser(@NotNull @NotNull MolangLexer lexer) throws IOException
      Creates a new parser that will read the tokens from the given lexer.
      Parameters:
      lexer - The lexer
      Returns:
      The created parser
      Throws:
      IOException - If parser initialization fails.
      Since:
      3.0.0
    • parser

      @NotNull static @NotNull MolangParser parser(@NotNull @NotNull Reader reader) throws IOException
      Creates a new parser that will read the tokens from the given reader.
      Parameters:
      reader - The reader
      Returns:
      The created parser
      Throws:
      IOException - If parser initialization fails.
      Since:
      3.0.0
    • parser

      @NotNull static @NotNull MolangParser parser(@NotNull @NotNull String string) throws IOException
      Creates a new parser that will read the tokens from the given string.
      Parameters:
      string - The string
      Returns:
      The created parser
      Throws:
      IOException - If parser initialization fails.
      Since:
      3.0.0
    • parseAll

      @NotNull static @NotNull List<Expression> parseAll(@NotNull @NotNull Reader reader) throws IOException
      Parses all the expressions from the given reader.
      Parameters:
      reader - The reader.
      Returns:
      The emitted expressions.
      Throws:
      IOException - If reading or parsing fails.
      Since:
      3.0.0
    • parseAll

      @NotNull static @NotNull List<Expression> parseAll(@NotNull @NotNull String string) throws IOException
      Parses the provided string.
      Parameters:
      string - The string.
      Returns:
      The emitted expressions.
      Throws:
      IOException - If reading or parsing fails.
      Since:
      3.0.0