public abstract class Token extends Object
A Token is the basic building block of a parser. It denotes something that can be parsed, either by reading from the input or composing other tokens.
Specifies the two fields that all tokens share: name (a
String) and encoding (an Encoding). A Token is parsed
by calling one of the parse methods. Parsing a Token succeeds
if the returned Optional contains an ParseState, otherwise
parsing has failed.
The name field is used during parsing to construct a scope, by
concatenating it to the incoming scope argument as follows:
scope + SEPARATOR + name
The encoding may be null. If it is not, it
overrides outer encoding specifications and is passed to nested tokens
instead. As such it can itself be overridden by explicit specifications in
nested tokens.| Modifier and Type | Field and Description |
|---|---|
static String |
EMPTY_NAME |
Encoding |
encoding |
String |
name |
static String |
NO_NAME |
static String |
SEPARATOR |
| Modifier | Constructor and Description |
|---|---|
protected |
Token(String name,
Encoding encoding) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj) |
Token |
getCanonical(ParseState parseState) |
int |
hashCode() |
boolean |
isLocal() |
protected String |
makeNameFragment() |
Optional<ParseState> |
parse(Environment environment) |
protected abstract Optional<ParseState> |
parseImpl(Environment environment) |
public static final String NO_NAME
public static final String SEPARATOR
public static final String EMPTY_NAME
public final String name
public final Encoding encoding
public Optional<ParseState> parse(Environment environment)
protected abstract Optional<ParseState> parseImpl(Environment environment)
public boolean isLocal()
public Token getCanonical(ParseState parseState)
protected String makeNameFragment()
Copyright © 2017. All rights reserved.