|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjfun.jaskell.Jaskell
public final class Jaskell
This is the facade class to parse and interpret a jaskell source code.
Throughout this jaskell function documentation,
For example: int->void is a Function that accepts one parameter
of int and returns void;
String->Object->int is a Function that accepts a String and then
an Object and returns an int.
Also, a "tuple" can also be considered as a "namespace" as it serves the same purpose.
Standard and optional Jaskell functions are organized
in a hierarchy as following:
To create a function that always return the same value regardless the parameter.
The expression used as the value is not evaluated until needed.
This function uses the parameter directly as return value.
To flip the position of the two parameters of a function.
"flip (-) 1 2" is equivalent to "2 - 1".
This function has 2 overloaded versions:
"define {a=1,b=2} (a+b)" evaluates to 3.
Jaskell is a statically scoped language, but the "import" function provides a limited support for dynamic scoping.
This member is optional.
see Java Bean class representing signature
The following items are valid in the "options" tuple:
If ommitted, or null, the ClassLoader used by the Jaskell object is used instead.
"classpath" can be a String, a File, a URL or a list of classpath.
When a string is specified for a classpath, "," or ";" can be used to separate
path elements.
A valid example is:
["lib/ant.jar, ../external_lib/xcercse.jar; /home/neptune/lib/neptune.jar", ["x.jar","build/y.jar"], ["z.jar"] ]
Optional parameter. Default value is the current directory.
"basedir" can be either a File or a String.
The following 4 policies are currently supported:
see Java Bean class representing signature
: Object callcc((Object->Object)->Object f)
callcc can be used to exit from a loop or nested function calls.
For example:
search l target = let pos = ref 0; next r = set(r, get r+1); callcc \return -> foreach(l, \i->if i==target then return(get pos) else next pos) endThe above "search" function searches a list/array to find the position of an element.
The callcc function is only a restricted continuation.
The continuation is only valid within the static scope of the callcc function.
Unlike continuation in Scheme, it cannot be saved in a refernece and
used outside of the static scope of the callcc function.
This means, this is an escape-only continuation mechanism.
This function has 2 overloaded versions:
Description:
see Java Bean class representing signature
The returned tuple can be used as if it were the class. For example:
import "java.lang.Integer".parseInt["10"]
This function has 2 overloaded versions:
This returns the tuple itself directly.
This Converts the object to a tuple.
For example:
java.lang.StringBuffer.new[].getLength[]However, for some functions that only expect Tuple as parameter, For example, the following code will fail because a non-tuple object is used where a tuple is expected:
"abc" `(jaskell.tuple.includes) "bcd"In this senario, 'asTuple' function can be used to incur the conversion explicitly.
The exception handler can be either a Function or a regular Expression.
When the handler is a function, the exception object is passed in to this function; otherwise, the expression is simply evaluated disregarding the exception object.
This is a sample usage of within-try-catch:
within $ try (some_expression) `(catch "java.lang.RuntimeException") (\e->jaskell.io.out.println(e.getMessage[]))
To split a string using a delimiter.
To "extend" tuple t2 with tuple t1.
"tuple1 `extends` tuple2" will create a new tuple whose members
come from tuple1 and tuple2.
When there's name conflict between two members from tuple1 and tuple2,
the one from tuple1 takes precedence.
"this" variable binds to the new tuple.
For example:
extended.fullname where tuple1 = {firstname="Tom",}; tuple2 = {firstname="Jack",lastname="Stone",fullname="${this.firstname} ${this.lastname}"}; extended = tuple1 `extends tuple2; endThe above expression should evaluate to "Tom Stone" because "this" is now bound to "extended", not "tuple1" any more.
'extends' does not cause any tuple member to be evaluated.
To create a tuple that includes members from both t1 and t2.
Different from 'extends', 'includes' doesn't change the "this" variable binding.
included.fullname where tuple1 = {firstname="Tom";}; tuple2 = {firstname="Jack";lastname="Stone";fullname="${this.firstname} ${this.lastname}"}; included = tuple1 `includes tuple2; endThe above expression will evaluate to "Jack Stone".
'includes' does not cause any tuple member to be evaluated.
Dynamically extend/override a tuple member.
"put {} "name" "Tom"" is equivalent to "{name="Tom"}"
'put' is more flexible than a tuple literal because any string or even non-string objects can be used as the member key.
'put' does not evaluate the expression that's used as the member value.
To get the member keys of a tuple.
The keys are put into an array.
The order of the keys are not defined.
To get the member keys of a tuple.
The keys are put into a list.
The order of the keys are not defined.
This function has 2 overloaded version:
"this" variable still binds to the original tuple, not the subtuple.
Therefore, the following expression still evaluates to "Tom Stone" even if
the subtuple does not contain the "firstname" and "lastname" member any more.
subtuple( {firstname="Tom", lastname="Stone";fullname="${this.firstname} ${this.lastname}"}, ["fullname"] ).fullname
"subtuple(t, ["a","b"})" is equivalent to "t.{a,b}".
subtuple function just provides more flexibility to handle non-string keys.
This function has 7 overloaded versions:
To evaluate and get the value of a member from a tuple.
null is returned if the key is not present in the tuple.
Equivalent to "str.charAt(ind)".
Equivalent to "list.get(ind)".
Equivalent to "map.get(key)".
To get the ind'th element in the list.
ArrayIndexOutOfBoundsException is thrown when ind<0 or ind>=list.size()
To call java.lang.reflect.Array.get(arr, ind)
when arr is an array.
ArrayIndexOutOfBoundsException is thrown when ind<0 or ind>=Array.getLength(arr)
To call map.get(key).
This function has 3 overloaded versions:
Equivalent to "map.containsKey(key)".
Equivalent to "map.get(key)!=null".
Equivalent to "t.getMember(key)!=null"
This function has 4 overloaded versions:
To get the length of the CharSequence.
To get the length of the array when the object is an array.
Equivalent to calling "sizeable.size()".
Equivalent to calling "col.size()".
To create a new tuple by removing one member.
Remember, this is functional remove, the original Tuple
is not changed.
This function has 3 overloaded versions:
To remove members identified by the keys stored in an array when the "arr" parameter is array.
To remove members identified by the keys stored in a list.
To remove members identified by the keys stored in a list.
To parse a string to an integer.
NumberFormatException if the string is not in a valid format.
To parse a string to a BigDecimal.
NumberFormatException if the string is not in a valid format.
To convert a BigDecimal to a BigInteger.
Fractional part is discarded if any.
To convert a BigInteger to a BigDecimal.
To convert an object to a string.
null is converted to "null", non-null object is converted using the toString() method.
This function has 10 overloaded version:
To call function f for |i| times.
The loop variable is passed to function f in each iteration.
If i>0, then the loop variable starts from 0 to (i-1).
If i<0, then the loop variable starts from 0 to (i+1).
To call function f for each character in the string.
In each iteration, the character is passed in to the function f.
To call function f for each element in the array when the "arr" object is an array.
In each iteration, the array element is passed in to the function f.
To call function f for each element in the list.
In each iteration, the list element is passed in to the function f.
To call function f for each element in the list.
In each iteration, the list element is passed in to the function f.
To call function f for each key-val pair in the tuple.
In each iteration, the key and the value expression of the member
are passed in to the function f.
i.e. "f(key, val)"
The tuple member is not evaluated before passed into the function.
It is up to the function to decide whether to evaluate this value.
The order of the key-value pair is not defined.
To call function f for each key-value pair in the immutable Dict object.
In each iteration, the key and the value are passed into the function f.
i.e. "f(key, value)"
The order of the key-value pair is not defined.
To call function f for each key-value pair in the Map object.
In each iteration, the key and the value are passed into the function f.
i.e. "f(key, value)"
To call function f for each element returned by the iterator.
After the foreach function, it.hasNext()==false
To call function f for each element returned by the Enumeration object.
After the foreach function, en.hasMoreElements()==false
"ref 1" will create a refernece whose initial value is 1.
"set r 2" will change the value that r references to 2.
To get the year of a date.
To get the month of a date. January is 0.
To get the day of month of a date. 1st day is 0.
To get the hour of day of a date.
To get the minute of hour of a date.
To get the second of minute of a date.
To get the millisecond of second of a date.
To get the day of week of a date. Sunday is 1 and Monday is 2.
To get any field of a date object.
The field values are defined in java.util.Calendar.
This function has 3 overloaded versions:
This returns the DateFormat object directly.
see Java Bean class representing signature
This function has 3 overloaded versions:
see Java Bean class representing signature
This function has 3 overloaded versions:
see Java Bean class representing signature
To create a new Date object by adding some amount to a certain field of the Date object.
This function has 2 overloaded versions:
see Java Bean class representing signature
If a property in the properties file is named as "a.b", the value is stored in the result tuple as "a.b", which means, the "b" is stored in subtuple named "a".
Functions in this tuple use array, java.util.List, jfun.util.List the same way. Therefore, "List" is used for any one of the three.
"auto expr1 expr2" will evaluate expr1 after expr2 even if expr2 throws an exception.
This is similar to the 'finally' function, except that the order of the two parameters are flipped.
This function is handy when 'expr2' is a long complex expression, where we can say:
auto expr1 $ ... //expr2
To create a tuple using keys and values stored in a list.
assoc ["name", "tom", "age", 10]is equivalent to
{name="tom", age=10}
To create a tuple using keys and values stored in two lists respectively.
assoc2 ["name", "age"] ["tom", 10] is equivalent to{name="tom",age=10}
Assert that two objects are equal. jfun.jaskell.AssertionFailedException is thrown otherwise.
Assert that two objects are not equal. jfun.jaskell.AssertionFailedException is thrown otherwise.
Assert that an object satisfies a predicate. jfun.jaskell.AssertionFailedException is thrown otherwise.
'default' function takes advantage of the dynamic scoping support
of Jaskell to provide a default-parameter support.
add args = default args {a=1,b=2,c=3} $ 1+2+3;The above "add" function adds up three numbers. These named parameters are passed into the function in a tuple and are given default values by the 'default' function.
Then, when calling:
add {a=10,b=0}The "c" is not provided in the argument tuple but instead is given the default value "3". Thus, the evaluation result is 13.
To throw an exception to report an error message.
To transform a list by applying a function to each element in the list.
The following assertion succeeds:
assert([2,4,6], map (2.*) [1,2,3])
To create a list with elements in the range of [from,to].
The following assertion succeeds:
assert([1,2,3], list 1 3)
To create a sub-list by filtering out elements that doesn't satisfy a predicate.
The following assertion succeeds:
assert([1,2], filter (3.>) [1,2,3])
To find the ordinal position of an element in a list. -1 is returned if the element cannot be found in the list.
The following assertion succeeds:
assert(1, find 2 [1,2,3])
To find the ordinal position of the first element in a list that satisfies the given predicate. -1 is returned if the element cannot be found in the list.
The following assertion succeeds:
assert(1, lookup (1.<) [1,2,3])
To reverse the order of elements in a list. The following assertion succeeds:
assert([3,2,1], reverse [1,2,3])
To append elements in a list in reverse order to another list. The following assertion succeeds:
assert([4,3,2,1], revAppend [4] [1,2,3])
To create a list by replicating an object for n times. The following assertion succeeds:
assert([1,1,1,1], replicate 4 1)
The following assertion succeeds:
assert(10, sum[1,2,3,4])
folds a list to a value by repeatedly applying a function to the elements.
Parameters:
folds a tuple/Map to a value by repeatedly applying a function to the key/value pairs.
Parameters:
folds a collection that's iterable to a value by repeatedly applying a function to the loop variables in each iteration.
Parameters:
The following assertion succeeds:
assert(6, plus3 1 2 3) where plus3 = curry 3 sum; end
The following assertion succeeds:
assert(3, add[1,2]) where add = uncurry 2 (+); end
The following assertion succeeds:
assert("x", const3 "a" "b" "c") where const3 = promote 3 "x"; end
To use the key-value pairs stored in a list to functionally update a tuple.
The following assertion succeeds:
asserts({zero=0;one=1;two=2}, puts {zero=0} ["one",1,"two",2])
To use the key-value pairs seperately stored in two lists to functionally update a tuple.
The following assertion succeeds:
asserts({zero=0;one=1;two=2}, puts2 {zero=0} ["one","two"] [1,2])
The following assertion succeeds:
assert("three", translate 3) where translate n = switch n .case 1 "one" .case 2 "two" .case 3 "three" .default "unknown" .end end
'switch' only tests equality for each case,
while 'when' parameterizes this test condition.
The following assertion succeeds:
assert("string", translate "a") where translate x = when (jaskell.java.instanceof) x .case (java.int) "int" .case (java.lang.String) "string" .default "unknown" .end end
Equivalent to "when (jaskell.java.instanceof)"
The following assertion succeeds:
assert("string", translate "a") where translate x = typecase x .case (java.int) "int" .case (java.lang.String) "string" .default "unknown" .end end
The following assertion succeeds:
assert("string,int", getTypes "abc" 1) where getTypes a b = overload [a,b] .case [java.int, java.int] "int,int" .case [java.lang.String, java.int] "string,int" .end end
To create a mutable reference of a value.
Different than 'jaskell.imperative.ref', this function provides more helper utilities.
Description:
To make sure an object is not a function.
The same object is returned if it is not a function;
Exception is thrown otherwise.
This is particularly useful when we want to make sure enough
parameters are provided to a function and partial-application
is not in effect.
A typical try-catch-finally can be written as:
try (some_expression) .catch(Exception1, handler1) .catch(Exception2, Handler2) .finally(have_to_run_expression) .endSame as Java, try-catch, or try-finally is also allowed:
try(some_expression) .catch(Exception1, handler1) .end
try(some_expression) .finally(have_to_run_expression) .end
'try' only handles direct execution of expression that could throw exception.
Some higher-order construct (such as a function, or an interface,
that when executed in a context, may throw exception) also needs
the try-catch-finally idiom. This function provides this idiom to
these higher-order constructs.
The 1st parameter should be a tuple with the following members:
The parameter is the monad "bind" function.
The return value is a function that supports "do-notation" for the given "bind" operation.
The monad "do-notation" has the following characteristic:
"do {x=a} b" is equivalent to "a `bind \x->b".
Nested Class Summary | |
---|---|
static interface |
Jaskell.Logger
The inferface for Jaskell runtime to log non-fatal error messages. |
Method Summary | |
---|---|
Jaskell |
addClasses(java.lang.String[] names,
java.lang.Class[] types)
Register classes under different names. |
Jaskell |
addMethod(java.lang.Class type,
java.lang.String name,
Function f)
Add a function whose name is local to a certain object type. |
Jaskell |
addSysPackage(java.lang.String prefix)
Create a new Jaskell object by adding a prefix for a system package so that dynamically created ClassLoader objects will always use parent-first policy for packages starting with this prefix. |
static void |
castToBean(java.lang.Object from,
java.lang.Object to,
java.lang.String subject)
Use a tuple java.util.Map object to populate a target java bean object by calling setters. |
static java.lang.Object |
castToJava(java.lang.Class type,
java.lang.Object obj,
java.lang.Object subject)
Casts a jaskell object to a certain java type. |
static Expr |
compileExpr(Expr expr)
Compiles an expression. |
static FunBinding[] |
compileLib(FunDef[] defs)
Compiles a list of function definitions as a library. |
static Jaskell |
defaultInstance()
Create a default instance of Jaskell runtime. |
static Jaskell |
defaultInstance(java.lang.ClassLoader cloader)
Create a default instance of Jaskell that includes all built-in functions. |
Jaskell |
disableImport()
Disables the ability to import jaskell module. |
Jaskell |
dropValue(java.lang.String fullname)
Drop a value from a runtime. |
Jaskell |
enableImport()
Enables the ability to import jaskell module. |
java.lang.Object |
eval(java.lang.CharSequence src)
Parse, compile and then run the jaskell script in the string. |
java.lang.Object |
eval(Expr expr)
Evaluate a compiled expression to a value. |
java.lang.Object |
eval(java.lang.Object module_id,
java.lang.CharSequence src)
Parse, compile and then run the jaskell script in the string. |
java.lang.Object |
eval(java.lang.Object module_id,
java.lang.String module,
java.lang.CharSequence src)
Parse, compile and then run the jaskell script in the string. |
static java.lang.Object |
evalArgument(java.lang.Object arg)
When implementing non-strict function, this method can be used to request evaluation against a function argument. |
java.lang.Object |
evalFile(java.io.File f)
Load file, parse, compile and then run the jaskell script in the string. |
java.lang.Object |
evalFile(java.io.File f,
boolean refresh)
Load file, parse, compile and then run the jaskell script in the string. |
java.lang.Object |
evalFile(java.lang.String fname)
Load file, parse, compile and then run the jaskell script in the string. |
java.lang.Object |
evalInputStream(java.lang.Object module_id,
java.lang.String module,
java.io.InputStream in)
Parse, compile and then run the jaskell script in the input stream. |
Tuple |
evalLib(FunBinding[] defs)
Evaluate a list of compiled function definitions as a Tuple. |
java.lang.Object |
evalReader(java.lang.Object module_id,
java.lang.String module,
java.io.Reader reader)
Parse, compile and then run the jaskell script in the reader. |
java.lang.Object |
evalResource(java.lang.String name)
Load, parse, compile and then run the jaskell script from a certain resource. |
java.lang.Object |
evalResource(java.lang.String name,
boolean refresh)
Load, parse, compile and then run the jaskell script from a certain resource. |
java.lang.ClassLoader |
getClassLoader()
To get the ClassLoader object used by the Jaskell object. |
LocationAware |
getLocator()
To get the LocationAware object used by the Jaskell evaluator. |
Jaskell.Logger |
getLogger()
To get the Logger object currently used by the Jaskell object. |
Resolver |
getResolver()
To get the Resolver object used by the Jaskell evaluator. |
Jaskell |
importClass(java.lang.Class type)
Import a java class and its public static nested classes as a tuple under the class name. |
Jaskell |
importClass(java.lang.String fullname,
java.lang.Class type)
Import a java class and its public static nested classes in a tuple. |
Jaskell |
importClasses(java.lang.Class[] types)
Import an array of java classes into the namespace. |
Jaskell |
importClassHierarchy(java.lang.Class type)
Import a java class and its public static nested classes into the evaluation context. |
Jaskell |
importPrelude()
Import the prelude.jsl module into the jaskell.prelude namespace. |
Jaskell |
importPrelude(boolean explode)
Import the prelude.jsl module into the jaskell.prelude namespace. |
Jaskell |
importStandardClasses()
To load some standard java classes to the namespace. |
Jaskell |
importStrictFunction(java.lang.String fullname,
Function f)
Import a Java Function. |
Jaskell |
importTuple(java.lang.String fullname,
Tuple t)
Import a tuple. |
Jaskell |
importValue(java.lang.Object o)
Import a Java object. |
Jaskell |
importValue(java.lang.String fullname,
java.lang.Object o)
Import a Java object. |
static Expr |
loadExpr(java.lang.Object module_id,
java.lang.String module,
java.lang.CharSequence src)
Parse and compile source code containing an expression. |
static Expr |
loadExpr(java.lang.Object module_id,
java.lang.String module,
java.io.InputStream in)
Parse and compile source code containing an expression. |
static Expr |
loadExprFile(java.io.File file)
Parse and compile an expression contained in a file. |
static Expr |
loadExprFile(java.lang.String fname)
Parse and compile an expression contained in a file. |
java.lang.Object |
lookup(java.lang.String fullname)
Lookup the value of a given path. |
static Expr |
parseExpr(java.lang.Object module_id,
java.lang.CharSequence src)
Parses source code containing an expression. |
static Expr |
parseExpr(java.lang.Object module_id,
java.lang.String module,
java.lang.CharSequence src)
Parses source code containing an expression. |
static Expr |
parseExpr(java.lang.Object module_id,
java.lang.String module,
jfun.parsec.PositionMap pmap,
java.lang.CharSequence src)
Parses source code containing an expression. |
static java.lang.Object |
parseExprOrLib(java.lang.Object module_id,
java.lang.CharSequence src)
Parses source code containing either an expression or a list of function definitions. |
static java.lang.Object |
parseExprOrLib(java.lang.Object module_id,
java.lang.String module,
java.lang.CharSequence src)
Parses source code containing either an expression or a list of function definitions. |
static java.lang.Object |
parseExprOrLib(java.lang.Object module_id,
java.lang.String module,
jfun.parsec.PositionMap pmap,
java.lang.CharSequence src)
Parses source code containing either an expression or a list of function definitions. |
static FunDef[] |
parseLib(java.lang.Object module_id,
java.lang.CharSequence src)
Parses source code containing a list of function definitions that can be mutually dependent. |
static FunDef[] |
parseLib(java.lang.Object module_id,
java.lang.String module,
java.lang.CharSequence src)
Parses source code containing a list of function definitions that can be mutually dependent. |
static FunDef[] |
parseLib(java.lang.Object module_id,
java.lang.String module,
jfun.parsec.PositionMap pmap,
java.lang.CharSequence src)
Parses source code containing a list of function definitions that can be mutually dependent. |
Jaskell |
setLocator(LocationAware loc)
Get a Jaskell object that uses a LocationAware object to notify source location of an expression. |
Jaskell |
setLogger(Jaskell.Logger logger)
Create a new Jaskell object that uses a Logger object to log non-fatal error messages. |
Jaskell |
setResolver(Resolver resolver)
Get a Jaskell object that uses a Resolver object to resolve unbound variables and undefined tuple members. |
static Tuple |
toClassTuple(java.lang.Class type)
To adapt a type to a corresponding Tuple. |
static Tuple |
toObjectTuple(java.lang.Object obj)
To adapt an object to a corresponding Tuple. |
Jaskell |
useClassLoader(java.lang.ClassLoader loader)
Create a new Jaskell object that uses a ClassLoader object to load classes. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static Jaskell defaultInstance()
public static Jaskell defaultInstance(java.lang.ClassLoader cloader)
cloader
- the ClassLoader to load classes for the interpreter.
to the evaluated objects.
public Jaskell disableImport()
public Jaskell enableImport()
public Jaskell importPrelude(boolean explode)
explode
- true if we also want to bring the prelude members in the top level namespace.
public Jaskell importPrelude()
The members are not exploded into the top level namespace.
public Jaskell importClasses(java.lang.Class[] types)
types
- the java classes to import.
public Jaskell addClasses(java.lang.String[] names, java.lang.Class[] types)
names
- the names that identifies these classes.types
- the classes.
public Jaskell importStandardClasses()
public java.lang.Object eval(Expr expr) throws EvaluationException
expr
- the compiled expression object.
EvaluationException
- thrown if evaluation fails.public static Expr compileExpr(Expr expr) throws CompilationException
expr
- the expression.
CompilationException
- thrown if compilation fails.public Tuple evalLib(FunBinding[] defs)
defs
- the compiled function definitions.
public static FunBinding[] compileLib(FunDef[] defs)
defs
- the function definitions.
public static FunDef[] parseLib(java.lang.Object module_id, java.lang.String module, java.lang.CharSequence src) throws jfun.parsec.ParserException
module_id
- the module identifier.module
- the module name.src
- the source code.
jfun.parsec.ParserException
- if parse fails.public static FunDef[] parseLib(java.lang.Object module_id, java.lang.String module, jfun.parsec.PositionMap pmap, java.lang.CharSequence src) throws jfun.parsec.ParserException
module_id
- the module identifier.module
- the module name.pmap
- the PositionMap to tell the location of each character.src
- the source code.
jfun.parsec.ParserException
- if parse fails.public static FunDef[] parseLib(java.lang.Object module_id, java.lang.CharSequence src) throws jfun.parsec.ParserException
module_id
- the module identifier.src
- the source code.
jfun.parsec.ParserException
- if parse fails.public static Expr parseExpr(java.lang.Object module_id, java.lang.String module, jfun.parsec.PositionMap pmap, java.lang.CharSequence src) throws jfun.parsec.ParserException
module_id
- the module identifier.module
- the module name.pmap
- the PositionMap to tell the location of each character.src
- the source code containing the expression.
jfun.parsec.ParserException
- thrown if parsing fails.public static Expr parseExpr(java.lang.Object module_id, java.lang.String module, java.lang.CharSequence src) throws jfun.parsec.ParserException
module_id
- the module identifier.module
- the module name.src
- the source code containing the expression.
jfun.parsec.ParserException
- thrown if parsing fails.public static Expr parseExpr(java.lang.Object module_id, java.lang.CharSequence src) throws jfun.parsec.ParserException
module_id
- the id of the module.src
- the source code containing the expression.
jfun.parsec.ParserException
- thrown if parsing fails.public static java.lang.Object parseExprOrLib(java.lang.Object module_id, java.lang.String module, jfun.parsec.PositionMap pmap, java.lang.CharSequence src) throws jfun.parsec.ParserException
module_id
- the module identifier.module
- the module name.pmap
- the PositionMap to tell the location of each character.src
- the source code.
jfun.parsec.ParserException
- thrown if parsing fails.public static java.lang.Object parseExprOrLib(java.lang.Object module_id, java.lang.String module, java.lang.CharSequence src) throws jfun.parsec.ParserException
module_id
- the module identifier.module
- the module name.src
- the source code.
jfun.parsec.ParserException
- thrown if parsing fails.public static java.lang.Object parseExprOrLib(java.lang.Object module_id, java.lang.CharSequence src) throws jfun.parsec.ParserException
module_id
- the module identifier.src
- the source code.
jfun.parsec.ParserException
- thrown if parsing fails.public static Expr loadExpr(java.lang.Object module_id, java.lang.String module, java.io.InputStream in) throws jfun.parsec.ParserException, CompilationException, java.io.IOException
module
- the module name.in
- the InputStream object containing the source code.
jfun.parsec.ParserException
- thrown if parsing fails.
CompilationException
- thrown if compilation fails.
java.io.IOException
- if failed to read the input.public static Expr loadExpr(java.lang.Object module_id, java.lang.String module, java.lang.CharSequence src) throws jfun.parsec.ParserException, CompilationException
module
- the module name.src
- the source code.
jfun.parsec.ParserException
- thrown if parsing fails.
CompilationException
- thrown if compilation fails.public static Expr loadExprFile(java.io.File file) throws java.io.FileNotFoundException, java.io.IOException, jfun.parsec.ParserException, CompilationException
file
- the file.
java.io.FileNotFoundException
- thrown if the source file cannot be found.
java.io.IOException
- thrown if fails to read the file.
jfun.parsec.ParserException
- thrown if parsing fails.
CompilationException
- thrown if compilation fails.public static Expr loadExprFile(java.lang.String fname) throws java.io.FileNotFoundException, java.io.IOException, jfun.parsec.ParserException, CompilationException
fname
- the file name.
java.io.FileNotFoundException
- thrown if the source file cannot be found.
java.io.IOException
- thrown if fails to read the file.
jfun.parsec.ParserException
- thrown if parsing fails.
CompilationException
- thrown if compilation fails.public java.lang.Object eval(java.lang.Object module_id, java.lang.String module, java.lang.CharSequence src) throws jfun.parsec.ParserException, CompilationException
module
- the module name. Name anything that's most meaningful.src
- the sting containing jaskell source code.
jfun.parsec.ParserException
- thrown if parsing fails.
CompilationException
- thrown if compilation fails.public java.lang.Object eval(java.lang.Object module_id, java.lang.CharSequence src) throws jfun.parsec.ParserException, CompilationException
module_id
- the id of the module being evaluated.src
- the sting containing jaskell source code.
jfun.parsec.ParserException
- thrown if parsing fails.
CompilationException
- thrown if compilation fails.public java.lang.Object eval(java.lang.CharSequence src)
src
- the sting containing jaskell source code.
jfun.parsec.ParserException
- thrown if parsing fails.
CompilationException
- thrown if compilation fails.public java.lang.Object evalResource(java.lang.String name) throws java.io.IOException
The resource is not reloaded if it is already loaded.
name
- the resource name.
java.io.IOException
- if error happens when reading this resource.
jfun.parsec.ParserException
- thrown if parsing fails.
CompilationException
- thrown if compilation fails.public java.lang.Object evalResource(java.lang.String name, boolean refresh) throws java.io.IOException
name
- the resource name.refresh
- do we reload if the resource is already loaded?
java.io.IOException
- if error happens when reading this resource.
jfun.parsec.ParserException
- thrown if parsing fails.
CompilationException
- thrown if compilation fails.public java.lang.Object evalFile(java.lang.String fname) throws java.io.FileNotFoundException, java.io.IOException, jfun.parsec.ParserException, CompilationException
The file is not reloaded if it is already loaded.
fname
- the source file name.
java.io.FileNotFoundException
- if the file is not found.
java.io.IOException
- if error happens when reading this file.
jfun.parsec.ParserException
- thrown if parsing fails.
CompilationException
- thrown if compilation fails.public java.lang.Object evalFile(java.io.File f) throws java.io.FileNotFoundException, java.io.IOException, jfun.parsec.ParserException, CompilationException
The file is not reloaded if it is already loaded.
f
- the source file.
java.io.FileNotFoundException
- if the file is not found.
java.io.IOException
- if error happens when reading this file.
jfun.parsec.ParserException
- thrown if parsing fails.
CompilationException
- thrown if compilation fails.public java.lang.Object evalFile(java.io.File f, boolean refresh) throws java.io.FileNotFoundException, java.io.IOException, jfun.parsec.ParserException, CompilationException
f
- the source file.refresh
- do we reload if the file is already loaded?
java.io.FileNotFoundException
- if the file is not found.
java.io.IOException
- if error happens when reading this file.
jfun.parsec.ParserException
- thrown if parsing fails.
CompilationException
- thrown if compilation fails.public java.lang.Object evalInputStream(java.lang.Object module_id, java.lang.String module, java.io.InputStream in) throws java.io.IOException
module
- the module namein
- the input stream
java.io.IOException
- if error happens when reading.
jfun.parsec.ParserException
- thrown if parsing fails.
CompilationException
- thrown if compilation fails.public java.lang.Object evalReader(java.lang.Object module_id, java.lang.String module, java.io.Reader reader) throws java.io.IOException
module
- the module namereader
- the reader
java.io.IOException
- if error happens when reading.
jfun.parsec.ParserException
- thrown if parsing fails.
CompilationException
- thrown if compilation fails.public Jaskell importValue(java.lang.String fullname, java.lang.Object o)
fullname
- the full qualified name that's gonna be used in jaskell code.o
- the java object.
public Jaskell importValue(java.lang.Object o)
o
- the java object.
public Jaskell dropValue(java.lang.String fullname)
fullname
- the full name of the path.
public java.lang.Object lookup(java.lang.String fullname)
fullname
- the full path name.
public static java.lang.Object castToJava(java.lang.Class type, java.lang.Object obj, java.lang.Object subject)
type
- the target type.obj
- the object to convert.subject
- the subject for this cast.
The string representation of this object will show up
in the TypeMismatchException message.
public Jaskell importStrictFunction(java.lang.String fullname, Function f)
fullname
- the full qualified name that's gonna be used in jaskell code.f
- the java Function object.
public Jaskell importTuple(java.lang.String fullname, Tuple t)
fullname
- the namespace where the tuple is imported.
The members are imported to the top level namespace
if fullname is empty or null,
in this case, only the members with a string key are imported.t
- the tuple.
public Jaskell importClassHierarchy(java.lang.Class type)
type
- the java class.
public Jaskell importClass(java.lang.String fullname, java.lang.Class type)
fullname
- the fullname of the tuple.type
- the java class.
public Jaskell importClass(java.lang.Class type)
type
- the java class.
public Jaskell useClassLoader(java.lang.ClassLoader loader)
loader
- the ClassLoader object to use.
public Jaskell addSysPackage(java.lang.String prefix)
prefix
- the package prefix.
public Jaskell setLogger(Jaskell.Logger logger)
logger
- the logger object.
public Jaskell setLocator(LocationAware loc)
loc
- the LocationAware object.
public Jaskell setResolver(Resolver resolver)
resolver
- the resolver object.
public Jaskell addMethod(java.lang.Class type, java.lang.String name, Function f)
type
- the type for the method.name
- the method name.f
- the function that accepts the object as its first parameter.
public Jaskell.Logger getLogger()
public java.lang.ClassLoader getClassLoader()
public LocationAware getLocator()
public Resolver getResolver()
public static void castToBean(java.lang.Object from, java.lang.Object to, java.lang.String subject)
from
- the source map or tuple object.to
- the target java bean object.subject
- the subject of this casting. will appear in error message.public static Tuple toObjectTuple(java.lang.Object obj)
obj
- the object.
public static Tuple toClassTuple(java.lang.Class type)
type
- the type.
public static java.lang.Object evalArgument(java.lang.Object arg)
arg
- the function argument.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |