| java.lang.Object pnuts.lang.Pnuts
All known Subclasses: pnuts.compiler.CompiledScript, pnuts.ext.CachedScript,
Pnuts | public class Pnuts implements Executable,Serializable(Code) | | This class provides a set of static methods to parse/execute scripts.
This object also represents a parsed script.
This class is serializable. When a Pnuts object is serialized, the syntax
tree is written to the object stream, along with the attributes such as
line, column, and script source.
When the object is deserialized, the parsed script is restored using
the information read from the object stream. If the script had been
compiled, the script should be recompiled.
Serialized objects of this class will not be compatible with
future releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing.
|
Constructor Summary | |
protected | Pnuts() |
Method Summary | |
public Object | accept(Visitor visitor, Context context) | protected Object | accept(Context context) | public static ClassLoader | createClassLoader(Context context) | public static ClassLoader | createClassLoader(Context context, ClassLoader parent) | static int | enter(Context context) all public entry points must go through this to ensure the correct
behavior of evalDepth method.
Parameters: context - the context in which the execution is taken place. | public static Object | eval(String expr, Context context) | public static int | evalDepth(Context context) Get the depth of evaluation. | public static String | format(Object obj) Returns the string representation of an object. | public static Object | get(String str) | public static Object | get(String str, String pkg) Gets a global variable. | static String | getCompiledClassPrefix() | public static Properties | getDefaults() Gets the properties previously set by setDefaults() method. | static PnutsParser | getParser(Reader reader) | final public static URL | getResource(String s, Context context) Get the resource URL. | public Object | getScriptSource() | final public static boolean | isJava2() Checks if the runtime environment supports J2SE. | public static boolean | isVerbose() | public static Object | load(String name, Context context) | public static Object | load(URL url, Context context) Loads a script specifed as a URL. | public static Object | load(InputStream in, Context context) | public static Object | load(InputStream in, boolean interactive, Context context) Load a script from an InputStream in the specified Context.
Parameters: in - an InputStream from which the interpreter reads an input Parameters: interactive - - When "interactive" is true, the greeting message, theprompt, and the results of evaluations are displayed.
| public static Object | load(Reader reader, Context context) | public static Object | load(Reader reader, boolean interactive, Context context) | final public static Class | loadClass(String name, Context context) Loads the class by the following order.
- A class loader associated with Pnuts context.
- The class loader associated with the current Thread (J2SE).
- The class loader by which Pnuts classes are loaded.
Parameters: name - the class name to be loaded Parameters: context - the context in which the class is loaded the loaded class. | public static Object | loadFile(String file, Context context) | public static Pnuts | parse(InputStream in) | public static Pnuts | parse(Reader reader) | public static Pnuts | parse(Reader reader, ParseEnvironment env) | public static Pnuts | parse(Reader reader, Object scriptSource, Context context) | public static Pnuts | parse(Reader reader, Object scriptSource, Context context, ParseEnvironment env) | public static Pnuts | parse(String expr) | static void | recycleParser(PnutsParser parser) | public static void | require(String file, Context context) Loads a script "file" only if the script has not been read. | public static void | require(String file, Context context, boolean checkForUpdate) | public Object | run(Context context) | static Object | session(Reader r, Context context) | public static void | set(String str, Object val) | public static void | set(String str, Object val, String pkg) | public static void | setDefaults(Properties properties) Sets properties that affect the behavior of Pnuts interpreter/compiler. | public static void | setPrompt(String str) | public void | setScriptSource(Object src) Associates a script source with this parsed (compiled) expression. | public static void | setVerbose(boolean b) | public String | unparse() | public void | unparse(Writer writer) Obtain the script code from a parsed object and write it to the specified
Writer. |
pnuts_version | final public static String pnuts_version(Code) | | The version number
|
prompt | public static String prompt(Code) | | "prompt" string for the command shell
|
scriptSource | protected Object scriptSource(Code) | | The script source, from where the script came. It is usually a URL
object, but not limitted to. If this variable is not null, error message
would include the positional information such as the line number and the
file name.
|
serialVersionUID | final static long serialVersionUID(Code) | | |
accept | public Object accept(Visitor visitor, Context context)(Code) | | traverse the parsed tree with the specified Visitor and Context
Parameters: context - the Context the result since: Pnuts 1.0beta3 |
accept | protected Object accept(Context context)(Code) | | Executes the parsed script
Parameters: context - the context in which the script is executed the result |
createClassLoader | public static ClassLoader createClassLoader(Context context)(Code) | | Create a classloader that can compile scripted classes
with the current thread's context classloader as its parent classloader
Parameters: context - the context in which scripts are compiled the classloader |
createClassLoader | public static ClassLoader createClassLoader(Context context, ClassLoader parent)(Code) | | Create a classloader that can compile scripted classes
Parameters: context - the context in which scripts are compiled Parameters: parent - the parent classloader the classloader |
enter | static int enter(Context context)(Code) | | all public entry points must go through this to ensure the correct
behavior of evalDepth method.
Parameters: context - the context in which the execution is taken place. the last value of context.depth. |
eval | public static Object eval(String expr, Context context)(Code) | | Evaluates "str" in "context"
Parameters: expr - the expression to be evaluated Parameters: context - the context in which the expression is evaluated the result of the evaluation |
evalDepth | public static int evalDepth(Context context)(Code) | | Get the depth of evaluation.
This value increases when load(), loadFile(), or eval() is called.
Parameters: context - the context of the evaluation. |
format | public static String format(Object obj)(Code) | | Returns the string representation of an object. When the object is a
number, a character, a boolean, or a string, it can be reconstructed by
eval() function.
Parameters: obj - the object. the string representation of the object |
get | public static Object get(String str)(Code) | | Get the value of a global variable
Parameters: str - the name of the global variable the value of the global variable str |
get | public static Object get(String str, String pkg)(Code) | | Gets a global variable.
Parameters: str - the name of the variable Parameters: pkg - the package where the variable is defined the value of a variable "str" in the package "pkg" |
getCompiledClassPrefix | static String getCompiledClassPrefix()(Code) | | |
getDefaults | public static Properties getDefaults()(Code) | | Gets the properties previously set by setDefaults() method.
the default setting that affects the behavior of Pnutsinterpreter/compiler. |
getResource | final public static URL getResource(String s, Context context)(Code) | | Get the resource URL.
Parameters: s - the resource name Parameters: context - the context in which the resource is read |
getScriptSource | public Object getScriptSource()(Code) | | Gets the script source associated with this parsed (compiled) expression
the script source to be associated with. |
isJava2 | final public static boolean isJava2()(Code) | | Checks if the runtime environment supports J2SE.
true if the runtime environment supports J2SE |
isVerbose | public static boolean isVerbose()(Code) | | Check the current verbose mode
the current verbose mode |
load | public static Object load(String name, Context context) throws FileNotFoundException(Code) | | Loads a script "file" in "context"
Parameters: name - the name of the script to be loaded Parameters: context - the context in which the script is loaded. |
load | public static Object load(URL url, Context context)(Code) | | Loads a script specifed as a URL.
Parameters: url - the URL Parameters: context - the context in which the script is loaded. |
load | public static Object load(InputStream in, Context context)(Code) | | Loads a script from InputStream "in" in "context"
Parameters: in - the input stream from which the script can be read. Parameters: context - the context in which the script is loaded. |
load | public static Object load(InputStream in, boolean interactive, Context context)(Code) | | Load a script from an InputStream in the specified Context.
Parameters: in - an InputStream from which the interpreter reads an input Parameters: interactive - - When "interactive" is true, the greeting message, theprompt, and the results of evaluations are displayed. When anexception is thrown and not caught by any exception handler,it is caught at the top level of the interpreter, display anerror message, and resume the interactive session. If theexception is caught by a handler that is registered at the toplevel, the result of the handler becomes the return value ofthe last expression.
- When "interactive" is false, exceptions are caught at the top levelof the interpreter and exits this function. If the exception thrown iscaught by a handler that is registered at the top level, the result ofthe handler becomes the return value of this method.
Parameters: context - a Context in which the interpretation is taken place. the result of the last expression |
load | public static Object load(Reader reader, Context context)(Code) | | This method loads a script
Parameters: reader - the Reader from which the script is loaded Parameters: context - the context in which the script is loaded the result of the last expression |
load | public static Object load(Reader reader, boolean interactive, Context context)(Code) | | This method loads a script
Parameters: reader - the Reader from which the script is loaded Parameters: interactive - specifies if the execution is in interactive mode. Parameters: context - the context in which the script is loaded the result of the last expression |
loadClass | final public static Class loadClass(String name, Context context) throws ClassNotFoundException(Code) | | Loads the class by the following order.
- A class loader associated with Pnuts context.
- The class loader associated with the current Thread (J2SE).
- The class loader by which Pnuts classes are loaded.
Parameters: name - the class name to be loaded Parameters: context - the context in which the class is loaded the loaded class. Note that it is not initialized. |
loadFile | public static Object loadFile(String file, Context context) throws FileNotFoundException(Code) | | Loads a local script "file" in "context"
Parameters: file - the script file to be loaded. Parameters: context - the context in which the file is loaded. |
parse | public static Pnuts parse(Reader reader) throws ParseException, IOException(Code) | | parse a script from Reader and return a Pnuts object
the Pnuts object including a parsed syntax tree Parameters: reader - the Reader since: Pnuts 1.0beta3 |
parse | public static Pnuts parse(Reader reader, Object scriptSource, Context context) throws IOException(Code) | | parse a script from Reader and return a Pnuts object
the Pnuts object including a parsed syntax tree Parameters: reader - the Reader Parameters: scriptSource - the script source |
parse | public static Pnuts parse(Reader reader, Object scriptSource, Context context, ParseEnvironment env) throws IOException(Code) | | parse a script from Reader and return a Pnuts object
the Pnuts object including a parsed syntax tree Parameters: reader - the Reader Parameters: scriptSource - the script source Parameters: env - |
parse | public static Pnuts parse(String expr) throws ParseException(Code) | | Parses a script and return a Pnuts object
the Pnuts object including a parsed syntax tree Parameters: expr - the script |
recycleParser | static void recycleParser(PnutsParser parser)(Code) | | |
require | public static void require(String file, Context context) throws FileNotFoundException(Code) | | Loads a script "file" only if the script has not been read. It is
guaranteed that the script runs at most once in this context.
Parameters: file - the script file, which must be an intern'ed String. Parameters: context - the context in which the script is loaded |
run | public Object run(Context context)(Code) | | Executes a Pnuts object with the specified Context
Parameters: context - the Context the result |
set | public static void set(String str, Object val)(Code) | | set a value "val" to a global variable "str"
|
set | public static void set(String str, Object val, String pkg)(Code) | | Set a value "val" to a variable "str" in package "pkg"
Parameters: str - Parameters: val - Parameters: pkg - |
setDefaults | public static void setDefaults(Properties properties)(Code) | | Sets properties that affect the behavior of Pnuts interpreter/compiler.
This method should be called before the classes that read the default
settings, such as pnuts.lang.Configuration and pnuts.lang.PnutsImpl.
Once those classes are loaded, this method call has no effect.
Pnuts.setDefaults(properties);
Context c = new Context(); // this line should not precede setDefaults() call.
Parameters: properties - the properties that override the system properties. |
setPrompt | public static void setPrompt(String str)(Code) | | Sets a "prompt" string for the command shell
|
setScriptSource | public void setScriptSource(Object src)(Code) | | Associates a script source with this parsed (compiled) expression.
Parameters: src - the script source to be associated with. |
setVerbose | public static void setVerbose(boolean b)(Code) | | Sets the verbose mode
|
unparse | public String unparse()(Code) | | Obtain the script code from a parsed object
the script code |
unparse | public void unparse(Writer writer) throws IOException(Code) | | Obtain the script code from a parsed object and write it to the specified
Writer.
Parameters: writer - the Writer to which the script code is written |
|
|