|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object gnu.expr.Language
public abstract class Language
Contains various language-dependent methods. Also contains "global" state about the executation environment, such as the global Environment. There can be multiple Languages associated with different threads, representing mutiple top-levels. (However, this functionality is incomplete.)
Field Summary | |
---|---|
protected static ThreadLocation |
current
|
protected static int |
env_counter
|
protected Environment |
environ
The environment for language built-ins and predefined bindings. |
static int |
FUNCTION_NAMESPACE
|
static java.lang.String |
NAMESPACE_PREFIX
Used when defining a namespace alias (prefix), in the XML sense. |
static int |
NAMESPACE_PREFIX_NAMESPACE
|
static int |
PARSE_IMMEDIATE
Flag to tell parse that expression will be evaluated immediately. |
static int |
PARSE_ONE_LINE
Flag to tell parse to only read a single line if possible. |
protected Environment |
userEnv
If non-null, the user environment. |
static int |
VALUE_NAMESPACE
|
Constructor Summary | |
---|---|
protected |
Language()
|
Method Summary | |
---|---|
Type |
asType(java.lang.Object spec)
"Coerce" a language-specific "type specifier" object to a Type. |
java.lang.Object |
booleanObject(boolean b)
|
java.lang.Object |
coerceFromObject(java.lang.Class clas,
java.lang.Object obj)
|
java.lang.Object |
coerceToObject(java.lang.Class clas,
java.lang.Object obj)
|
java.lang.Object |
coerceToObject(int val)
|
Declaration |
declFromField(ModuleExp mod,
java.lang.Object fvalue,
Field fld)
|
protected void |
defAliasStFld(java.lang.String name,
java.lang.String cname,
java.lang.String fname)
Declare in the current Environment a variable aliased to a static field. |
void |
define(java.lang.String sym,
java.lang.Object p)
Enter a value into the current environment. |
void |
defineFunction(Named proc)
Enter a named function into the current environment. |
void |
defineFunction(java.lang.String name,
java.lang.Object proc)
Enter a function into the current environment. |
protected void |
defProcStFld(java.lang.String name,
java.lang.String cname)
Declare in the current Environment a procedure bound to a static field. |
protected void |
defProcStFld(java.lang.String name,
java.lang.String cname,
java.lang.String fname)
Declare in the current Environment a procedure bound to a static field. |
void |
emitCoerceToBoolean(CodeAttr code)
Generate code to test if an object is considered true. |
void |
emitPushBoolean(boolean value,
CodeAttr code)
|
java.lang.Object |
eval(InPort port)
Evaluate expression(s) read from an InPort. |
void |
eval(InPort port,
CallContext ctx)
|
java.lang.Object |
eval(java.io.Reader in)
Evaluate expression(s) read from a Reader. |
void |
eval(java.io.Reader in,
Consumer out)
Read expressions from a Reader and write the result to a Consumer. |
void |
eval(java.io.Reader in,
java.io.Writer out)
Read expressions from a Reader and write the result to a Writer. |
java.lang.Object |
eval(java.lang.String string)
Return the result of evaluating a string as a source expression. |
void |
eval(java.lang.String string,
Consumer out)
Evaluate a string and write the result value(s) to a Consumer. |
void |
eval(java.lang.String string,
PrintConsumer out)
Evaluate a string and write the result value(s) to a PrintConsumer. |
void |
eval(java.lang.String string,
java.io.Writer out)
Evaluate a string and write the result value(s) on a Writer. |
static Language |
getDefaultLanguage()
|
Environment |
getEnvironment()
Get current user environment. |
java.lang.Object |
getEnvPropertyFor(Declaration decl)
|
java.lang.Object |
getEnvPropertyFor(java.lang.reflect.Field fld,
java.lang.Object value)
|
AbstractFormat |
getFormat(boolean readable)
|
static Language |
getInstance(java.lang.String name)
Look for a language with the given name or extension. |
static Language |
getInstance(java.lang.String langName,
java.lang.Class langClass)
|
static Language |
getInstanceFromFilenameExtension(java.lang.String filename)
|
Environment |
getLangEnvironment()
|
static java.lang.String[][] |
getLanguages()
Get a list of all available languages |
abstract Lexer |
getLexer(InPort inp,
SourceMessages messages)
|
java.lang.String |
getName()
|
int |
getNamespaceOf(Declaration decl)
Return the namespace (e.g value or function) of a Declaration. |
Environment |
getNewEnvironment()
|
Consumer |
getOutputConsumer(java.io.Writer out)
|
Procedure |
getPrompter()
|
Symbol |
getSymbol(java.lang.String name)
|
Type |
getTypeFor(java.lang.Class clas)
|
Type |
getTypeFor(Expression exp)
|
Type |
getTypeFor(java.lang.String name)
|
boolean |
hasSeparateFunctionNamespace()
True if functions are in a separate anme space from variable. |
boolean |
isTrue(java.lang.Object value)
Test if a value is considered "true" in this language. |
void |
loadClass(java.lang.String name)
|
java.lang.Object |
lookup(java.lang.String name)
|
NamedLocation |
lookupBuiltin(Symbol name,
java.lang.Object property,
int hash)
|
java.lang.Object |
noValue()
The value to return for a "void" result. |
Compilation |
parse(InPort port,
SourceMessages messages,
int options)
Parse one or more expressions. |
abstract Compilation |
parse(Lexer lexer,
int options)
|
void |
print(java.lang.Object obj,
OutPort out)
|
void |
print(java.lang.Object value,
OutPort out,
boolean readable)
|
static void |
registerLanguage(java.lang.String[] langMapping)
Add a language to the list. |
void |
runAsApplication(java.lang.String[] args)
|
static void |
setDefaultLanguage(Language language)
|
static void |
setDefaults(Language lang)
|
static Type |
string2Type(java.lang.String name)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final ThreadLocation current
protected Environment environ
protected Environment userEnv
public static final int PARSE_IMMEDIATE
public static final int PARSE_ONE_LINE
public static final java.lang.String NAMESPACE_PREFIX
public static final int VALUE_NAMESPACE
public static final int FUNCTION_NAMESPACE
public static final int NAMESPACE_PREFIX_NAMESPACE
protected static int env_counter
Constructor Detail |
---|
protected Language()
Method Detail |
---|
public static Language getDefaultLanguage()
public static void setDefaultLanguage(Language language)
public static java.lang.String[][] getLanguages()
public static void registerLanguage(java.lang.String[] langMapping)
langMapping
- is a language definition, the first index
is the language name, subsequent indexes are file types that
might cause the language to be used and the final index is the
name of the class that implements the language.public static Language getInstanceFromFilenameExtension(java.lang.String filename)
public static Language getInstance(java.lang.String name)
public static Language getInstance(java.lang.String langName, java.lang.Class langClass)
public boolean isTrue(java.lang.Object value)
public java.lang.Object booleanObject(boolean b)
public java.lang.Object noValue()
public boolean hasSeparateFunctionNamespace()
public final Environment getEnvironment()
public final Environment getNewEnvironment()
public Environment getLangEnvironment()
public NamedLocation lookupBuiltin(Symbol name, java.lang.Object property, int hash)
public void define(java.lang.String sym, java.lang.Object p)
protected void defAliasStFld(java.lang.String name, java.lang.String cname, java.lang.String fname)
protected void defProcStFld(java.lang.String name, java.lang.String cname, java.lang.String fname)
name
- the procedure's source-level name.cname
- the name of the class containing the field.fname
- the name of the field, which should be a static
final field whose type extends gnu.mapping.Procedure.protected void defProcStFld(java.lang.String name, java.lang.String cname)
name
- the procedure's source-level name.cname
- the name of the class containing the field.
The name of the field is the mangling of name
.public final void defineFunction(Named proc)
public void defineFunction(java.lang.String name, java.lang.Object proc)
public java.lang.Object getEnvPropertyFor(java.lang.reflect.Field fld, java.lang.Object value)
public java.lang.Object getEnvPropertyFor(Declaration decl)
public void loadClass(java.lang.String name) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
public Symbol getSymbol(java.lang.String name)
public java.lang.Object lookup(java.lang.String name)
public void print(java.lang.Object obj, OutPort out)
public void print(java.lang.Object value, OutPort out, boolean readable)
public AbstractFormat getFormat(boolean readable)
public Consumer getOutputConsumer(java.io.Writer out)
public java.lang.String getName()
public abstract Lexer getLexer(InPort inp, SourceMessages messages)
public final Compilation parse(InPort port, SourceMessages messages, int options) throws java.io.IOException, SyntaxException
port
- the InPort to read the expressions from.messages
- where to send error messages and warningsoptions
- various flags, includding PARSE_IMMEDIATE
and PARSE_ONE_LINE
java.io.IOException
SyntaxException
public abstract Compilation parse(Lexer lexer, int options) throws java.io.IOException, SyntaxException
java.io.IOException
SyntaxException
public Type getTypeFor(java.lang.Class clas)
public static Type string2Type(java.lang.String name)
public Type getTypeFor(java.lang.String name)
public Type asType(java.lang.Object spec)
public Type getTypeFor(Expression exp)
public Declaration declFromField(ModuleExp mod, java.lang.Object fvalue, Field fld)
public int getNamespaceOf(Declaration decl)
public void emitPushBoolean(boolean value, CodeAttr code)
public void emitCoerceToBoolean(CodeAttr code)
public java.lang.Object coerceFromObject(java.lang.Class clas, java.lang.Object obj)
public java.lang.Object coerceToObject(java.lang.Class clas, java.lang.Object obj)
public java.lang.Object coerceToObject(int val)
public static void setDefaults(Language lang)
public Procedure getPrompter()
public final java.lang.Object eval(java.lang.String string) throws java.lang.Throwable
java.lang.Throwable
public final java.lang.Object eval(java.io.Reader in) throws java.lang.Throwable
java.lang.Throwable
public final java.lang.Object eval(InPort port) throws java.lang.Throwable
java.lang.Throwable
public final void eval(java.lang.String string, java.io.Writer out) throws java.lang.Throwable
java.lang.Throwable
public final void eval(java.lang.String string, PrintConsumer out) throws java.lang.Throwable
java.lang.Throwable
public final void eval(java.lang.String string, Consumer out) throws java.lang.Throwable
java.lang.Throwable
public final void eval(java.io.Reader in, java.io.Writer out) throws java.lang.Throwable
java.lang.Throwable
public void eval(java.io.Reader in, Consumer out) throws java.lang.Throwable
java.lang.Throwable
public void eval(InPort port, CallContext ctx) throws java.lang.Throwable
java.lang.Throwable
public void runAsApplication(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |