| java.lang.Object xtc.parser.ParserBase
All known Subclasses: xtc.lang.jeannie.DebuggerParser, xtc.xform.XFormParser, xtc.typical.TypicalParser, xtc.lang.jeannie.JeannieParser, xtc.lang.p2.Parser, xtc.lang.JavaFiveReader, xtc.parser.PParser, xtc.lang.JavaFiveParser, xtc.lang.JavaReader, xtc.lang.jeannie.PreJeannieParser, xtc.lang.JavaParser, xtc.lang.CFactoryParser, xtc.lang.TypedLambdaParser, xtc.lang.JavaRecognizer, xtc.lang.CParser, xtc.lang.CReader, xtc.lang.c4.C4Parser, xtc.lang.JavaFactoryParser,
ParserBase | abstract public class ParserBase (Code) | | The base class for packrat parsers.
author: Robert Grimm version: $Revision: 1.17 $ |
Field Summary | |
final public static int | FIRST_COLUMN The start index for columns. | final public static int | FIRST_LINE The start index for lines. | final public static int | INCR_SIZE The increment for the arrays storing the memoization table's
columns. | final public static int | INIT_SIZE The default size for the arrays storing the memoization table's
columns. | final public static 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 Reader | yyReader The reader for the character stream to be parsed. |
Method Summary | |
final protected T | apply(Pair<Action<T>> actions, T seed) Apply the specified actions on the specified seed. | final protected T | apply(Pair<Action<T>> actions, T seed, int index) Apply the specified actions on the specified seed while also
setting the results' locations. | final protected static T | cast(Object o) Cast the specified object. | final protected static Pair<T> | cast(Pair> p) Cast the list starting at the specified pair. | final protected int | character(int index) Parse a character at the specified index.
Parameters: index - The index. | final protected Column | column(int index) Get the column at the specified index. | final protected String | difference(int start, int end) Get the difference between the specified indices.
Parameters: start - The start index. Parameters: end - The end index. | final public String | format(ParseError error) Format the specified parse error. | final public boolean | isEOF(int index) Determine whether the specified index represents the end-of-file.
Parameters: index - The index. | final public String | lineAt(int index) Get the line at the specified index.
Parameters: index - The index. | final public Location | location(int index) Get the location for the specified index.
Parameters: index - The index. | abstract protected Column | newColumn() Create a new column. | final protected String | peek(int index) Get the next few characters from the specified index.
Parameters: index - The index. | final public void | resetTo(int index) Reset this parser to the specified index. | final protected void | setLocation(int index, String file, int line, int column) Set the location for the specified index. | final public void | setLocation(Locatable locatable, int index) Set the location for the specified locatable object. | final public void | signal(ParseError error) Signal the specified parse error as a parse exception. | final public Object | value(Result r) Extract the specified result's value. |
FIRST_COLUMN | final public static int FIRST_COLUMN(Code) | | The start index for columns. Note that this constant mirrors
xtc.Constants.FIRST_COLUMN to avoid parsers depending on
that class.
|
FIRST_LINE | final public static int FIRST_LINE(Code) | | The start index for lines. Note that this constant mirrors
xtc.Constants.FIRST_LINE to avoid parsers depending on
that class.
|
INCR_SIZE | final public static int INCR_SIZE(Code) | | The increment for the arrays storing the memoization table's
columns.
|
INIT_SIZE | final public static int INIT_SIZE(Code) | | The default size for the arrays storing the memoization table's
columns.
|
NEWLINE | final public static String NEWLINE(Code) | | The platform's line separator.
|
yyColumns | protected Column[] yyColumns(Code) | | The memoization table columns.
|
yyCount | protected int yyCount(Code) | | The number of characters consumed from the character stream.
|
yyData | protected char[] yyData(Code) | | The characters consumed so far.
|
yyEOF | protected boolean yyEOF(Code) | | The flag for whether the end-of-file has been reached.
|
yyReader | protected Reader yyReader(Code) | | The reader for the character stream to be parsed.
|
ParserBase | public ParserBase(Reader reader, String file)(Code) | | Create a new parser base.
Parameters: reader - The reader for the character stream to be parsed. Parameters: file - The name of the file backing the character stream. throws: NullPointerException - Signals a null file name. |
ParserBase | public ParserBase(Reader reader, String file, int size)(Code) | | Create a new parser base.
Parameters: reader - The reader for the character stream to be parsed. Parameters: file - The name of the file backing the character stream. Parameters: size - The length of the character stream. throws: NullPointerException - Signals a null file name. throws: IllegalArgumentException - Signals a negative file size. |
apply | final protected T apply(Pair<Action<T>> actions, T seed)(Code) | | Apply the specified actions on the specified seed. This method
applies all
xtc.util.Action 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.
Parameters: actions - The actions to apply. Parameters: seed - The initial argument. The result of applying the actions. |
apply | final protected T apply(Pair<Action<T>> actions, T seed, int index)(Code) | | Apply the specified actions on the specified seed while also
setting the results' locations. This method applies all
xtc.util.Action 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.
Parameters: actions - The actions to apply. Parameters: seed - The initial argument. Parameters: index - The index representing the current parser location. The result of applying the actions. |
cast | final protected static T cast(Object o)(Code) | | Cast the specified object. This method is used to avoid spurious
compiler warnings for parsers utilizing generic types.
Parameters: o - The object. The cast object. |
cast | final protected static Pair<T> cast(Pair> p)(Code) | | Cast the list starting at the specified pair. This method is
used to avoid spurious compiler warnings for parsers utilizing
generic types.
Parameters: p - The list. The cast list. |
character | final protected int character(int index) throws IOException(Code) | | Parse a character at the specified index.
Parameters: index - The index. The character or -1 if the end-of-file has been reached. throws: IOException - Signals an exceptional condition while accessing the characterstream. |
column | final protected Column column(int index)(Code) | | Get the column at the specified index. If the column at the
specified index has not been created yet, it is created as a
side-effect of calling this method.
Parameters: index - The index. The corresponding column. throws: IndexOutOfBoundsException - Signals an invalid index. |
difference | final protected String difference(int start, int end)(Code) | | Get the difference between the specified indices.
Parameters: start - The start index. Parameters: end - The end index. The difference as a string. |
format | final public String format(ParseError error) throws IOException(Code) | | Format the specified parse error. The specified error must have
been created by this parser.
Parameters: error - The error. The corresponding error message. throws: IOException - Signals an I/O error while creating the errormessage. |
isEOF | final public boolean isEOF(int index)(Code) | | Determine whether the specified index represents the end-of-file.
Parameters: index - The index. true if the specified index represents EOF. |
lineAt | final public String lineAt(int index) throws IOException(Code) | | Get the line at the specified index.
Parameters: index - The index. The corresponding line, without any line terminatingcharacters. throws: IndexOutOfBoundsException - Signals an invalid index. throws: IOException - Signals an I/O error. |
location | final public Location location(int index)(Code) | | Get the location for the specified index.
Parameters: index - The index. The corresponding location. |
newColumn | abstract protected Column newColumn()(Code) | | Create a new column. A concrete implementation of this method
should simply return a new memoization table column.
A new memoization table column. |
peek | final protected String peek(int index)(Code) | | Get the next few characters from the specified index.
Parameters: index - The index. The next few characters. |
resetTo | final public void resetTo(int index)(Code) | | Reset this parser to the specified index. This method discards
the input and all memoized intermediate results up to and
excluding the specified index. The index should be determined by
accessing
SemanticValue.index from a previous,
successful parse (i.e., the result must be a
SemanticValue semantic value ).
Parameters: index - The index. throws: IndexOutOfBoundsException - Signals an invalid index. |
setLocation | final protected void setLocation(int index, String file, int line, int column)(Code) | | Set the location for the specified index. This method updates
the internal location based on, for example, a line marker
recognized by the parser.
This method must be called before any nodes are created for
positions at or beyond the specified index — unless the
specified file, line, and column are the same as the internal
location for the index. The line number may be one less than the
start index for lines (
ParserBase.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 (
ParserBase.FIRST_COLUMN ), again accounting for a line marker being present
in the input.
Parameters: index - The index. Parameters: file - The new file name. Parameters: line - The new line number. Parameters: column - The new column number. throws: NullPointerException - Signals a null file name. throws: IllegalArgumentException - Signals an invalid line orcolumn number. throws: IndexOutOfBoundsException - Signals an invalid index. throws: IllegalStateException - Signals that the index comes at orbefore any memoized results. |
setLocation | final public void setLocation(Locatable locatable, int index)(Code) | | Set the location for the specified locatable object. This method
is equivalent to:
if ((null != locatable) && (! locatable.hasLocation())) {
locatable.setLocation(location(index));
}
Parameters: locatable - The locatable object. Parameters: index - The index. |
signal | final public void signal(ParseError error) throws ParseException, IOException(Code) | | Signal the specified parse error as a parse exception. The
specified error must have been created by this parser.
Parameters: error - The parse error. throws: ParseException - Signals the error. throws: IOException - Signals an I/O error while creating theexception's detail message. |
value | final public Object value(Result r) throws ParseException, IOException(Code) | | Extract the specified result's value. If the result is a
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.
Parameters: r - The result. The corresponding value. throws: ParseException - Signals that the result represents a parseerror. throws: IOException - Signals an I/O error while creating the parseerror's detail message. |
|
|