public abstract class ParserBase
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static int |
FIRST_COLUMN
The start index for columns.
|
static int |
FIRST_LINE
The start index for lines.
|
static int |
INCR_SIZE
The increment for the arrays storing the memoization table's
columns.
|
static int |
INIT_SIZE
The default size for the arrays storing the memoization table's
columns.
|
static java.lang.String |
NEWLINE
The platform's line separator.
|
protected Column[] |
yyColumns
The memoization table columns.
|
protected int |
yyCount
The number of characters consumed from the character stream.
|
protected char[] |
yyData
The characters consumed so far.
|
protected boolean |
yyEOF
The flag for whether the end-of-file has been reached.
|
protected java.io.Reader |
yyReader
The reader for the character stream to be parsed.
|
| Constructor and Description |
|---|
ParserBase(java.io.Reader reader,
java.lang.String file)
Create a new parser base.
|
ParserBase(java.io.Reader reader,
java.lang.String file,
int size)
Create a new parser base.
|
| Modifier and Type | Method and Description |
|---|---|
protected <T> T |
apply(Pair<Action<T>> actions,
T seed)
Apply the specified actions on the specified seed.
|
protected <T extends Locatable> |
apply(Pair<Action<T>> actions,
T seed,
int index)
Apply the specified actions on the specified seed while also
setting the results' locations.
|
protected static <T> T |
cast(java.lang.Object o)
Cast the specified object.
|
protected static <T> Pair<T> |
cast(Pair<?> p)
Cast the list starting at the specified pair.
|
protected int |
character(int index)
Parse a character at the specified index.
|
protected Column |
column(int index)
Get the column at the specified index.
|
protected java.lang.String |
difference(int start,
int end)
Get the difference between the specified indices.
|
java.lang.String |
format(ParseError error)
Format the specified parse error.
|
boolean |
isEOF(int index)
Determine whether the specified index represents the end-of-file.
|
java.lang.String |
lineAt(int index)
Get the line at the specified index.
|
Location |
location(int index)
Get the location for the specified index.
|
protected abstract Column |
newColumn()
Create a new column.
|
protected java.lang.String |
peek(int index)
Get the next few characters from the specified index.
|
void |
resetTo(int index)
Reset this parser to the specified index.
|
protected void |
setLocation(int index,
java.lang.String file,
int line,
int column)
Set the location for the specified index.
|
void |
setLocation(Locatable locatable,
int index)
Set the location for the specified locatable object.
|
void |
signal(ParseError error)
Signal the specified parse error as a parse exception.
|
java.lang.Object |
value(Result r)
Extract the specified result's value.
|
public static final java.lang.String NEWLINE
public static final int FIRST_LINE
xtc.Constants#FIRST_LINE to avoid parsers depending on
that class.public static final int FIRST_COLUMN
xtc.Constants#FIRST_COLUMN to avoid parsers depending on
that class.public static final int INIT_SIZE
public static final int INCR_SIZE
protected java.io.Reader yyReader
protected int yyCount
protected boolean yyEOF
protected char[] yyData
protected Column[] yyColumns
public ParserBase(java.io.Reader reader,
java.lang.String file)
reader - The reader for the character stream to be parsed.file - The name of the file backing the character stream.java.lang.NullPointerException - Signals a null file name.public ParserBase(java.io.Reader reader,
java.lang.String file,
int size)
reader - The reader for the character stream to be parsed.file - The name of the file backing the character stream.size - The length of the character stream.java.lang.NullPointerException - Signals a null file name.java.lang.IllegalArgumentException - Signals a negative file size.public final void resetTo(int index)
Result.index from a previous,
successful parse (i.e., the result must be a semantic value).index - The index.java.lang.IndexOutOfBoundsException - Signals an invalid index.protected abstract Column newColumn()
protected final Column column(int index)
index - The index.java.lang.IndexOutOfBoundsException - Signals an invalid index.protected final int character(int index)
throws java.io.IOException
index - The index.java.io.IOException - Signals an exceptional condition while accessing the character
stream.protected final java.lang.String difference(int start,
int end)
start - The start index.end - The end index.public final boolean isEOF(int index)
index - The index.true if the specified index represents EOF.public final java.lang.String lineAt(int index)
throws java.io.IOException
index - The index.java.lang.IndexOutOfBoundsException - Signals an invalid index.java.io.IOException - Signals an I/O error.public final Location location(int index)
index - The index.protected final void setLocation(int index,
java.lang.String file,
int line,
int column)
FIRST_LINE), to account for a
line marker being present in the input. The column number is
generally be expected to be the start index for columns (FIRST_COLUMN), again accounting for a line marker being present
in the input.index - The index.file - The new file name.line - The new line number.column - The new column number.java.lang.NullPointerException - Signals a null file name.java.lang.IllegalArgumentException - Signals an invalid line or
column number.java.lang.IndexOutOfBoundsException - Signals an invalid index.java.lang.IllegalStateException - Signals that the index comes at or
before any memoized results.public final void setLocation(Locatable locatable, int index)
if ((null != locatable) && (! locatable.hasLocation())) {
locatable.setLocation(location(index));
}
locatable - The locatable object.index - The index.protected final <T> T apply(Pair<Action<T>> actions, T seed)
actions on the specified
list, using the result of the previous action as the argument to
the next action. The argument to the first action is the
specified seed. If the specified list is empty, this method
simply returns the specified seed.actions - The actions to apply.seed - The initial argument.protected final <T extends Locatable> T apply(Pair<Action<T>> actions, T seed, int index)
actions on the specified list, using the result
of the previous action as the argument to the next action. For
the result of each application, it also sets the location. The
argument to the first action is the specified seed. If the
specified list is empty, this method simply returns the specified
seed.actions - The actions to apply.seed - The initial argument.index - The index representing the current parser location.public final java.lang.String format(ParseError error) throws java.io.IOException
error - The error.java.io.IOException - Signals an I/O error while creating the error
message.public final void signal(ParseError error) throws ParseException, java.io.IOException
error - The parse error.ParseException - Signals the error.java.io.IOException - Signals an I/O error while creating the
exception's detail message.public final java.lang.Object value(Result r) throws ParseException, java.io.IOException
SemanticValue, this method returns the actual value; if it is a
ParseError, it signals a parse exception with the
corresponding message. The specified result must have been
created by this parser.r - The result.ParseException - Signals that the result represents a parse
error.java.io.IOException - Signals an I/O error while creating the parse
error's detail message.protected final java.lang.String peek(int index)
index - The index.protected static final <T> T cast(java.lang.Object o)
o - The object.Copyright © 2012. All Rights Reserved.