jfun.parsec

Class Terms

public final class Terms extends Object implements Serializable

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

Author: Ben Yu Nov 20, 2004

Method Summary
static <R> Parser<R>charParser(String name, FromChar<R> fc)
gets a Parser object to parse Character token.
static <R> Parser<R>charParser(FromChar<R> fc)
gets a Parser object to parse Character token.
static <R> Parser<R>decimalParser(String name, FromString<R> fc)
gets a Parser object to parse TokenDecimal.
static <R> Parser<R>decimalParser(FromString<R> fc)
gets a Parser object to parse TokenDecimal.
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 <T,R> FromToken<R>fromTypedToken(T[] types, FromString<R> f)
Get a FromToken object that only recognizes a token of certain types.
static TermsgetCaseInsensitive(String[] ops, 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 TermsgetCaseInsensitive(Parser<?> wscanner, String[] ops, 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 TermsgetCaseInsensitive(Parser<?> wscanner, String[] ops, 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 TermsgetCaseInsensitiveInstance(String[] ops, 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 TermsgetCaseInsensitiveInstance(Parser<?> wscanner, String[] ops, 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 TermsgetCaseInsensitiveInstance(Parser<?> wscanner, String[] ops, 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 TermsgetCaseSensitive(String[] ops, 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 TermsgetCaseSensitive(Parser<?> wscanner, String[] ops, 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 TermsgetCaseSensitive(Parser<?> wscanner, String[] ops, 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 TermsgetCaseSensitiveInstance(String[] ops, 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 TermsgetCaseSensitiveInstance(Parser<?> wscanner, String[] ops, 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 TermsgetCaseSensitiveInstance(Parser<?> wscanner, String[] ops, 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.
Parser<Tok>getLexer()
gets the lexer for the terminals.
static TermsgetOperators(String... ops)
Creates a Terms object for lexing the operators with names specified in ops.
static TermsgetOperatorsInstance(String... ops)
Creates a Terms object for lexing the operators with names specified in ops.
Parser<Tok>getParser(String... tnames)
gets the parser for the terminals identified by tnames.
Parser<Tok>getParser(String name, String[] tnames)
gets the parser for the terminals identified by tnames.
Parser<Tok>getParser(String[] tnames, String expected)
gets the parser for the terminals identified by tnames.
Parser<Tok>getParser(String name, String[] tnames, String expected)
gets the parser for the terminals identified by tnames.
Parser<Tok>getParser(String name, String tname, String expected)
gets the parser for a terminal identified by tname.
Parser<Tok>getParser(String tname, String expected)
gets the parser for a terminal identified by tname.
Parser<Tok>getParser(String tname)
gets the parser for a terminal identified by tname.
static <R> Parser<R>integerParser(String name, 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(String name, FromString<R> fs)
gets a Parser object to parse token of arbitrary length integer.
static <R> Parser<R>integerParser(FromLong<R> fc)
gets a Parser object to parse Long token.
static <R> Parser<R>quotedWordParser(String name, FromString3<R> fc)
gets a Parser object to parse TokenQuoted.
static <R> Parser<R>quotedWordParser(FromString3<R> fc)
gets a Parser object to parse TokenQuoted.
static <R> Parser<R>stringParser(String name, FromString<R> fc)
gets a Parser object to parse String token.
static <R> Parser<R>stringParser(FromString<R> fc)
gets a Parser object to parse String token.
static <R> Parser<R>wordParser(String name, FromString<R> fc)
gets a Parser object to parse TokenWord.
static <R> Parser<R>wordParser(FromString<R> fc)
gets a Parser object to parse TokenWord.

Method Detail

charParser

public static <R> Parser<R> charParser(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

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

decimalParser

public static <R> Parser<R> decimalParser(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

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

getCaseInsensitive

public static Terms getCaseInsensitive(String[] ops, String[] keywords)

Deprecated: Use (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.

getCaseInsensitive

public static Terms getCaseInsensitive(Parser<?> wscanner, String[] ops, String[] keywords)

Deprecated: Use (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.

getCaseInsensitive

public static Terms getCaseInsensitive(Parser<?> wscanner, String[] ops, String[] keywords, FromString<?> toWord)

Deprecated: Use (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.

getCaseInsensitiveInstance

public static Terms getCaseInsensitiveInstance(String[] ops, 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

getCaseInsensitiveInstance

public static Terms getCaseInsensitiveInstance(Parser<?> wscanner, String[] ops, 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

getCaseInsensitiveInstance

public static Terms getCaseInsensitiveInstance(Parser<?> wscanner, String[] ops, 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

getCaseSensitive

public static Terms getCaseSensitive(String[] ops, String[] keywords)

Deprecated: Use (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.

getCaseSensitive

public static Terms getCaseSensitive(Parser<?> wscanner, String[] ops, String[] keywords)

Deprecated: Use (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.

getCaseSensitive

public static Terms getCaseSensitive(Parser<?> wscanner, String[] ops, String[] keywords, FromString<?> toWord)

Deprecated: Use (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.

getCaseSensitiveInstance

public static Terms getCaseSensitiveInstance(String[] ops, 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

getCaseSensitiveInstance

public static Terms getCaseSensitiveInstance(Parser<?> wscanner, String[] ops, 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

getCaseSensitiveInstance

public static Terms getCaseSensitiveInstance(Parser<?> wscanner, String[] ops, 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

getLexer

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

Returns: the lexer.

getOperators

public static Terms getOperators(String... ops)

Deprecated: Use (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.

getOperatorsInstance

public static Terms getOperatorsInstance(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

getParser

public Parser<Tok> getParser(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(String name, 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(String[] tnames, 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(String name, String[] tnames, 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(String name, String tname, 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(String tname, 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(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.

integerParser

public static <R> Parser<R> integerParser(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(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

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

quotedWordParser

public static <R> Parser<R> quotedWordParser(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

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

stringParser

public static <R> Parser<R> stringParser(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

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

wordParser

public static <R> Parser<R> wordParser(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

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