xtc.parser
Class Result

java.lang.Object
  extended by xtc.parser.Result
Direct Known Subclasses:
ParseError, SemanticValue

public abstract class Result
extends java.lang.Object

The superclass of all parser results.

Version:
$Revision: 1.23 $
Author:
Robert Grimm

Field Summary
 int index
          The index into the parser's memoization table.
 
Constructor Summary
Result(int index)
          Create a new result with the specified index.
 
Method Summary
abstract  SemanticValue createValue(java.lang.Object value, ParseError error)
          Create a semantic value based on this result.
abstract  boolean hasValue()
          Determine whether this result has a value.
abstract  boolean hasValue(java.lang.String s)
          Determine whether this result has the specified string value.
abstract  boolean hasValueIgnoreCase(java.lang.String s)
          Determine whether this result has the specified string value, ignoring case.
abstract  ParseError parseError()
          Get the parse error for this result.
abstract  ParseError select(ParseError error)
          Select the more specific parse error.
abstract  ParseError select(ParseError error, int index)
          Select the more specific parse error.
abstract
<T> T
semanticValue()
          Get the semantic value for this result.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

index

public final int index
The index into the parser's memoization table.

Constructor Detail

Result

public Result(int index)
Create a new result with the specified index.

Parameters:
index - The index.
Method Detail

hasValue

public abstract boolean hasValue()
Determine whether this result has a value.

Returns:
true if this result has a value.

hasValue

public abstract boolean hasValue(java.lang.String s)
Determine whether this result has the specified string value. The specified value must not be null.

Parameters:
s - The string value.
Returns:
true if this result has the specified string value.

hasValueIgnoreCase

public abstract boolean hasValueIgnoreCase(java.lang.String s)
Determine whether this result has the specified string value, ignoring case. The specified value must not be null.

Parameters:
s - The string value.
Returns:
true if this result has the specified string value, ignoring case.

semanticValue

public abstract <T> T semanticValue()
Get the semantic value for this result.

Returns:
The semantic value for this result.
Throws:
java.lang.IllegalStateException - Signals that this result does not have a semantic value.

parseError

public abstract ParseError parseError()
Get the parse error for this result. If the result does not represent a parse error or does not have an embedded parse error, this method must return the dummy parse error.

Returns:
The parse error for this result.

select

public abstract ParseError select(ParseError error)
Select the more specific parse error. This method compares this result (i.e., either the parse error or the embedded parse error) with the specified parse error and returns the one representing the longer parse.

Parameters:
error - The error.
Returns:
The more specific parse error.

select

public abstract ParseError select(ParseError error,
                                  int index)
Select the more specific parse error. This method comparse this result (i.e., either the parse error or embedded parse error) with specified error and index. If this result represents an error beyond the specified error and index, it returns this result's error. Otherwise, it returns the specified parse error.

Parameters:
error - The error.
index - The index.
Returns:
The more specific parse error.

createValue

public abstract SemanticValue createValue(java.lang.Object value,
                                          ParseError error)
Create a semantic value based on this result. A straight-forward implementation of this method simply creates a new semantic value, using the specified actual value, this result's index, and the specified parse error:
   public SemanticValue value(Object value, ParseError error) {
     return new SemanticValue(value, index, error);
   }
 
However, for a result that already is a semantic value, a more sophisticated implementation can avoid creating a new semantic value if the specified actual value and parse error are identical to those for this result.

Parameters:
value - The actual value.
error - The embedded parse error.
Throws:
java.lang.IllegalStateException - Signals that this result is a parse error.


Copyright © 2012. All Rights Reserved.