public class Pnuts extends java.lang.Object implements Executable, java.io.Serializable
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.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
pnuts_version
The version number
|
static java.lang.String |
prompt
"prompt" string for the command shell
|
protected java.lang.Object |
scriptSource
The script source, from where the script came.
|
protected SimpleNode |
startNodes
Parsed scripts
|
Modifier | Constructor and Description |
---|---|
protected |
Pnuts() |
Modifier and Type | Method and Description |
---|---|
protected java.lang.Object |
accept(Context context)
Executes the parsed script
|
java.lang.Object |
accept(Visitor visitor,
Context context)
traverse the parsed tree with the specified Visitor and Context
|
static java.lang.ClassLoader |
createClassLoader(Context context)
Create a classloader that can compile scripted classes
with the current thread's context classloader as its parent classloader
|
static java.lang.ClassLoader |
createClassLoader(Context context,
java.lang.ClassLoader parent)
Create a classloader that can compile scripted classes
|
static java.lang.Object |
eval(java.lang.String expr,
Context context)
Evaluates "str" in "context"
|
static int |
evalDepth(Context context)
Get the depth of evaluation.
|
static java.lang.String |
format(java.lang.Object obj)
Returns the string representation of an object.
|
static java.lang.Object |
get(java.lang.String str)
Deprecated.
replaced by Context.getCurrentPackage().get(str.intern())
|
static java.lang.Object |
get(java.lang.String str,
java.lang.String pkg)
Deprecated.
replaced by Package.getPackage(pkg, null).get(str)
|
static java.util.Properties |
getDefaults()
Gets the properties previously set by setDefaults() method.
|
static java.net.URL |
getResource(java.lang.String s,
Context context)
Get the resource URL.
|
java.lang.Object |
getScriptSource()
Gets the script source associated with this parsed (compiled) expression
|
static boolean |
isJava2()
Checks if the runtime environment supports J2SE.
|
static boolean |
isVerbose()
Deprecated.
replaced by Context.isVerbose()
|
static java.lang.Object |
load(java.io.InputStream in,
boolean interactive,
Context context)
Load a script from an InputStream in the specified Context.
|
static java.lang.Object |
load(java.io.InputStream in,
Context context)
Loads a script from InputStream "in" in "context"
|
static java.lang.Object |
load(java.io.Reader reader,
boolean interactive,
Context context)
This method loads a script
|
static java.lang.Object |
load(java.io.Reader reader,
Context context)
This method loads a script
|
static java.lang.Object |
load(java.lang.String name,
Context context)
Loads a script "file" in "context"
|
static java.lang.Object |
load(java.net.URL url,
Context context)
Loads a script specifed as a URL.
|
static java.lang.Class |
loadClass(java.lang.String name,
Context context)
Loads the class by the following order.
|
static java.lang.Object |
loadFile(java.lang.String file,
Context context)
Loads a local script "file" in "context"
|
static Pnuts |
parse(java.io.InputStream in)
Deprecated.
replaced by parse(Reader)
|
static Pnuts |
parse(java.io.Reader reader)
parse a script from Reader and return a Pnuts object
|
static Pnuts |
parse(java.io.Reader reader,
java.lang.Object scriptSource,
Context context)
parse a script from Reader and return a Pnuts object
|
static Pnuts |
parse(java.io.Reader reader,
java.lang.Object scriptSource,
Context context,
ParseEnvironment env)
parse a script from Reader and return a Pnuts object
|
static Pnuts |
parse(java.io.Reader reader,
ParseEnvironment env)
parse a script from Reader and return a Pnuts object
|
static Pnuts |
parse(java.lang.String expr)
Parses a script and return a Pnuts object
|
static void |
require(java.lang.String file,
Context context)
Loads a script "file" only if the script has not been read.
|
static void |
require(java.lang.String file,
Context context,
boolean checkForUpdate) |
java.lang.Object |
run(Context context)
Executes a Pnuts object with the specified Context
|
static void |
set(java.lang.String str,
java.lang.Object val)
Deprecated.
replaced by context.getCurrentPackage().set(str.intern(),
val)
|
static void |
set(java.lang.String str,
java.lang.Object val,
java.lang.String pkg)
Deprecated.
replaced by Package.getPackage(pkg, null).set(str, val)
|
static void |
setDefaults(java.util.Properties properties)
Sets properties that affect the behavior of Pnuts interpreter/compiler.
|
static void |
setPrompt(java.lang.String str)
Sets a "prompt" string for the command shell
|
void |
setScriptSource(java.lang.Object src)
Associates a script source with this parsed (compiled) expression.
|
static void |
setVerbose(boolean b)
Deprecated.
replaced by Context.setVerbose()
|
java.lang.String |
unparse()
Obtain the script code from a parsed object
|
void |
unparse(java.io.Writer writer)
Obtain the script code from a parsed object and write it to the specified
Writer.
|
public static final java.lang.String pnuts_version
public static java.lang.String prompt
protected SimpleNode startNodes
protected java.lang.Object scriptSource
public static final boolean isJava2()
public static void setDefaults(java.util.Properties properties)
Pnuts.setDefaults(properties); Context c = new Context(); // this line should not precede setDefaults() call.
properties
- the properties that override the system properties.public static java.util.Properties getDefaults()
public static final java.lang.Class loadClass(java.lang.String name, Context context) throws java.lang.ClassNotFoundException
name
- the class name to be loadedcontext
- the context in which the class is loadedjava.lang.ClassNotFoundException
public static final java.net.URL getResource(java.lang.String s, Context context)
s
- the resource namecontext
- the context in which the resource is readpublic static void setPrompt(java.lang.String str)
public static void setVerbose(boolean b)
public static boolean isVerbose()
public static java.lang.String format(java.lang.Object obj)
obj
- the object.public static java.lang.Object get(java.lang.String str)
str
- the name of the global variablepublic static java.lang.Object get(java.lang.String str, java.lang.String pkg)
str
- the name of the variablepkg
- the package where the variable is definedpublic static void set(java.lang.String str, java.lang.Object val)
public static void set(java.lang.String str, java.lang.Object val, java.lang.String pkg)
str
- val
- pkg
- public static java.lang.Object eval(java.lang.String expr, Context context)
expr
- the expression to be evaluatedcontext
- the context in which the expression is evaluatedpublic static java.lang.Object loadFile(java.lang.String file, Context context) throws java.io.FileNotFoundException
file
- the script file to be loaded.context
- the context in which the file is loaded.java.io.FileNotFoundException
public static java.lang.Object load(java.lang.String name, Context context) throws java.io.FileNotFoundException
name
- the name of the script to be loadedcontext
- the context in which the script is loaded.java.io.FileNotFoundException
public static java.lang.Object load(java.net.URL url, Context context)
url
- the URLcontext
- the context in which the script is loaded.public static java.lang.Object load(java.io.InputStream in, Context context)
in
- the input stream from which the script can be read.context
- the context in which the script is loaded.public static java.lang.Object load(java.io.InputStream in, boolean interactive, Context context)
in
- an InputStream from which the interpreter reads an inputinteractive
- context
- a Context in which the interpretation is taken place.public static java.lang.Object load(java.io.Reader reader, Context context)
reader
- the Reader from which the script is loadedcontext
- the context in which the script is loadedpublic static int evalDepth(Context context)
context
- the context of the evaluation.public static java.lang.Object load(java.io.Reader reader, boolean interactive, Context context)
reader
- the Reader from which the script is loadedinteractive
- specifies if the execution is in interactive mode.context
- the context in which the script is loadedpublic static Pnuts parse(java.io.InputStream in) throws ParseException
in
- the InputStreamParseException
public static Pnuts parse(java.io.Reader reader) throws ParseException
reader
- the ReaderParseException
public static Pnuts parse(java.io.Reader reader, ParseEnvironment env) throws ParseException
ParseException
public static Pnuts parse(java.io.Reader reader, java.lang.Object scriptSource, Context context)
reader
- the ReaderscriptSource
- the script sourcepublic static Pnuts parse(java.io.Reader reader, java.lang.Object scriptSource, Context context, ParseEnvironment env)
reader
- the ReaderscriptSource
- the script sourceenv
- public static Pnuts parse(java.lang.String expr) throws ParseException
expr
- the scriptParseException
public static void require(java.lang.String file, Context context) throws java.io.FileNotFoundException
file
- the script file, which must be an intern'ed String.context
- the context in which the script is loadedjava.io.FileNotFoundException
public static void require(java.lang.String file, Context context, boolean checkForUpdate) throws java.io.FileNotFoundException
java.io.FileNotFoundException
public static java.lang.ClassLoader createClassLoader(Context context)
context
- the context in which scripts are compiledpublic static java.lang.ClassLoader createClassLoader(Context context, java.lang.ClassLoader parent)
context
- the context in which scripts are compiledparent
- the parent classloaderpublic java.lang.Object run(Context context)
run
in interface Executable
context
- the Contextpublic void setScriptSource(java.lang.Object src)
src
- the script source to be associated with.public java.lang.Object getScriptSource()
public java.lang.Object accept(Visitor visitor, Context context)
context
- the Contextpublic java.lang.String unparse()
public void unparse(java.io.Writer writer) throws java.io.IOException
writer
- the Writer to which the script code is writtenjava.io.IOException
protected java.lang.Object accept(Context context)
context
- the context in which the script is executed