Package team.unnamed.mocha.parser
Interface MolangParser
- All Superinterfaces:
AutoCloseable,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 TypeMethodDescriptionvoidclose()Closes this parser and the internalMolangLexer.@Nullable Expressioncurrent()Returns the last emitted expression (the last expression value returned when callingnext())default @NotNull Cursorcursor()Returns the cursor for this parser, the cursor maintains track of the current line and column, it is used for error reporting.@NotNull MolangLexerlexer()Returns the internal lexer being used.@Nullable Expressionnext()Parses the next expression.default @NotNull List<Expression>parseAll()Parses all the tokens until it finds aTokenKind.EOF.static @NotNull List<Expression>Parses all the expressions from the given reader.static @NotNull List<Expression>Parses the provided string.static @NotNull MolangParserCreates a new parser that will read the tokens from the given reader.static @NotNull MolangParserCreates a new parser that will read the tokens from the given string.static @NotNull MolangParserparser(@NotNull MolangLexer lexer) Creates a new parser that will read the tokens from the given lexer.
-
Method Details
-
lexer
Returns the internal lexer being used.- Returns:
- The lexer for this parser.
- Since:
- 3.0.0
-
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
Returns the last emitted expression (the last expression value returned when callingnext())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
Parses the next expression.This method returns
nullif it reaches the end of file and throws aParseExceptionif there is an error.- Returns:
- The parsed expression
- Throws:
IOException- If reading or parsing fails- Since:
- 3.0.0
-
parseAll
Parses all the tokens until it finds aTokenKind.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
Closes this parser and the internalMolangLexer.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- 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
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
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
-