fmpp.tdd
Class Interpreter

java.lang.Object
  extended by fmpp.tdd.Interpreter

public class Interpreter
extends java.lang.Object

Evaluates TDD expressions.


Field Summary
static EvaluationEnvironment SIMPLE_EVALUATION_ENVIRONMENT
          Evaluates function calls to itself.
 
Method Summary
static java.lang.String dump(java.lang.Object value)
          Converts an object to a TDD-like representation (not necessary valid TDD).
static java.lang.Object eval(Fragment fragment, EvaluationEnvironment ee, boolean forceStringValues)
          Evaluates a Fragment as single TDD expression.
static java.lang.Object eval(java.lang.String text)
          Same as eval(text, null, false, null).
static java.lang.Object eval(java.lang.String text, EvaluationEnvironment ee, boolean forceStringValues, java.lang.String fileName)
          Evaluates text as single TDD expression.
static java.lang.Object eval(java.lang.String text, java.lang.String fileName)
          Same as eval(text, null, false, fileName).
static java.util.Map evalAsHash(java.lang.String text)
          Same as evalAsHash(text, null, false, null).
static java.util.Map evalAsHash(java.lang.String text, EvaluationEnvironment ee, boolean forceStringValues, java.lang.String fileName)
          Evaluates text as a list of key:value pairs.
static java.util.Map evalAsHash(java.lang.String text, java.lang.String fileName)
          Same as evalAsHash(text, null, false, fileName).
static java.util.List evalAsSequence(java.lang.String text)
          Same as evalAsList(text, null, false, null).
static java.util.List evalAsSequence(java.lang.String text, EvaluationEnvironment ee, boolean forceStringValues, java.lang.String fileName)
          Evaluates text as a list values.
static java.util.List evalAsSequence(java.lang.String text, java.lang.String fileName)
          Same as evalAsList(text, null, false, fileName).
 EvaluationEnvironment getEvaluationEnvironment()
           
 java.lang.String getFileName()
           
 int getPosition()
           
 java.lang.String getText()
           
static java.lang.String getTypeName(java.lang.Object value)
           
static java.lang.String loadTdd(byte[] b, java.lang.String defaultEncoding)
          Loads a TDD file with utilizing #encoding:enc header.
static java.lang.String loadTdd(java.io.InputStream in, java.lang.String defaultEncoding)
          Loads a TDD file with utilizing #encoding:enc header.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SIMPLE_EVALUATION_ENVIRONMENT

public static final EvaluationEnvironment SIMPLE_EVALUATION_ENVIRONMENT
Evaluates function calls to itself.

Method Detail

eval

public static java.lang.Object eval(java.lang.String text,
                                    EvaluationEnvironment ee,
                                    boolean forceStringValues,
                                    java.lang.String fileName)
                             throws EvalException
Evaluates text as single TDD expression.

Parameters:
text - the text to interpret.
ee - the EvaluationEnvironment used to resolve function calls. If it is null then SIMPLE_EVALUATION_ENVIRONMENT will be used.
forceStringValues - specifies if expressions as true and 123 should be interpreted as strings, or as boolean and number respectively.
fileName - the path of the source file, or other description of the source. It is used for informative purposes only, as in error messages.
Returns:
the result of the evaluation. Possibly an empty Map, but never null.
Throws:
EvalException

eval

public static java.lang.Object eval(Fragment fragment,
                                    EvaluationEnvironment ee,
                                    boolean forceStringValues)
                             throws EvalException
Evaluates a Fragment as single TDD expression. The expression can be surrounded with superfluous white-space.

Throws:
EvalException
See Also:
eval(String, EvaluationEnvironment, boolean, String)

eval

public static java.lang.Object eval(java.lang.String text,
                                    java.lang.String fileName)
                             throws EvalException
Same as eval(text, null, false, fileName).

Throws:
EvalException
See Also:
eval(String, EvaluationEnvironment, boolean, String)

eval

public static java.lang.Object eval(java.lang.String text)
                             throws EvalException
Same as eval(text, null, false, null).

Throws:
EvalException
See Also:
eval(String, EvaluationEnvironment, boolean, String)

evalAsHash

public static java.util.Map evalAsHash(java.lang.String text,
                                       EvaluationEnvironment ee,
                                       boolean forceStringValues,
                                       java.lang.String fileName)
                                throws EvalException
Evaluates text as a list of key:value pairs.

Parameters:
text - the text to interpret.
ee - the EvaluationEnvironment used to resolve function calls. If it is null then SIMPLE_EVALUATION_ENVIRONMENT will be used.
forceStringValues - specifies if expressions as true and 123 should be interpreted as strings, or as boolean and number respectively.
fileName - the path of the source file, or other description of the source. It is used for informative purposes only, as in error messages.
Returns:
the result of the evaluation. Possibly an empty Map, but never null.
Throws:
EvalException

evalAsHash

public static java.util.Map evalAsHash(java.lang.String text)
                                throws EvalException
Same as evalAsHash(text, null, false, null).

Throws:
EvalException
See Also:
evalAsHash(String, EvaluationEnvironment, boolean, String)

evalAsHash

public static java.util.Map evalAsHash(java.lang.String text,
                                       java.lang.String fileName)
                                throws EvalException
Same as evalAsHash(text, null, false, fileName).

Throws:
EvalException
See Also:
evalAsHash(String, EvaluationEnvironment, boolean, String)

evalAsSequence

public static java.util.List evalAsSequence(java.lang.String text,
                                            EvaluationEnvironment ee,
                                            boolean forceStringValues,
                                            java.lang.String fileName)
                                     throws EvalException
Evaluates text as a list values.

Parameters:
text - the text to interpret.
ee - the EvaluationEnvironment used to resolve function calls. If it is null then SIMPLE_EVALUATION_ENVIRONMENT will be used.
forceStringValues - specifies if expressions as true and 123 should be interpreted as strings, or as boolean and number respectively.
fileName - the path of the source file, or other description of the source. It is used for informative purposes only, as in error messages.
Returns:
the result of the evaluation. Possibly an empty List, but never null.
Throws:
EvalException

evalAsSequence

public static java.util.List evalAsSequence(java.lang.String text)
                                     throws EvalException
Same as evalAsList(text, null, false, null).

Throws:
EvalException
See Also:
evalAsSequence(String, EvaluationEnvironment, boolean, String)

evalAsSequence

public static java.util.List evalAsSequence(java.lang.String text,
                                            java.lang.String fileName)
                                     throws EvalException
Same as evalAsList(text, null, false, fileName).

Throws:
EvalException
See Also:
evalAsSequence(String, EvaluationEnvironment, boolean, String)

loadTdd

public static java.lang.String loadTdd(java.io.InputStream in,
                                       java.lang.String defaultEncoding)
                                throws java.io.IOException
Loads a TDD file with utilizing #encoding:enc header. If the header is missing, the encoding given as parameter is used.

Parameters:
in - the stream that reads the content of the file.
Throws:
java.io.IOException

loadTdd

public static java.lang.String loadTdd(byte[] b,
                                       java.lang.String defaultEncoding)
                                throws java.io.IOException
Loads a TDD file with utilizing #encoding:enc header. If the header is missing, the encoding given as parameter is used.

Parameters:
b - the content of the file.
Throws:
java.io.IOException

dump

public static java.lang.String dump(java.lang.Object value)
Converts an object to a TDD-like representation (not necessary valid TDD).

Parameters:
value - the object to convert
Returns:
the TDD "source code".

getTypeName

public static java.lang.String getTypeName(java.lang.Object value)

getPosition

public int getPosition()

getText

public java.lang.String getText()

getFileName

public java.lang.String getFileName()

getEvaluationEnvironment

public EvaluationEnvironment getEvaluationEnvironment()