| java.lang.Object gnu.expr.Language
All known Subclasses: gnu.xquery.lang.XQuery, gnu.kawa.lispexpr.LispLanguage,
Language | abstract public class Language (Code) | | 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.)
|
Constructor Summary | |
protected | Language() |
Method Summary | |
final public Type | asType(Object spec) "Coerce" a language-specific "type specifier" object to a Type. | public Object | booleanObject(boolean b) | public Object | coerceFromObject(Class clas, Object obj) | public Object | coerceToObject(Class clas, Object obj) | public Object | coerceToObject(int val) | public Declaration | declFromField(ModuleExp mod, Object fvalue, Field fld) | protected void | defAliasStFld(String name, String cname, String fname) Declare in the current Environment a variable aliased to a static field. | protected void | defProcStFld(String name, String cname, String fname) Declare in the current Environment a procedure bound to a static field. | protected void | defProcStFld(String name, String cname) Declare in the current Environment a procedure bound to a static field. | public void | define(String sym, Object p) Enter a value into the current environment. | final public void | defineFunction(Named proc) Enter a named function into the current environment. | public void | defineFunction(String name, Object proc) Enter a function into the current environment. | public static Language | detect(InputStream in) Detect the programming language of a file based on its first line. | public static Language | detect(InPort port) Detect the programming language of a file based on its first line. | public static Language | detect(String line) Detect the programming language of a file based on its first line. | public void | emitCoerceToBoolean(CodeAttr code) Generate code to test if an object is considered true.
Assume the object has been pushed on the JVM stack.
Generate code to push true or false as appropriate. | public void | emitPushBoolean(boolean value, CodeAttr code) | final public Object | eval(String string) Return the result of evaluating a string as a source expression. | final public Object | eval(Reader in) Evaluate expression(s) read from a Reader. | final public Object | eval(InPort port) Evaluate expression(s) read from an InPort. | final public void | eval(String string, Writer out) Evaluate a string and write the result value(s) on a Writer. | final public void | eval(String string, PrintConsumer out) Evaluate a string and write the result value(s) to a PrintConsumer.
This is to disambiguate calls using OutPort or XMLPrinter,
which are both Writer and Consumer. | final public void | eval(String string, Consumer out) Evaluate a string and write the result value(s) to a Consumer. | final public void | eval(Reader in, Writer out) Read expressions from a Reader and write the result to a Writer. | public void | eval(Reader in, Consumer out) Read expressions from a Reader and write the result to a Consumer. | public void | eval(InPort port, CallContext ctx) | public String | formatType(Type type) | public Compilation | getCompilation(Lexer lexer, SourceMessages messages) | public static Language | getDefaultLanguage() | public Object | getEnvPropertyFor(java.lang.reflect.Field fld, Object value) | public Object | getEnvPropertyFor(Declaration decl) | final public Environment | getEnvironment() Get current user environment. | public AbstractFormat | getFormat(boolean readable) | public static Language | getInstance(String name) Look for a language with the given name or extension.
If name is null, look for the first language available. | public static Language | getInstance(String langName, Class langClass) | public static Language | getInstanceFromFilenameExtension(String filename) | public Environment | getLangEnvironment() | final public Type | getLangTypeFor(Type type) | public static String[][] | getLanguages() | abstract public Lexer | getLexer(InPort inp, SourceMessages messages) | public String | getName() | public int | getNamespaceOf(Declaration decl) Return the namespace (e.g value or function) of a Declaration. | final public Environment | getNewEnvironment() | public Consumer | getOutputConsumer(Writer out) | public Procedure | getPrompter() | public Symbol | getSymbol(String name) | public Type | getTypeFor(Class clas) | public Type | getTypeFor(String name) | final public Type | getTypeFor(Object spec, boolean lenient) | final public Type | getTypeFor(Expression exp) | public Type | getTypeFor(Expression exp, boolean lenient) | public boolean | hasNamespace(Declaration decl, int namespace) True if a Declaration is in the specified namespace.
Parameters: namespace - normally a bitmask as returned by getNamespaceOf. | public boolean | hasSeparateFunctionNamespace() True if functions are in a separate anme space from variable.
Is true for e.g. | public boolean | isTrue(Object value) Test if a value is considered "true" in this language. | public void | loadClass(String name) | public Object | lookup(String name) | public NamedLocation | lookupBuiltin(Symbol name, Object property, int hash) | public Object | noValue() The value to return for a "void" result. | final public Compilation | parse(InPort port, gnu.text.SourceMessages messages, int options) Parse one or more expressions. | final public Compilation | parse(InPort port, gnu.text.SourceMessages messages, ModuleInfo info) | final public Compilation | parse(Lexer lexer, int options, ModuleInfo info) | abstract public boolean | parse(Compilation comp, int options) | public static void | registerLanguage(String[] langMapping) Add a language to the list. | public void | resolve(Compilation comp) Perform any need post-processing after we've read all the modules
to be compiled.
Using a separate pass allows compiling mutually recursive modules. | public void | runAsApplication(String[] args) | public static void | setDefaultLanguage(Language language) | public static synchronized void | setDefaults(Language lang) | public static Type | string2Type(String name) |
FUNCTION_NAMESPACE | final public static int FUNCTION_NAMESPACE(Code) | | |
NAMESPACE_PREFIX_NAMESPACE | final public static int NAMESPACE_PREFIX_NAMESPACE(Code) | | |
PARSE_IMMEDIATE | final public static int PARSE_IMMEDIATE(Code) | | Flag to tell parse that expression will be evaluated immediately.
I.e. we're not creating class files for future execution.
|
PARSE_ONE_LINE | final public static int PARSE_ONE_LINE(Code) | | Flag to tell parse to only read a single line if possible.
Multiple lines may be read if syntactically required.
|
PARSE_PROLOG | final public static int PARSE_PROLOG(Code) | | Flag to tell parser to continue until we have the module name.
The parser is allowed to continue further, but must stop before
any module import.
|
VALUE_NAMESPACE | final public static int VALUE_NAMESPACE(Code) | | |
envCounter | static int envCounter(Code) | | |
env_counter | protected static int env_counter(Code) | | |
environ | protected Environment environ(Code) | | The environment for language built-ins and predefined bindings.
|
languages | static String[][] languages(Code) | | List of known languages and their Language classes.
Each element is one or more language names, or filename extensions,
followed by the name of the Language sub-class.
The table is searched from the beginning.
|
requirePedantic | public static boolean requirePedantic(Code) | | |
userEnv | protected Environment userEnv(Code) | | If non-null, the user environment.
This allows "bunding" an Environment with a Language. This is partly to
match existing documentation, and partly for convenience from Java code.
Normally, userEnv is null, in which case the user environment is
extracted from the current thread.
|
Language | protected Language()(Code) | | |
asType | final public Type asType(Object spec)(Code) | | "Coerce" a language-specific "type specifier" object to a Type.
|
defAliasStFld | protected void defAliasStFld(String name, String cname, String fname)(Code) | | Declare in the current Environment a variable aliased to a static field.
|
defProcStFld | protected void defProcStFld(String name, String cname, String fname)(Code) | | Declare in the current Environment a procedure bound to a static field.
Parameters: name - the procedure's source-level name. Parameters: cname - the name of the class containing the field. Parameters: fname - the name of the field, which should be a staticfinal field whose type extends gnu.mapping.Procedure. |
defProcStFld | protected void defProcStFld(String name, String cname)(Code) | | Declare in the current Environment a procedure bound to a static field.
Parameters: name - the procedure's source-level name. Parameters: cname - the name of the class containing the field.The name of the field is the mangling of name . |
define | public void define(String sym, Object p)(Code) | | Enter a value into the current environment.
|
defineFunction | final public void defineFunction(Named proc)(Code) | | Enter a named function into the current environment.
|
defineFunction | public void defineFunction(String name, Object proc)(Code) | | Enter a function into the current environment.
Same as define(name,proc) for Scheme, but not for (say) Common Lisp.
|
detect | public static Language detect(InputStream in) throws IOException(Code) | | Detect the programming language of a file based on its first line.
a suitable Language or null if we didn't recognize one. |
detect | public static Language detect(InPort port) throws IOException(Code) | | Detect the programming language of a file based on its first line.
a suitable Language or null if we didn't recognize one. |
detect | public static Language detect(String line)(Code) | | Detect the programming language of a file based on its first line.
Parameters: line - the first input line a suitable Language or null if we didn't recognize one. |
emitCoerceToBoolean | public void emitCoerceToBoolean(CodeAttr code)(Code) | | Generate code to test if an object is considered true.
Assume the object has been pushed on the JVM stack.
Generate code to push true or false as appropriate.
|
emitPushBoolean | public void emitPushBoolean(boolean value, CodeAttr code)(Code) | | |
eval | final public Object eval(Reader in) throws Throwable(Code) | | Evaluate expression(s) read from a Reader.
This just calls eval(InPort).
|
eval | final public void eval(String string, Writer out) throws Throwable(Code) | | Evaluate a string and write the result value(s) on a Writer.
|
eval | final public void eval(String string, PrintConsumer out) throws Throwable(Code) | | Evaluate a string and write the result value(s) to a PrintConsumer.
This is to disambiguate calls using OutPort or XMLPrinter,
which are both Writer and Consumer.
|
eval | final public void eval(Reader in, Writer out) throws Throwable(Code) | | Read expressions from a Reader and write the result to a Writer.
|
getEnvironment | final public Environment getEnvironment()(Code) | | Get current user environment.
|
getInstance | public static Language getInstance(String name)(Code) | | Look for a language with the given name or extension.
If name is null, look for the first language available.
|
getInstanceFromFilenameExtension | public static Language getInstanceFromFilenameExtension(String filename)(Code) | | |
getLanguages | public static String[][] getLanguages()(Code) | | Get a list of all available languages
|
getNamespaceOf | public int getNamespaceOf(Declaration decl)(Code) | | Return the namespace (e.g value or function) of a Declaration.
Return a bitmask of all the namespaces "covered" by the Declaration.
Note this isn't a namespace in the XML sense; if a Declaration has
a specific namespace URI, then that is part of its symbol.
This namespace bitmap is a separate dimension, for the use of
languages that have separate namespaces for different kinds of
declarations, such as variables and functions.
|
hasNamespace | public boolean hasNamespace(Declaration decl, int namespace)(Code) | | True if a Declaration is in the specified namespace.
Parameters: namespace - normally a bitmask as returned by getNamespaceOf. |
hasSeparateFunctionNamespace | public boolean hasSeparateFunctionNamespace()(Code) | | True if functions are in a separate anme space from variable.
Is true for e.g. Common Lisp, Emacs Lisp; false for Scheme.
|
isTrue | public boolean isTrue(Object value)(Code) | | Test if a value is considered "true" in this language.
|
noValue | public Object noValue()(Code) | | The value to return for a "void" result.
|
parse | final public Compilation parse(InPort port, gnu.text.SourceMessages messages, int options) throws java.io.IOException, gnu.text.SyntaxException(Code) | | Parse one or more expressions.
Parameters: port - the InPort to read the expressions from. Parameters: messages - where to send error messages and warnings Parameters: options - various flags, includding PARSE_IMMEDIATE and PARSE_ONE_LINE a new Compilation.May return null if PARSE_ONE_LINE on end-of-file. |
registerLanguage | public static void registerLanguage(String[] langMapping)(Code) | | Add a language to the list.
Parameters: langMapping - is a language definition, the first indexis the language name, subsequent indexes are file types thatmight cause the language to be used and the final index is thename of the class that implements the language. |
resolve | public void resolve(Compilation comp)(Code) | | Perform any need post-processing after we've read all the modules
to be compiled.
Using a separate pass allows compiling mutually recursive modules.
|
runAsApplication | public void runAsApplication(String[] args)(Code) | | |
setDefaultLanguage | public static void setDefaultLanguage(Language language)(Code) | | |
setDefaults | public static synchronized void setDefaults(Language lang)(Code) | | |
|
|