xtc.parser
Class SemanticValue

java.lang.Object
  extended by xtc.parser.Result
      extended by xtc.parser.SemanticValue

public final class SemanticValue
extends Result

A semantic value.

Version:
$Revision: 1.23 $
Author:
Robert Grimm

Field Summary
 ParseError error
          The embedded parse error.
 java.lang.Object value
          The actual value.
 
Fields inherited from class xtc.parser.Result
index
 
Constructor Summary
SemanticValue(java.lang.Object value, int index)
          Create a new semantic value.
SemanticValue(java.lang.Object value, int index, ParseError error)
          Create a new semantic value.
 
Method Summary
 SemanticValue createValue(java.lang.Object value, ParseError error)
          Create a semantic value based on this result.
 boolean hasValue()
          Determine whether this result has a value.
 boolean hasValue(java.lang.String s)
          Determine whether this result has the specified string value.
 boolean hasValueIgnoreCase(java.lang.String s)
          Determine whether this result has the specified string value, ignoring case.
 ParseError parseError()
          Get the parse error for this result.
 ParseError select(ParseError error)
          Select the more specific parse error.
 ParseError select(ParseError error, int index)
          Select the more specific parse error.
<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

value

public final java.lang.Object value
The actual value.


error

public final ParseError error
The embedded parse error. An embedded parse error is the most specific parse error encountered during the parse leading to this semantic value (typically, returned by an unsuccessful option). It is used to possibly replace a less specific parse error generated while continuing to parse the input. This field must not be null; instead, a dummy parse error should be used.

Constructor Detail

SemanticValue

public SemanticValue(java.lang.Object value,
                     int index)
Create a new semantic value.

Parameters:
value - The value.
index - The index into the rest of the input.

SemanticValue

public SemanticValue(java.lang.Object value,
                     int index,
                     ParseError error)
Create a new semantic value.

Parameters:
value - The value.
index - The index into the rest of the input.
error - The embedded parse error.
Method Detail

hasValue

public boolean hasValue()
Description copied from class: Result
Determine whether this result has a value.

Specified by:
hasValue in class Result
Returns:
true if this result has a value.

hasValue

public boolean hasValue(java.lang.String s)
Description copied from class: Result
Determine whether this result has the specified string value. The specified value must not be null.

Specified by:
hasValue in class Result
Parameters:
s - The string value.
Returns:
true if this result has the specified string value.

hasValueIgnoreCase

public boolean hasValueIgnoreCase(java.lang.String s)
Description copied from class: Result
Determine whether this result has the specified string value, ignoring case. The specified value must not be null.

Specified by:
hasValueIgnoreCase in class Result
Parameters:
s - The string value.
Returns:
true if this result has the specified string value, ignoring case.

semanticValue

public <T> T semanticValue()
Description copied from class: Result
Get the semantic value for this result.

Specified by:
semanticValue in class Result
Returns:
The semantic value for this result.

parseError

public ParseError parseError()
Description copied from class: Result
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.

Specified by:
parseError in class Result
Returns:
The parse error for this result.

select

public ParseError select(ParseError error)
Description copied from class: Result
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.

Specified by:
select in class Result
Parameters:
error - The error.
Returns:
The more specific parse error.

select

public ParseError select(ParseError error,
                         int index)
Description copied from class: Result
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.

Specified by:
select in class Result
Parameters:
error - The error.
index - The index.
Returns:
The more specific parse error.

createValue

public SemanticValue createValue(java.lang.Object value,
                                 ParseError error)
Description copied from class: Result
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.

Specified by:
createValue in class Result
Parameters:
value - The actual value.
error - The embedded parse error.


Copyright © 2012. All Rights Reserved.