Package fmpp.tdd

Class Interpreter


  • public class Interpreter
    extends java.lang.Object
    Evaluates TDD expressions.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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
      • 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
      • 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
      • 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()