Package com.blackrook.rookscript.struct
Class Lexer.Parser
java.lang.Object
com.blackrook.rookscript.struct.Lexer.Parser
- Direct Known Subclasses:
ScriptParser
- Enclosing class:
- Lexer
Abstract parser class.
This class aids in the creation of top-down (AKA recursive-descent) parsers.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Thrown when a Parser has a problem. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected Lexer.Token
Gets the token read from the lastnextToken()
call.protected boolean
currentType
(int... tokenTypes) Attempts to match the type of the current token.getLexer()
Gets theLexer
that this Parser uses.getTokenInfoLine
(String message) Returns a stock error line for when an error/warning or whatever occurs during parse.protected boolean
matchType
(int tokenType) Matches the current token.protected void
Reads and sets the current token to the next token.
-
Constructor Details
-
Parser
Constructs the parser and binds a Lexer to it.- Parameters:
lexer
- the lexer that this reads from.
-
-
Method Details
-
getLexer
Gets theLexer
that this Parser uses.- Returns:
- the underlying Lexer.
-
currentToken
Gets the token read from the lastnextToken()
call.- Returns:
- the current token.
-
matchType
protected boolean matchType(int tokenType) Matches the current token. If matched, this returns true and advances to the next token. Else, this returns false.- Parameters:
tokenType
- the type to match.- Returns:
- true if matched, false if not.
-
currentType
protected boolean currentType(int... tokenTypes) Attempts to match the type of the current token. If matched, this returns true. This DOES NOT ADVANCE to the next token.- Parameters:
tokenTypes
- the list of types.- Returns:
- true if one was matched, false if not.
-
nextToken
protected void nextToken()Reads and sets the current token to the next token. If the current token is null, it is the end of the Lexer's stream.- Throws:
Lexer.Parser.Exception
- if the next token can't be read.
-
getTokenInfoLine
Returns a stock error line for when an error/warning or whatever occurs during parse. For convenience only - not called by any of the current methods.- Parameters:
message
- the message to append.- Returns:
- the error message.
-