Package com.singularsys.client
Class GWTExpose
java.lang.Object
com.singularsys.client.GWTExpose
- All Implemented Interfaces:
EntryPoint
GWT entry point exposing parts of the Jep system to JavaScript using the JSNI system.
The following methods are provided
var node = window.jep.parse(string)
parse an expressionwindow.jep.evaluateD()
evaluate the last expression parsedwindow.jep.evaluate(node)
evaluate a nodewindow.jep.getVariableValue(name)
return the value of a Jep variablewindow.jep.setVariable(name,val)
set the value of a Jep variablewindow.jep.getErrMsg()
return the last error messagewindow.jep.nodeType(node)
finds the type of a given nodewindow.jep.getNChildren(node)
return the number of childerne of a nodewindow.jep.getChild(node,i)
find the i-th child of a nodewindow.jep.getOperator(node)
find the operator associated with a nodewindow.jep.getNodeName(node)
find the name of associated with a node, either a variable name or function namewindow.jep.getNodeValue(node)
finds the value of a node, either a constant value of a variable valuewindow.jep.getOpPrec(op)
find the precedence of an operatorwindow.jep.getOpSymbol(op)
find the symbol of an operatorwindow.jep.nf.buildVarNode(name)
build a node representing a variablewindow.jep.nf.buildConstantNode(val)
build a node with a constant valuewindow.jep.nf.buildBinaryOpNode(op,l,r)
build a node with two arguments
- Author:
- rich
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Node
buildBinaryOpNode
(Operator op, Node l, Node r) static Node
buildConstantNode
(Object val) static Node
static void
consoleLog
(String msg) Native method to write to the JavaScript consolestatic double
Evaluates the last expression returning a double.static Object
evaluateNE
(Node node) Evaluate a node, returning an object, does not throw exceptionsstatic Object
Evaluate a node, returning an objectstatic Node
Gets the child of a nodestatic String
Returns the error message generated by the last action.static Object
getJavaValue
(Object val) Convert a JavaScript value to Java value suitable for Jep.static Object
getJSValue
(Object val) Convert values produced by Jep into values suitable for JavaScript.static int
getNChildren
(Node n) Return the number of children of a nodestatic String
getNodeName
(Node n) Returns the name of a variable or function nodestatic Operator
static Object
getNodeValue
(Node n) Returns the value of a constant or variable nodestatic int
static String
getOpSymbol
(Operator op) static Object
getVariableValueO
(String name) Gets the value of a variable as an object valuestatic int
Returns the type of the node.static void
Native method written in JavaScript.void
Standard GWT method called when module loaded.static Node
Parse an expressionstatic Node
Parse an expression, does not throw exceptionsstatic Variable
setVariable
(String name, Object obj) Set the value of a variable to a object valuestatic Variable
setVariableNE
(String name, Object obj) Set the value of a variable to a object valuestatic String
-
Constructor Details
-
GWTExpose
public GWTExpose()
-
-
Method Details
-
onModuleLoad
public void onModuleLoad()Standard GWT method called when module loaded.- Specified by:
onModuleLoad
in interfaceEntryPoint
-
parse
Parse an expression- Parameters:
S
- expression- Returns:
- root node of parse tree
- Throws:
ParseException
- if the string cannot be successfully parsed
-
parseNE
Parse an expression, does not throw exceptions- Parameters:
S
- expression- Returns:
- root node of parse tree or null the string cannot be successfully parsed
- Throws:
ParseException
-
evaluateD
public static double evaluateD()Evaluates the last expression returning a double.- Returns:
- either the double result or NaN on EvaluationException
-
evaluateO
Evaluate a node, returning an object- Parameters:
node
- expression to evaluate- Returns:
- value or null on EvaluationException
- Throws:
EvaluationException
- if an error in evaluation
-
evaluateNE
Evaluate a node, returning an object, does not throw exceptions- Parameters:
node
- expression to evaluate- Returns:
- value or null if an error occurred during evaluation
-
setVariableNE
Set the value of a variable to a object value- Parameters:
name
- name of variableobj
- JavaScript value of the variable- Returns:
- the variable object or null if an attempt to set a constant variable or the value cannot be converted to Java
-
setVariable
Set the value of a variable to a object value- Parameters:
name
- name of variableobj
- JavaScript value of the variable- Returns:
- the variable object
- Throws:
JepException
- if an attempt to set a constant variable or the value cannot be converted to Java
-
getJavaValue
Convert a JavaScript value to Java value suitable for Jep. Most types are parsed directly apart from JsArray arrays which are converted toVectors<Object>
the type used by standard Jep.- Parameters:
val
- value from JavaScript, must be Number, String, Boolean or array.- Returns:
- converted value or null on error.
- Throws:
EvaluationException
-
getVariableValueO
Gets the value of a variable as an object value- Parameters:
name
- variable name- Returns:
- value as an object
-
getJSValue
Convert values produced by Jep into values suitable for JavaScript. Changes Jeps Vector representation for arrays to- Parameters:
val
-- Returns:
-
getErrorMsg
Returns the error message generated by the last action.- Returns:
- the error message or "" if no error detected
-
toString
- Throws:
EvaluationException
-
nodeType
Returns the type of the node.- Parameters:
n
- node to examine- Returns:
- 2 for operators, 3 for variable, 4 for functions or 5 for constants
-
getNChildren
Return the number of children of a node- Parameters:
n
- node to examine- Returns:
- number of children
-
getChild
Gets the child of a node- Parameters:
n
- node to examinei
- position of child index from zero- Returns:
- the child
-
getNodeName
Returns the name of a variable or function node- Parameters:
n
- node to examine- Returns:
- a string
-
getNodeValue
Returns the value of a constant or variable node- Parameters:
n
- node to examine- Returns:
- a object representing the value
-
getNodeOperator
-
getOpPrec
-
getOpSymbol
-
buildVarNode
-
buildConstantNode
-
buildBinaryOpNode
-
onModLoad
public static void onModLoad()Native method written in JavaScript. Adds methods to the JavaScriptwindow.jep
object. Methods are- jep.parse(expression)
- jep.evaluateD()
- jep.evluate(node)
- jep.getVariableValue(name)
- jep.setVariableValue(name,val)
- jep.getJavaValue(val)
-
consoleLog
Native method to write to the JavaScript console- Parameters:
msg
-
-