jfun.parsec
Class Terms

java.lang.Object
  extended by jfun.parsec.Terms
All Implemented Interfaces:
java.io.Serializable

public final class Terms
extends java.lang.Object
implements java.io.Serializable

This helper class provides convenient api's to build lexer and parsers for terminals.

Author:
Ben Yu Nov 20, 2004
See Also:
Serialized Form

Method Summary
static
<R> Parser<R>
charParser(FromChar<R> fc)
          gets a Parser object to parse Character token.
static
<R> Parser<R>
charParser(java.lang.String name, FromChar<R> fc)
          gets a Parser object to parse Character token.
static
<R> Parser<R>
decimalParser(FromString<R> fc)
          gets a Parser object to parse TokenDecimal.
static
<R> Parser<R>
decimalParser(java.lang.String name, FromString<R> fc)
          gets a Parser object to parse TokenDecimal.
static
<T,R> FromToken<R>
fromTypedToken(T[] types, FromString<R> f)
          Get a FromToken object that only recognizes a token of certain types.
static
<T,R> FromToken<R>
fromTypedToken(T type, FromString<R> f)
          Get a FromToken object that only recognizes a token of a certain type.
static Terms getCaseInsensitive(Parser<?> wscanner, java.lang.String[] ops, java.lang.String[] keywords)
          Deprecated. Use getCaseInsensitiveInstance(Parser, String[], String[]) instead.
static Terms getCaseInsensitive(Parser<?> wscanner, java.lang.String[] ops, java.lang.String[] keywords, FromString<?> toWord)
          Deprecated. Use getCaseInsensitiveInstance(Parser, String[], String[], FromString) instead.
static Terms getCaseInsensitive(java.lang.String[] ops, java.lang.String[] keywords)
          Deprecated. Use getCaseInsensitiveInstance(String[], String[]) instead.
static Terms getCaseInsensitiveInstance(Parser<?> wscanner, java.lang.String[] ops, java.lang.String[] keywords)
          Creates a Terms object for lexing and parsing the operators with names specified in ops, and for lexing and parsing the keywords case insensitively.
static Terms getCaseInsensitiveInstance(Parser<?> wscanner, java.lang.String[] ops, java.lang.String[] keywords, FromString<?> toWord)
          Creates a Terms object for lexing and parsing the operators with names specified in ops, and for lexing and parsing the keywords case insensitively.
static Terms getCaseInsensitiveInstance(java.lang.String[] ops, java.lang.String[] keywords)
          Creates a Terms object for lexing and parsing the operators with names specified in ops, and for lexing and parsing the keywords case insensitively.
static Terms getCaseSensitive(Parser<?> wscanner, java.lang.String[] ops, java.lang.String[] keywords)
          Deprecated. Use getCaseSensitiveInstance(Parser, String[], String[]) instead.
static Terms getCaseSensitive(Parser<?> wscanner, java.lang.String[] ops, java.lang.String[] keywords, FromString<?> toWord)
          Deprecated. Use getCaseSensitiveInstance(Parser, String[], String[], FromString) instead.
static Terms getCaseSensitive(java.lang.String[] ops, java.lang.String[] keywords)
          Deprecated. Use getCaseSensitiveInstance(String[], String[]) instead.
static Terms getCaseSensitiveInstance(Parser<?> wscanner, java.lang.String[] ops, java.lang.String[] keywords)
          Creates a Terms object for lexing and parsing the operators with names specified in ops, and for lexing and parsing the keywords case sensitively.
static Terms getCaseSensitiveInstance(Parser<?> wscanner, java.lang.String[] ops, java.lang.String[] keywords, FromString<?> toWord)
          Creates a Terms object for lexing and parsing the operators with names specified in ops, and for lexing and parsing the keywords case sensitively.
static Terms getCaseSensitiveInstance(java.lang.String[] ops, java.lang.String[] keywords)
          Creates a Terms object for lexing and parsing the operators with names specified in ops, and for lexing and parsing the keywords case sensitively.
 Parser<Tok> getLexer()
          gets the lexer for the terminals.
static Terms getOperators(java.lang.String... ops)
          Deprecated. Use getOperatorsInstance(String[]) instead.
static Terms getOperatorsInstance(java.lang.String... ops)
          Creates a Terms object for lexing the operators with names specified in ops.
 Parser<Tok> getParser(java.lang.String... tnames)
          gets the parser for the terminals identified by tnames.
 Parser<Tok> getParser(java.lang.String tname)
          gets the parser for a terminal identified by tname.
 Parser<Tok> getParser(java.lang.String[] tnames, java.lang.String expected)
          gets the parser for the terminals identified by tnames.
 Parser<Tok> getParser(java.lang.String tname, java.lang.String expected)
          gets the parser for a terminal identified by tname.
 Parser<Tok> getParser(java.lang.String name, java.lang.String[] tnames)
          gets the parser for the terminals identified by tnames.
 Parser<Tok> getParser(java.lang.String name, java.lang.String[] tnames, java.lang.String expected)
          gets the parser for the terminals identified by tnames.
 Parser<Tok> getParser(java.lang.String name, java.lang.String tname, java.lang.String expected)
          gets the parser for a terminal identified by tname.
static
<R> Parser<R>
integerParser(FromLong<R> fc)
          gets a Parser object to parse Long token.
static
<R> Parser<R>
integerParser(FromString<R> fs)
          gets a Parser object to parse token of arbitrary length integer.
static
<R> Parser<R>
integerParser(java.lang.String name, FromLong<R> fc)
          gets a Parser object to parse Long token.
static
<R> Parser<R>
integerParser(java.lang.String name, FromString<R> fs)
          gets a Parser object to parse token of arbitrary length integer.
static
<R> Parser<R>
myParser(FromMyText<R> fm)
          Deprecated. 
static
<R> Parser<R>
myParser(int kind, FromString<R> fs)
          Deprecated. 
static
<R> Parser<R>
myParser(java.lang.String name, FromMyText<R> fm)
          Deprecated. 
static
<R> Parser<R>
myParser(java.lang.String name, int kind, FromString<R> fs)
          Deprecated. 
static
<R> Parser<R>
quotedWordParser(FromString3<R> fc)
          gets a Parser object to parse TokenQuoted.
static
<R> Parser<R>
quotedWordParser(java.lang.String name, FromString3<R> fc)
          gets a Parser object to parse TokenQuoted.
static
<R> Parser<R>
stringParser(FromString<R> fc)
          gets a Parser object to parse String token.
static
<R> Parser<R>
stringParser(java.lang.String name, FromString<R> fc)
          gets a Parser object to parse String token.
static
<R> Parser<R>
wordParser(FromString<R> fc)
          gets a Parser object to parse TokenWord.
static
<R> Parser<R>
wordParser(java.lang.String name, FromString<R> fc)
          gets a Parser object to parse TokenWord.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getParser

public Parser<Tok> getParser(java.lang.String... tnames)
gets the parser for the terminals identified by tnames. The Tok object is returned from the result parser.

Parameters:
tnames - the names of the terminals.
Returns:
the Parser.

getParser

public Parser<Tok> getParser(java.lang.String name,
                             java.lang.String[] tnames)
gets the parser for the terminals identified by tnames. The Tok object is returned.

Parameters:
name - the name of the parser.
tnames - the names of the terminals.
Returns:
the Parser.

getParser

public Parser<Tok> getParser(java.lang.String[] tnames,
                             java.lang.String expected)
gets the parser for the terminals identified by tnames. The Tok object is returned from the result parser.

Parameters:
tnames - the names of the terminals.
expected - the label when this parser fails.
Returns:
the Parser.

getParser

public Parser<Tok> getParser(java.lang.String name,
                             java.lang.String[] tnames,
                             java.lang.String expected)
gets the parser for the terminals identified by tnames. The Tok object is returned from the result parser.

Parameters:
name - the name of the parser.
tnames - the names of the terminals.
expected - the label when this parser fails.
Returns:
the Parser.

getParser

public Parser<Tok> getParser(java.lang.String name,
                             java.lang.String tname,
                             java.lang.String expected)
gets the parser for a terminal identified by tname. The Tok object is returned from the result parser.

Parameters:
name - the name of the parser.
tname - the name of the terminal.
expected - the label when this parser fails.
Returns:
the Parser.

getParser

public Parser<Tok> getParser(java.lang.String tname,
                             java.lang.String expected)
gets the parser for a terminal identified by tname. The Tok object is returned from the result parser.

Parameters:
tname - the name of the terminal.
expected - the label when this parser fails.
Returns:
the Parser.

getParser

public Parser<Tok> getParser(java.lang.String tname)
gets the parser for a terminal identified by tname. The Tok object is returned from the result parser.

Parameters:
tname - the name of the terminal.
Returns:
the Parser.

getLexer

public Parser<Tok> getLexer()
gets the lexer for the terminals.

Returns:
the lexer.

getCaseInsensitiveInstance

public static Terms getCaseInsensitiveInstance(java.lang.String[] ops,
                                               java.lang.String[] keywords)
Creates a Terms object for lexing and parsing the operators with names specified in ops, and for lexing and parsing the keywords case insensitively. Keywords and operators are lexed as TokenReserved. Words that are not among the keywords are lexed as TokenWord. A word is defined as an alpha numeric string that starts with [_a-zA-Z], with 0 or more [0-9_a-zA-Z] following.

Parameters:
ops - the operator names.
keywords - the keyword names.
Returns:
the Terms instance.
Since:
version 1.1

getCaseSensitiveInstance

public static Terms getCaseSensitiveInstance(java.lang.String[] ops,
                                             java.lang.String[] keywords)
Creates a Terms object for lexing and parsing the operators with names specified in ops, and for lexing and parsing the keywords case sensitively. Keywords and operators are lexed as TokenReserved. Words that are not among the keywords are lexed as TokenWord. A word is defined as an alpha numeric string that starts with [_a-zA-Z], with 0 or more [0-9_a-zA-Z] following.

Parameters:
ops - the operator names.
keywords - the keyword names.
Returns:
the Terms instance.
Since:
version 1.1

getCaseInsensitiveInstance

public static Terms getCaseInsensitiveInstance(Parser<?> wscanner,
                                               java.lang.String[] ops,
                                               java.lang.String[] keywords)
Creates a Terms object for lexing and parsing the operators with names specified in ops, and for lexing and parsing the keywords case insensitively. Keywords and operators are lexed as TokenReserved. Words that are not among the keywords are lexed as TokenWord.

Parameters:
wscanner - the scanner that identifies a word in the language.
ops - the operator names.
keywords - the keyword names.
Returns:
the Terms instance.
Since:
version 1.1

getCaseSensitiveInstance

public static Terms getCaseSensitiveInstance(Parser<?> wscanner,
                                             java.lang.String[] ops,
                                             java.lang.String[] keywords)
Creates a Terms object for lexing and parsing the operators with names specified in ops, and for lexing and parsing the keywords case sensitively. Keywords and operators are lexed as TokenReserved. Words that are not among the keywords are lexed as TokenWord.

Parameters:
wscanner - the scanner that identifies a word in the language.
ops - the operator names.
keywords - the keyword names.
Returns:
the Terms instance.
Since:
version 1.1

getCaseInsensitiveInstance

public static Terms getCaseInsensitiveInstance(Parser<?> wscanner,
                                               java.lang.String[] ops,
                                               java.lang.String[] keywords,
                                               FromString<?> toWord)
Creates a Terms object for lexing and parsing the operators with names specified in ops, and for lexing and parsing the keywords case insensitively. Keywords and operators are lexed as TokenReserved. Words that are not among the keywords are lexed as TokenWord.

Parameters:
wscanner - the scanner that identifies a word in the language.
ops - the operator names.
keywords - the keyword names.
toWord - the FromString object used to create a token for non-key words recognized by wscanner.
Returns:
the Terms instance.
Since:
version 1.1

getCaseSensitiveInstance

public static Terms getCaseSensitiveInstance(Parser<?> wscanner,
                                             java.lang.String[] ops,
                                             java.lang.String[] keywords,
                                             FromString<?> toWord)
Creates a Terms object for lexing and parsing the operators with names specified in ops, and for lexing and parsing the keywords case sensitively. Keywords and operators are lexed as TokenReserved. Words that are not among the keywords are lexed as TokenWord.

Parameters:
wscanner - the scanner that identifies a word in the language.
ops - the operator names.
keywords - the keyword names.
toWord - the FromString object used to create a token for non-key words recognized by wscanner.
Returns:
the Terms instance.
Since:
version 1.1

getOperatorsInstance

public static Terms getOperatorsInstance(java.lang.String... ops)
Creates a Terms object for lexing the operators with names specified in ops. Operators are lexed as TokenReserved.

Parameters:
ops - the operator names.
Returns:
the Terms instance.
Since:
version 1.1

getCaseInsensitive

public static Terms getCaseInsensitive(java.lang.String[] ops,
                                       java.lang.String[] keywords)
Deprecated. Use getCaseInsensitiveInstance(String[], String[]) instead.

Creates a Terms object for lexing and parsing the operators with names specified in ops, and for lexing and parsing the keywords case insensitively. Keywords and operators are lexed as TokenReserved. Words that are not among the keywords are lexed as TokenWord. A word is defined as an alpha numeric string that starts with [_a-zA-Z], with 0 or more [0-9_a-zA-Z] following.

Parameters:
ops - the operator names.
keywords - the keyword names.
Returns:
the Terms instance.

getCaseSensitive

public static Terms getCaseSensitive(java.lang.String[] ops,
                                     java.lang.String[] keywords)
Deprecated. Use getCaseSensitiveInstance(String[], String[]) instead.

Creates a Terms object for lexing and parsing the operators with names specified in ops, and for lexing and parsing the keywords case sensitively. Keywords and operators are lexed as TokenReserved. Words that are not among the keywords are lexed as TokenWord. A word is defined as an alpha numeric string that starts with [_a-zA-Z], with 0 or more [0-9_a-zA-Z] following.

Parameters:
ops - the operator names.
keywords - the keyword names.
Returns:
the Terms instance.

getCaseInsensitive

public static Terms getCaseInsensitive(Parser<?> wscanner,
                                       java.lang.String[] ops,
                                       java.lang.String[] keywords)
Deprecated. Use getCaseInsensitiveInstance(Parser, String[], String[]) instead.

Creates a Terms object for lexing and parsing the operators with names specified in ops, and for lexing and parsing the keywords case insensitively. Keywords and operators are lexed as TokenReserved. Words that are not among the keywords are lexed as TokenWord.

Parameters:
wscanner - the scanner that identifies a word in the language.
ops - the operator names.
keywords - the keyword names.
Returns:
the Terms instance.

getCaseSensitive

public static Terms getCaseSensitive(Parser<?> wscanner,
                                     java.lang.String[] ops,
                                     java.lang.String[] keywords)
Deprecated. Use getCaseSensitiveInstance(Parser, String[], String[]) instead.

Creates a Terms object for lexing and parsing the operators with names specified in ops, and for lexing and parsing the keywords case sensitively. Keywords and operators are lexed as TokenReserved. Words that are not among the keywords are lexed as TokenWord.

Parameters:
wscanner - the scanner that identifies a word in the language.
ops - the operator names.
keywords - the keyword names.
Returns:
the Terms instance.

getCaseInsensitive

public static Terms getCaseInsensitive(Parser<?> wscanner,
                                       java.lang.String[] ops,
                                       java.lang.String[] keywords,
                                       FromString<?> toWord)
Deprecated. Use getCaseInsensitiveInstance(Parser, String[], String[], FromString) instead.

Creates a Terms object for lexing and parsing the operators with names specified in ops, and for lexing and parsing the keywords case insensitively. Keywords and operators are lexed as TokenReserved. Words that are not among the keywords are lexed as TokenWord.

Parameters:
wscanner - the scanner that identifies a word in the language.
ops - the operator names.
keywords - the keyword names.
toWord - the FromString object used to create a token for non-key words recognized by wscanner.
Returns:
the Terms instance.

getCaseSensitive

public static Terms getCaseSensitive(Parser<?> wscanner,
                                     java.lang.String[] ops,
                                     java.lang.String[] keywords,
                                     FromString<?> toWord)
Deprecated. Use getCaseSensitiveInstance(Parser, String[], String[], FromString) instead.

Creates a Terms object for lexing and parsing the operators with names specified in ops, and for lexing and parsing the keywords case sensitively. Keywords and operators are lexed as TokenReserved. Words that are not among the keywords are lexed as TokenWord.

Parameters:
wscanner - the scanner that identifies a word in the language.
ops - the operator names.
keywords - the keyword names.
toWord - the FromString object used to create a token for non-key words recognized by wscanner.
Returns:
the Terms instance.

getOperators

public static Terms getOperators(java.lang.String... ops)
Deprecated. Use getOperatorsInstance(String[]) instead.

Creates a Terms object for lexing the operators with names specified in ops. Operators are lexed as TokenReserved.

Parameters:
ops - the operator names.
Returns:
the Terms instance.

charParser

public static <R> Parser<R> charParser(java.lang.String name,
                                       FromChar<R> fc)
gets a Parser object to parse Character token.

Parameters:
name - the parser name.
fc - the mapping to map char to an object returned by the parser.
Returns:
the parser

stringParser

public static <R> Parser<R> stringParser(java.lang.String name,
                                         FromString<R> fc)
gets a Parser object to parse String token.

Parameters:
name - the parser name.
fc - the mapping to map String to an object returned by the parser.
Returns:
the parser

quotedWordParser

public static <R> Parser<R> quotedWordParser(java.lang.String name,
                                             FromString3<R> fc)
gets a Parser object to parse TokenQuoted.

Parameters:
name - the parser name.
fc - the mapping to map the quoted string to an object returned by the parser.
Returns:
the parser

wordParser

public static <R> Parser<R> wordParser(java.lang.String name,
                                       FromString<R> fc)
gets a Parser object to parse TokenWord.

Parameters:
name - the parser name.
fc - the mapping to map the word to an object returned by the parser.
Returns:
the parser

myParser

@Deprecated
public static <R> Parser<R> myParser(FromMyText<R> fm)
Deprecated. 

Create a parser that recognizes MyToken object.

Parameters:
fm - the FromMyText object to recognize MyToken object.
Returns:
the Tokenizer object.

myParser

@Deprecated
public static <R> Parser<R> myParser(java.lang.String name,
                                                FromMyText<R> fm)
Deprecated. 

Create a parser that recognizes MyToken object.

Parameters:
name - the name of the parser object.
fm - the FromMyText object to recognize MyToken object.
Returns:
the Tokenizer object.

myParser

@Deprecated
public static <R> Parser<R> myParser(int kind,
                                                FromString<R> fs)
Deprecated. 

Create a parser that recognizes MyToken of a certain kind.

Parameters:
kind - the token kind to recognize.
fs - the FromString object to transform.
Returns:
the Parser object.

myParser

@Deprecated
public static <R> Parser<R> myParser(java.lang.String name,
                                                int kind,
                                                FromString<R> fs)
Deprecated. 

Create a parser that recognizes MyToken of a certain kind.

Parameters:
name - the Parser name.
kind - the token kind to recognize.
fs - the FromString object to transform.
Returns:
the Parser object.

integerParser

public static <R> Parser<R> integerParser(java.lang.String name,
                                          FromLong<R> fc)
gets a Parser object to parse Long token.

Parameters:
name - the parser name.
fc - the mapping to map the number to an object returned by the parser.
Returns:
the parser

integerParser

public static <R> Parser<R> integerParser(FromString<R> fs)
gets a Parser object to parse token of arbitrary length integer.

Parameters:
fs - the mapping to map the number to an object returned by the parser.
Returns:
the parser

integerParser

public static <R> Parser<R> integerParser(java.lang.String name,
                                          FromString<R> fs)
gets a Parser object to parse token of arbitrary length integer.

Parameters:
name - the parser name.
fs - the mapping to map the number to an object returned by the parser.
Returns:
the parser

decimalParser

public static <R> Parser<R> decimalParser(java.lang.String name,
                                          FromString<R> fc)
gets a Parser object to parse TokenDecimal.

Parameters:
name - the parser name.
fc - the mapping to map the decimal to an object returned by the parser.
Returns:
the parser

charParser

public static <R> Parser<R> charParser(FromChar<R> fc)
gets a Parser object to parse Character token.

Parameters:
fc - the mapping to map char to an object returned by the parser.
Returns:
the parser

stringParser

public static <R> Parser<R> stringParser(FromString<R> fc)
gets a Parser object to parse String token.

Parameters:
fc - the mapping to map String to an object returned by the parser.
Returns:
the parser

quotedWordParser

public static <R> Parser<R> quotedWordParser(FromString3<R> fc)
gets a Parser object to parse TokenQuoted.

Parameters:
fc - the mapping to map the quoted string to an object returned by the parser.
Returns:
the parser

wordParser

public static <R> Parser<R> wordParser(FromString<R> fc)
gets a Parser object to parse TokenWord.

Parameters:
fc - the mapping to map the word to an object returned by the parser.
Returns:
the parser

integerParser

public static <R> Parser<R> integerParser(FromLong<R> fc)
gets a Parser object to parse Long token.

Parameters:
fc - the mapping to map the number to an object returned by the parser.
Returns:
the parser

decimalParser

public static <R> Parser<R> decimalParser(FromString<R> fc)
gets a Parser object to parse TokenDecimal.

Parameters:
fc - the mapping to map the decimal to an object returned by the parser.
Returns:
the parser

fromTypedToken

public static <T,R> FromToken<R> fromTypedToken(T type,
                                                FromString<R> f)
Get a FromToken object that only recognizes a token of a certain type.

Parameters:
type - the token type recognized.
f - the FromString object used to translate the character range to a certain object.
Returns:
the FromToken object.
Since:
version 1.1

fromTypedToken

public static <T,R> FromToken<R> fromTypedToken(T[] types,
                                                FromString<R> f)
Get a FromToken object that only recognizes a token of certain types.

Parameters:
types - the token types recognized.
f - the FromString object used to translate the character range to a certain object.
Returns:
the FromToken object.
Since:
version 1.1