public abstract class Language
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static java.lang.InheritableThreadLocal<Language> |
current |
protected Environment |
environ
The environment for language built-ins and predefined bindings.
|
static int |
FUNCTION_NAMESPACE |
protected static Language |
global |
static int |
NAMESPACE_PREFIX_NAMESPACE |
static int |
PARSE_CURRENT_NAMES
Flag to tell parse to use current NameLookup.
|
static int |
PARSE_EMIT_MAIN |
static int |
PARSE_EXPLICIT
Compilation explicitly requested, not just because of an import.
|
static int |
PARSE_FOR_APPLET |
static int |
PARSE_FOR_EVAL |
static int |
PARSE_FOR_LINT |
static int |
PARSE_FOR_SERVLET |
static int |
PARSE_IMMEDIATE
Flag to tell parse that expression will be evaluated immediately.
|
static int |
PARSE_INTERACTIVE_MODULE |
static int |
PARSE_ONE_LINE
Flag to tell parse to only read a single line if possible.
|
static int |
PARSE_PROLOG
Flag to tell parser to continue until we have the module name.
|
static boolean |
requirePedantic |
protected Environment |
userEnv
If non-null, the user environment.
|
static int |
VALUE_NAMESPACE |
Modifier | Constructor and Description |
---|---|
protected |
Language() |
Modifier and Type | Method and Description |
---|---|
Type |
asType(java.lang.Object spec)
"Coerce" a language-specific "type specifier" object to a Type.
|
java.lang.Object |
booleanObject(boolean b) |
int |
booleanValue(java.lang.Object value)
Test if a value is considered "true" in this language.
|
java.lang.Object |
coerceFromObject(java.lang.Class clas,
java.lang.Object obj) |
java.lang.Object |
coerceToObject(java.lang.Class clas,
java.lang.Object obj) |
Declaration |
declFromField(ModuleExp mod,
java.lang.Object fvalue,
Field fld) |
Type |
decodeType(Type javaType,
java.lang.String annotType,
ParameterizedType parameterizedType) |
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.
|
protected void |
defProcStFld(Symbol sym,
java.lang.String cname,
java.lang.String fname) |
protected void |
defProcStFldAs(java.lang.String asName,
java.lang.String cname,
java.lang.String mname)
Declare by name in the current environment a procedure bound to a static field.
|
static Language |
detect(gnu.kawa.io.InPort port)
Detect the programming language of a file based on its first line.
|
static Language |
detect(java.io.InputStream in)
Detect the programming language of a file based on its first line.
|
static Language |
detect(java.lang.String line)
Detect the programming language of a file based on its first line.
|
java.lang.String |
encodeType(Type type)
Encode this type as a parseable string.
|
java.lang.Object |
eval(gnu.kawa.io.InPort port)
Evaluate expression(s) read from an InPort.
|
void |
eval(gnu.kawa.io.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.
|
java.lang.String |
formatType(Type type) |
Compilation |
getCompilation(Lexer lexer,
int options,
ModuleInfo info) |
Compilation |
getCompilation(SourceMessages messages,
NameLookup lexical) |
java.lang.String |
getCompilationClass() |
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) |
java.util.List<java.lang.String> |
getExtensions() |
gnu.kawa.format.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() |
Type |
getLangTypeFor(Type type) |
static java.lang.String[][] |
getLanguages()
Get a list of all available languages
|
abstract Lexer |
getLexer(gnu.kawa.io.InPort inp,
SourceMessages messages) |
java.lang.String |
getName() |
Type |
getNamedType(java.lang.String name)
Get the corresponding
Type for a given name. |
int |
getNamespaceOf(Declaration decl)
Return the namespace (e.g value or function) of a Declaration.
|
Environment |
getNewEnvironment() |
Consumer |
getOutputConsumer(java.io.Writer out) |
java.lang.String |
getPrimaryPrompt() |
java.lang.String |
getSecondaryPrompt() |
Symbol |
getSymbol(java.lang.String name) |
Type |
getTypeFor(java.lang.Class clas) |
Type |
getTypeFor(Expression exp) |
Type |
getTypeFor(Expression exp,
boolean lenient)
Interpreting exp as a type specifier, get the actual type.
|
Type |
getTypeFor(java.lang.Object spec,
boolean lenient)
Convert a "type value" to a Type.
|
Type |
getTypeFor(java.lang.String name) |
boolean |
hasNamespace(Declaration decl,
int namespace)
True if a Declaration is in the specified namespace.
|
boolean |
hasSeparateFunctionNamespace()
True if functions are in a separate name space from variable.
|
boolean |
isTrue(java.lang.Object value)
Test if a value is considered "true" in this language.
|
static boolean |
isValidJavaName(java.lang.String name) |
void |
loadClass(java.lang.String name) |
java.lang.Object |
lookup(java.lang.String name) |
NamedLocation |
lookupBuiltin(Symbol name,
java.lang.Object property,
int hash) |
static java.lang.String |
mangleName(java.lang.String name,
int kind)
Convert a string to a safe Java identifier.
|
java.lang.Object |
noValue()
The value to return for a "void" result.
|
boolean |
parse(Compilation tr) |
abstract boolean |
parse(Compilation comp,
int options) |
Compilation |
parse(gnu.kawa.io.InPort port,
SourceMessages messages,
int options)
Parse one or more expressions.
|
Compilation |
parse(gnu.kawa.io.InPort port,
SourceMessages messages,
int options,
ModuleInfo info) |
Compilation |
parse(Lexer lexer,
int options,
ModuleInfo info) |
static void |
registerLanguage(java.lang.String[] langMapping)
Add a language to the list.
|
void |
resolve(Compilation comp)
Perform any need post-processing after we've read all the modules
to be compiled.
|
static void |
restoreCurrent(Language saved) |
void |
runAsApplication(java.lang.String[] args) |
static void |
setCurrentLanguage(Language language) |
static void |
setDefaults(Language lang) |
static Language |
setSaveCurrent(Language language) |
static Type |
unionType(Type t1,
Type t2) |
protected static final java.lang.InheritableThreadLocal<Language> current
protected static Language global
protected Environment environ
protected Environment userEnv
public static final int PARSE_IMMEDIATE
public static final int PARSE_CURRENT_NAMES
public static final int PARSE_ONE_LINE
public static final int PARSE_PROLOG
public static final int PARSE_FOR_EVAL
public static final int PARSE_FOR_APPLET
public static final int PARSE_FOR_SERVLET
public static final int PARSE_EXPLICIT
public static final int PARSE_INTERACTIVE_MODULE
public static final int PARSE_EMIT_MAIN
public static final int PARSE_FOR_LINT
public static boolean requirePedantic
public static final int VALUE_NAMESPACE
public static final int FUNCTION_NAMESPACE
public static final int NAMESPACE_PREFIX_NAMESPACE
public static Language getDefaultLanguage()
public static void setCurrentLanguage(Language language)
public static void restoreCurrent(Language saved)
public static java.lang.String[][] getLanguages()
public static void registerLanguage(java.lang.String[] langMapping)
langMapping
- is a language definition, the first element
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 detect(java.io.InputStream in) throws java.io.IOException
java.io.IOException
public static Language detect(gnu.kawa.io.InPort port) throws java.io.IOException
java.io.IOException
public static Language detect(java.lang.String line)
line
- the first input linepublic 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 int booleanValue(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)
public Type getNamedType(java.lang.String name)
Type
for a given name.
This is currently used as a hook in the conversion of type designators to
types. LispLanguage
uses it to check for package
style type designators such as emacs:buffer
,
and CommonLisp uses it to check for a type designator "boolean",
so that is can return the appropriate boolean type.
This is a bit over-specialised, but it beats actually
overriding getTypeFor(String) in LispLanguage, CommonLisp just for these minor
changes... FIXME!name
- The name of a type to search for.Type
if a suitable one can be found,
otherwise null
.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(Symbol sym, java.lang.String cname, java.lang.String fname)
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
.protected void defProcStFldAs(java.lang.String asName, java.lang.String cname, java.lang.String mname)
asName
- The procedure's source-level name.cname
- The name of the class containing the field.mname
- The name of the (mangled) field in cname
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 gnu.kawa.format.AbstractFormat getFormat(boolean readable)
public Consumer getOutputConsumer(java.io.Writer out)
public java.lang.String getName()
public java.util.List<java.lang.String> getExtensions()
public static boolean isValidJavaName(java.lang.String name)
public static java.lang.String mangleName(java.lang.String name, int kind)
kind
- -1 - non-reversible;
0: reversible, except that '$' is not mapped;
1: reversiblepublic abstract Lexer getLexer(gnu.kawa.io.InPort inp, SourceMessages messages)
public java.lang.String getCompilationClass()
public final Compilation getCompilation(SourceMessages messages, NameLookup lexical)
public final Compilation getCompilation(Lexer lexer, int options, ModuleInfo info)
public final Compilation parse(gnu.kawa.io.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, including PARSE_IMMEDIATE
and PARSE_ONE_LINEjava.io.IOException
SyntaxException
public final Compilation parse(gnu.kawa.io.InPort port, SourceMessages messages, int options, ModuleInfo info) throws java.io.IOException, SyntaxException
java.io.IOException
SyntaxException
public final Compilation parse(Lexer lexer, int options, ModuleInfo info) throws java.io.IOException, SyntaxException
java.io.IOException
SyntaxException
public final boolean parse(Compilation tr) throws java.io.IOException, SyntaxException
java.io.IOException
SyntaxException
public abstract boolean parse(Compilation comp, int options) throws java.io.IOException, SyntaxException
java.io.IOException
SyntaxException
public void resolve(Compilation comp)
public Type getTypeFor(java.lang.Class clas)
public java.lang.String formatType(Type type)
public Type getTypeFor(java.lang.String name)
public Type getTypeFor(java.lang.Object spec, boolean lenient)
public java.lang.String encodeType(Type type)
decodeType(gnu.bytecode.Type, java.lang.String, gnu.bytecode.ParameterizedType)
,
or null if the type is "uninteresting" in the sense we can
infer it from the Java typing.public Type decodeType(Type javaType, java.lang.String annotType, ParameterizedType parameterizedType)
public final Type asType(java.lang.Object spec)
public final Type getTypeFor(Expression exp)
public Type getTypeFor(Expression exp, boolean lenient)
public Declaration declFromField(ModuleExp mod, java.lang.Object fvalue, Field fld)
public int getNamespaceOf(Declaration decl)
public boolean hasNamespace(Declaration decl, int namespace)
namespace
- normally a bitmask as returned by getNamespaceOf.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 static void setDefaults(Language lang)
public java.lang.String getPrimaryPrompt()
public java.lang.String getSecondaryPrompt()
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(gnu.kawa.io.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(gnu.kawa.io.InPort port, CallContext ctx) throws java.lang.Throwable
java.lang.Throwable
public void runAsApplication(java.lang.String[] args)