net.sf.jga.parser
Class FunctorParser

java.lang.Object
  extended by net.sf.jga.parser.FunctorParser
All Implemented Interfaces:
FunctorParserConstants
Direct Known Subclasses:
GenericParser

public class FunctorParser
extends java.lang.Object
implements FunctorParserConstants

Parser that converts java-like expressions into functors. The parser is not safe to be used concurrently by multiple threads.


Field Summary
static java.lang.String[] ARG_NAME
           
 Token jj_nt
           
 boolean lookingAhead
           
 Token token
           
 FunctorParserTokenManager token_source
           
 
Fields inherited from interface net.sf.jga.parser.FunctorParserConstants
CHARACTER_LITERAL, CLASS, DECIMAL_LITERAL, DEFAULT, DIGIT, EOF, EXPONENT, FALSE, FLOATING_POINT_LITERAL, HEX_LITERAL, IDENTIFIER, INSTANCEOF, INTEGER_LITERAL, LETTER, LPAREN, NEW, NULL, OCTAL_LITERAL, STRING_LITERAL, THIS, tokenImage, TRUE
 
Constructor Summary
FunctorParser()
           
FunctorParser(CharStream stream)
           
FunctorParser(FunctorParserTokenManager tm)
           
FunctorParser(java.io.InputStream is)
           
FunctorParser(java.io.Reader in)
           
 
Method Summary
 FunctorRef AdditiveExpression()
           
 FunctorRef AllocationExpression()
           
 FunctorRef AndExpression()
           
 FunctorRef[] ArgumentList(FunctorRef[] args)
           
 FunctorRef[] Arguments()
           
 void bindThis(java.lang.Object thisBinding)
          Binds the object to which 'this' refers
 FunctorRef Boolean()
           
 FunctorRef CastExpression()
           
 void CastLookahead()
           
 FunctorRef Character()
           
 FunctorRef ClassOrInterfaceType()
           
 FunctorRef ConditionalAndExpression()
           
 FunctorRef ConditionalExpression()
           
 FunctorRef ConditionalOrExpression()
           
 void deportClass(java.lang.String alias)
          Removes information about the class imported under the given name.
 void disable_tracing()
           
 void enable_tracing()
           
 FunctorRef EqualityExpression()
           
 FunctorRef Expression()
           
 FunctorRef Float()
           
 FunctorRef Functor()
           
 ParseException generateParseException()
           
protected  java.lang.Object getBoundObject()
          Returns the current object to which 'this' refers
 java.lang.reflect.Field getImportedField(java.lang.String name)
          Returns the imported field with the given name, or null if no such field has been imported.
 java.lang.reflect.Method[] getImportedMethods(java.lang.String name)
          Returns a list of methods with the given name
static FunctorParser getInstance()
          Returns a globally accessible default instance of a FunctorParser.
 Token getNextToken()
           
 java.lang.Class getReturnType()
          Returns the type of object returned by the last functor parsed.
 Token getToken(int index)
           
 void importClass(java.lang.Class clasz)
          Imports the given class into the parser.
 void importClass(java.lang.String alias, java.lang.Class clasz)
          Imports the given class into the parser under the given alias.
 void ImportedMethodLookahead()
           
 FunctorRef ImportedStaticMethodCall()
           
 void importField(java.lang.Class clasz, java.lang.String name)
          Imports the given static member.
 void importField(java.lang.reflect.Field field)
          Imports the given static member.
 void importMethod(java.lang.Class clasz, java.lang.String name)
          Imports the given static method(s).
 void importMethod(java.lang.reflect.Method meth)
          Imports a static method into the parser.
 void importMethod(java.lang.String name, java.lang.reflect.Method meth)
          Imports a static method into the parser under the given name.
 void importStatics(java.lang.Class clasz)
          Imports all of the static public methods and members in the given class.
 FunctorRef InstanceOfExpression()
           
 FunctorRef Integer()
           
 boolean isUndecoratedDecimal()
          When true, an undecorated number containing a decimal, for example 1.50 is interpreted as a BigDecimal literal.
 FunctorRef Literal()
           
static void main(java.lang.String[] args)
           
 FunctorRef MultiplicativeExpression()
           
 FunctorRef Name()
           
 FunctorRef Null()
           
 FunctorRef OrExpression()
           
static Generator parse(java.lang.String str)
          Parses the string to create a Generator.
static UnaryFunctor parse(java.lang.String str, java.lang.Class argType)
          Parses the string to create a UnaryFunctor that takes an argument of the given type.
static BinaryFunctor parse(java.lang.String str, java.lang.Class arg1Type, java.lang.Class arg2Type)
          Parses the string to create a BinaryFunctor that takes arguments of the given types.
 BinaryFunctor parseBinary(java.lang.Class arg1Type, java.lang.Class arg2Type)
          Parses the current input to create a BinaryFunctor that takes arguments of the given types.
 BinaryFunctor parseBinary(java.lang.String str, java.lang.Class arg1Type, java.lang.Class arg2Type)
          Parses the string to create a BinaryFunctor that takes arguments of the given types.
 Generator parseGenerator()
          Parses the contents of the current input to create a Generator
 Generator parseGenerator(java.lang.String str)
          Parses the string to create a Generator.
 UnaryFunctor parseUnary(java.lang.Class argType)
          Parses the current input to create a UnaryFunctor that takes an argument of the given type.
 UnaryFunctor parseUnary(java.lang.String str, java.lang.Class argType)
          Parses the string to create a UnaryFunctor that takes an argument of the given type.
 FunctorRef PrimaryExpression()
           
 FunctorRef PrimaryPrefix()
           
 FunctorRef PrimarySuffix(FunctorRef prefix)
           
 void ReInit(CharStream stream)
           
 void ReInit(FunctorParserTokenManager tm)
           
 FunctorRef RelationalExpression()
           
protected  FunctorRef reservedFunction(java.lang.String name, FunctorRef[] args)
          Allows for function-style names to be added to the grammar.
protected  FunctorRef reservedWord(java.lang.String name)
          Allows for (not necessarily constant) values to be added to the grammar
protected  FunctorRef resolveMethodName(FunctorRef prefix, java.lang.String name, FunctorRef[] args)
          Returns a functor ref containing a functor that corresponds to a call to the named method with the given args.
 void setUndecoratedDecimal(boolean flag)
          Enables/Disables the interpretation of undecorated decimal literals as BigDecimals.
 FunctorRef ShiftExpression()
           
 FunctorRef String()
           
 FunctorRef UnaryExpression()
           
 FunctorRef XorExpression()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ARG_NAME

public static final java.lang.String[] ARG_NAME

token_source

public FunctorParserTokenManager token_source

token

public Token token

jj_nt

public Token jj_nt

lookingAhead

public boolean lookingAhead
Constructor Detail

FunctorParser

public FunctorParser()

FunctorParser

public FunctorParser(java.io.InputStream is)

FunctorParser

public FunctorParser(java.io.Reader in)

FunctorParser

public FunctorParser(CharStream stream)

FunctorParser

public FunctorParser(FunctorParserTokenManager tm)
Method Detail

main

public static void main(java.lang.String[] args)

importClass

public void importClass(java.lang.Class clasz)
Imports the given class into the parser. The class will not need to be fully qualified for use in expressions. This will replace any existing imported class that happens to have the same name.


importClass

public void importClass(java.lang.String alias,
                        java.lang.Class clasz)
Imports the given class into the parser under the given alias. The alias may be used in place of the fully qualified name of the class hereafter. This will replace any existing imported class associated with the alias.


deportClass

public void deportClass(java.lang.String alias)
Removes information about the class imported under the given name.


importStatics

public void importStatics(java.lang.Class clasz)
Imports all of the static public methods and members in the given class.


importField

public void importField(java.lang.Class clasz,
                        java.lang.String name)
                 throws java.lang.NoSuchFieldException
Imports the given static member. The member will not need to be qualified with its classname for use in expressions.

Throws:
java.lang.NoSuchFieldException - if the named field does not exist
java.lang.IllegalArgumentException - if the named field is not static

importField

public void importField(java.lang.reflect.Field field)
                 throws java.lang.IllegalArgumentException
Imports the given static member. The member will not need to be qualified with its classname for use in expressions.

Throws:
java.lang.IllegalArgumentException - if the field is not static

getImportedField

public java.lang.reflect.Field getImportedField(java.lang.String name)
Returns the imported field with the given name, or null if no such field has been imported.


importMethod

public void importMethod(java.lang.Class clasz,
                         java.lang.String name)
                  throws java.lang.NoSuchMethodException
Imports the given static method(s).

Throws:
java.lang.NoSuchMethodException - if the named method does not exist, or if it/they is/are not static

importMethod

public void importMethod(java.lang.reflect.Method meth)
Imports a static method into the parser. The method will not need to be qualified with its classname for use in expressions. Multiple methods may be imported with the same name: the first best fit will be used when the method name is used.

Throws:
java.lang.NoSuchMethodException - if the named method does not exist
java.lang.IllegalArgumentException - if the named method is not static

importMethod

public void importMethod(java.lang.String name,
                         java.lang.reflect.Method meth)
Imports a static method into the parser under the given name. The method will not need to be qualified with its classname for use in expressions. Multiple methods may be imported with the same name: the first best fit will be used when the method name is used.

Throws:
java.lang.IllegalArgumentException - if the method is not static

getImportedMethods

public java.lang.reflect.Method[] getImportedMethods(java.lang.String name)
Returns a list of methods with the given name


reservedWord

protected FunctorRef reservedWord(java.lang.String name)
                           throws ParseException
Allows for (not necessarily constant) values to be added to the grammar

Throws:
ParseException

reservedFunction

protected FunctorRef reservedFunction(java.lang.String name,
                                      FunctorRef[] args)
                               throws ParseException
Allows for function-style names to be added to the grammar.

Throws:
ParseException

bindThis

public void bindThis(java.lang.Object thisBinding)
Binds the object to which 'this' refers


getBoundObject

protected java.lang.Object getBoundObject()
Returns the current object to which 'this' refers


setUndecoratedDecimal

public void setUndecoratedDecimal(boolean flag)
Enables/Disables the interpretation of undecorated decimal literals as BigDecimals. When true, an undecorated number containing a decimal, for example 1.50 is interpreted as a BigDecimal literal. When false, the same token is interpreted as a Double, as is the case in standard java


isUndecoratedDecimal

public boolean isUndecoratedDecimal()
When true, an undecorated number containing a decimal, for example 1.50 is interpreted as a BigDecimal literal. When false, the same token is interpreted as a Double, as is the case in standard java


parseGenerator

public Generator parseGenerator(java.lang.String str)
                         throws ParseException
Parses the string to create a Generator.

Throws:
ParseException

parseGenerator

public Generator parseGenerator()
                         throws ParseException
Parses the contents of the current input to create a Generator

Throws:
ParseException

parseUnary

public UnaryFunctor parseUnary(java.lang.String str,
                               java.lang.Class argType)
                        throws ParseException
Parses the string to create a UnaryFunctor that takes an argument of the given type.

Throws:
ParseException

parseUnary

public UnaryFunctor parseUnary(java.lang.Class argType)
                        throws ParseException
Parses the current input to create a UnaryFunctor that takes an argument of the given type.

Throws:
ParseException

parseBinary

public BinaryFunctor parseBinary(java.lang.String str,
                                 java.lang.Class arg1Type,
                                 java.lang.Class arg2Type)
                          throws ParseException
Parses the string to create a BinaryFunctor that takes arguments of the given types.

Throws:
ParseException

parseBinary

public BinaryFunctor parseBinary(java.lang.Class arg1Type,
                                 java.lang.Class arg2Type)
                          throws ParseException
Parses the current input to create a BinaryFunctor that takes arguments of the given types.

Throws:
ParseException

getReturnType

public java.lang.Class getReturnType()
Returns the type of object returned by the last functor parsed.

Throws:
java.lang.IllegalStateException - if the parser has not been used or if parsing the last functor resulted in an exception being thrown.

getInstance

public static FunctorParser getInstance()
Returns a globally accessible default instance of a FunctorParser. Do not configure this instance as any changes made will affect all code that accesses this class through a given classloader.


parse

public static Generator parse(java.lang.String str)
                       throws UncheckedParseException
Parses the string to create a Generator.

Throws:
UncheckedParseException

parse

public static UnaryFunctor parse(java.lang.String str,
                                 java.lang.Class argType)
                          throws UncheckedParseException
Parses the string to create a UnaryFunctor that takes an argument of the given type.

Throws:
UncheckedParseException

parse

public static BinaryFunctor parse(java.lang.String str,
                                  java.lang.Class arg1Type,
                                  java.lang.Class arg2Type)
                           throws UncheckedParseException
Parses the string to create a BinaryFunctor that takes arguments of the given types.

Throws:
UncheckedParseException

resolveMethodName

protected FunctorRef resolveMethodName(FunctorRef prefix,
                                       java.lang.String name,
                                       FunctorRef[] args)
                                throws ParseException
Returns a functor ref containing a functor that corresponds to a call to the named method with the given args.

Throws:
ParseException

Functor

public final FunctorRef Functor()
                         throws ParseException
Throws:
ParseException

Expression

public final FunctorRef Expression()
                            throws ParseException
Throws:
ParseException

ConditionalExpression

public final FunctorRef ConditionalExpression()
                                       throws ParseException
Throws:
ParseException

ConditionalOrExpression

public final FunctorRef ConditionalOrExpression()
                                         throws ParseException
Throws:
ParseException

ConditionalAndExpression

public final FunctorRef ConditionalAndExpression()
                                          throws ParseException
Throws:
ParseException

OrExpression

public final FunctorRef OrExpression()
                              throws ParseException
Throws:
ParseException

XorExpression

public final FunctorRef XorExpression()
                               throws ParseException
Throws:
ParseException

AndExpression

public final FunctorRef AndExpression()
                               throws ParseException
Throws:
ParseException

EqualityExpression

public final FunctorRef EqualityExpression()
                                    throws ParseException
Throws:
ParseException

InstanceOfExpression

public final FunctorRef InstanceOfExpression()
                                      throws ParseException
Throws:
ParseException

RelationalExpression

public final FunctorRef RelationalExpression()
                                      throws ParseException
Throws:
ParseException

ShiftExpression

public final FunctorRef ShiftExpression()
                                 throws ParseException
Throws:
ParseException

AdditiveExpression

public final FunctorRef AdditiveExpression()
                                    throws ParseException
Throws:
ParseException

MultiplicativeExpression

public final FunctorRef MultiplicativeExpression()
                                          throws ParseException
Throws:
ParseException

UnaryExpression

public final FunctorRef UnaryExpression()
                                 throws ParseException
Throws:
ParseException

CastLookahead

public final void CastLookahead()
                         throws ParseException
Throws:
ParseException

CastExpression

public final FunctorRef CastExpression()
                                throws ParseException
Throws:
ParseException

PrimaryExpression

public final FunctorRef PrimaryExpression()
                                   throws ParseException
Throws:
ParseException

PrimaryPrefix

public final FunctorRef PrimaryPrefix()
                               throws ParseException
Throws:
ParseException

AllocationExpression

public final FunctorRef AllocationExpression()
                                      throws ParseException
Throws:
ParseException

ClassOrInterfaceType

public final FunctorRef ClassOrInterfaceType()
                                      throws ParseException
Throws:
ParseException

PrimarySuffix

public final FunctorRef PrimarySuffix(FunctorRef prefix)
                               throws ParseException
Throws:
ParseException

ImportedMethodLookahead

public final void ImportedMethodLookahead()
                                   throws ParseException
Throws:
ParseException

ImportedStaticMethodCall

public final FunctorRef ImportedStaticMethodCall()
                                          throws ParseException
Throws:
ParseException

Name

public final FunctorRef Name()
                      throws ParseException
Throws:
ParseException

Arguments

public final FunctorRef[] Arguments()
                             throws ParseException
Throws:
ParseException

ArgumentList

public final FunctorRef[] ArgumentList(FunctorRef[] args)
                                throws ParseException
Throws:
ParseException

Literal

public final FunctorRef Literal()
                         throws ParseException
Throws:
ParseException

Integer

public final FunctorRef Integer()
                         throws ParseException
Throws:
ParseException

Float

public final FunctorRef Float()
                       throws ParseException
Throws:
ParseException

Boolean

public final FunctorRef Boolean()
                         throws ParseException
Throws:
ParseException

Character

public final FunctorRef Character()
                           throws ParseException
Throws:
ParseException

String

public final FunctorRef String()
                        throws ParseException
Throws:
ParseException

Null

public final FunctorRef Null()
                      throws ParseException
Throws:
ParseException

ReInit

public void ReInit(CharStream stream)

ReInit

public void ReInit(FunctorParserTokenManager tm)

getNextToken

public final Token getNextToken()

getToken

public final Token getToken(int index)

generateParseException

public ParseException generateParseException()

enable_tracing

public final void enable_tracing()

disable_tracing

public final void disable_tracing()


Copyright © 2002-2005 David A. Hall. All Rights Reserved.