Package com.blackrook.archetext.struct
Class Lexer.Parser
- java.lang.Object
-
- com.blackrook.archetext.struct.Lexer.Parser
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLexer.Parser.ExceptionThrown when a Parser has a problem.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Lexer.TokencurrentToken()Gets the token read from the lastnextToken()call.protected booleancurrentType(int... tokenTypes)Attempts to match the type of the current token.LexergetLexer()Gets theLexerthat this Parser uses.StringgetTokenInfoLine(String message)Returns a stock error line for when an error/warning or whatever occurs during parse.protected booleanmatchType(int tokenType)Matches the current token.protected voidnextToken()Reads and sets the current token to the next token.
-
-
-
Constructor Detail
-
Parser
protected Parser(Lexer lexer)
Constructs the parser and binds a Lexer to it.- Parameters:
lexer- the lexer that this reads from.
-
-
Method Detail
-
getLexer
public Lexer getLexer()
Gets theLexerthat this Parser uses.- Returns:
- the underlying Lexer.
-
currentToken
protected Lexer.Token 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.
-
-