net.percederberg.grammatica.parser
Class TokenPattern

java.lang.Object
  extended bynet.percederberg.grammatica.parser.TokenPattern

public class TokenPattern
extends java.lang.Object

A token pattern. This class contains the definition of a token (i.e. it's pattern), and allows testing a string against this pattern. A token pattern is uniquely identified by an integer id, that must be provided upon creation.


Field Summary
static int REGEXP_TYPE
          The regular expression pattern type.
static int STRING_TYPE
          The string pattern type.
 
Constructor Summary
TokenPattern(int id, java.lang.String name, int type, java.lang.String pattern)
          Creates a new token pattern.
 
Method Summary
 java.lang.String getErrorMessage()
          Returns the token error message if the pattern corresponds to an error token.
 int getId()
          Returns the unique token pattern identity value.
 java.lang.String getIgnoreMessage()
          Returns the token ignore message if the pattern corresponds to an ignored token.
 java.lang.String getName()
          Returns the token pattern name.
 java.lang.String getPattern()
          Returns te token pattern.
 int getType()
          Returns the token pattern type.
 boolean isError()
          Checks if the pattern corresponds to an error token.
 boolean isIgnore()
          Checks if the pattern corresponds to an ignored token.
 void setError()
          Sets the token error flag and assigns a default error message.
 void setError(java.lang.String message)
          Sets the token error flag and assigns the specified error message.
 void setIgnore()
          Sets the token ignore flag and clears the ignore message.
 void setIgnore(java.lang.String message)
          Sets the token ignore flag and assigns the specified ignore message.
 java.lang.String toShortString()
          Returns a short string representation of this object.
 java.lang.String toString()
          Returns a detailed string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STRING_TYPE

public static final int STRING_TYPE
The string pattern type. This pattern type is used for tokens that only match an exact string.

See Also:
Constant Field Values

REGEXP_TYPE

public static final int REGEXP_TYPE
The regular expression pattern type. This pattern type is used for tokens that match a regular expression.

See Also:
Constant Field Values
Constructor Detail

TokenPattern

public TokenPattern(int id,
                    java.lang.String name,
                    int type,
                    java.lang.String pattern)
Creates a new token pattern.

Parameters:
id - the token pattern id
name - the token pattern name
type - the token pattern type
pattern - the token pattern
Method Detail

isError

public boolean isError()
Checks if the pattern corresponds to an error token. If this is true, it means that an error should be reported if a matching token is found.

Returns:
true if the pattern maps to an error token, or false otherwise

isIgnore

public boolean isIgnore()
Checks if the pattern corresponds to an ignored token. If this is true, it means that the token should be ignored if found.

Returns:
true if the pattern maps to an ignored token, or false otherwise

getId

public int getId()
Returns the unique token pattern identity value.

Returns:
the token pattern id

getName

public java.lang.String getName()
Returns the token pattern name.

Returns:
the token pattern name

getType

public int getType()
Returns the token pattern type.

Returns:
the token pattern type
See Also:
STRING_TYPE, REGEXP_TYPE

getPattern

public java.lang.String getPattern()
Returns te token pattern.

Returns:
the token pattern

getErrorMessage

public java.lang.String getErrorMessage()
Returns the token error message if the pattern corresponds to an error token.

Returns:
the token error message

getIgnoreMessage

public java.lang.String getIgnoreMessage()
Returns the token ignore message if the pattern corresponds to an ignored token.

Returns:
the token ignore message

setError

public void setError()
Sets the token error flag and assigns a default error message.


setError

public void setError(java.lang.String message)
Sets the token error flag and assigns the specified error message.

Parameters:
message - the error message to display

setIgnore

public void setIgnore()
Sets the token ignore flag and clears the ignore message.


setIgnore

public void setIgnore(java.lang.String message)
Sets the token ignore flag and assigns the specified ignore message.

Parameters:
message - the ignore message to display

toString

public java.lang.String toString()
Returns a detailed string representation of this object.

Returns:
a detailed string representation of this object

toShortString

public java.lang.String toShortString()
Returns a short string representation of this object.

Returns:
a short string representation of this object