public abstract class BaseParser<Token> extends Object
Generated parsers extend this class to inherit the tokenizer mechanism, as well as the parsing exceptions utilities.
Generated parsers which require systematic position tracking
of terminals and non-terminals extend BaseParser.WithPositions
,
a sub-class of BaseParser
.
Modifier and Type | Class and Description |
---|---|
static class |
BaseParser.ParsingException
Exception raised by parsing errors in generated parsers
|
static class |
BaseParser.WithPositions<Token>
Base class for generated parsers which track positions
of terminals and non-terminals as the parsing goes on.
|
Modifier and Type | Field and Description |
---|---|
protected LexBuffer.Position |
_jl_lastTokenEnd
The end position of the last token that was consumed by
the parser, or the start-of-input position if no token
was consumed yet
|
protected LexBuffer.Position |
_jl_lastTokenStart
The start position of the last token that was consumed by
the parser, or the start-of-input position if no token
was consumed yet
|
protected LexBuffer |
_jl_lexbuf
The underlying lexing buffer
|
protected Token |
_jl_nextToken
The last token read and not yet consumed, or
null
if the next token must be fetched from _jl_tokens |
Modifier | Constructor and Description |
---|---|
protected |
BaseParser(String version,
T lexbuf,
Function<T,Token> tokens)
Construct a new parser which will feed on the
given tokenizer.
|
Modifier and Type | Method and Description |
---|---|
protected Token |
eat()
Consumes the next token and returns it
|
protected BaseParser.ParsingException |
parsingError(String msg)
Convenience helper which returns a
BaseParser.ParsingException
located at the last token consumed by the parser. |
protected Token |
peek() |
protected BaseParser.ParsingException |
tokenError(Object token,
Object... expectedKinds)
Convenience function to build a
BaseParser.ParsingException when
encountering some token which does not correspond to the
set of expected token kinds |
@DolmenInternal(read=true) protected final LexBuffer _jl_lexbuf
@DolmenInternal protected Token _jl_nextToken
null
if the next token must be fetched from _jl_tokens
@DolmenInternal(read=true) protected LexBuffer.Position _jl_lastTokenStart
@DolmenInternal(read=true) protected LexBuffer.Position _jl_lastTokenEnd
protected BaseParser(String version, T lexbuf, Function<T,Token> tokens)
version
- the version of Dolmen which generated the subclasslexbuf
- tokens
- Exceptions.DolmenVersionException
- if version
is not equal to
the version of this BaseParser
protected BaseParser.ParsingException tokenError(Object token, Object... expectedKinds)
BaseParser.ParsingException
when
encountering some token
which does not correspond to the
set of expected token kindstoken
- expectedKinds
- protected BaseParser.ParsingException parsingError(String msg)
BaseParser.ParsingException
located at the last token consumed by the parser.msg
- @DolmenInternal protected final Token peek()
@DolmenInternal protected final Token eat()