xtc.parser
Class ParseError

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

public final class ParseError
extends Result

An erroneous parse.

Version:
$Revision: 1.27 $
Author:
Robert Grimm

Field Summary
static ParseError DUMMY
          The dummy parse error.
 java.lang.String msg
          The error message.
 
Fields inherited from class xtc.parser.Result
index
 
Constructor Summary
ParseError(java.lang.String msg, int index)
          Create a new parse error.
 
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 other)
          Select the more specific parse error.
 ParseError select(ParseError other, int index)
          Select the more specific parse error.
 ParseError select(java.lang.String msg, 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

DUMMY

public static final ParseError DUMMY
The dummy parse error. The dummy parse error is used for initializing a production's parse error and then threading the most specific parse error through the production. It works like a sentinel for managing linked lists, avoiding repeated tests for a null value.

See Also:
SemanticValue.error

msg

public final java.lang.String msg
The error message.

Constructor Detail

ParseError

public ParseError(java.lang.String msg,
                  int index)
Create a new parse error.

Parameters:
msg - The error message.
index - The index for the error location.
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 other)
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:
other - The error.
Returns:
The more specific parse error.

select

public ParseError select(ParseError other,
                         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:
other - The error.
index - The index.
Returns:
The more specific parse error.

select

public ParseError select(java.lang.String msg,
                         int index)
Select the more specific parse error. This method compares this parse error with the specified index and returns a parse error representing the longer parse (creating a new parse error with the specified message and index if necessary).

Parameters:
msg - The error message.
index - The index of the 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.