📄 expressionparser.jj
字号:
// ----------------------------------------------------------------------------
// Options
options {
JAVA_UNICODE_ESCAPE = true;
}
// ----------------------------------------------------------------------------
// Parser Begin
PARSER_BEGIN(ExpressionParser)
package prefuse.data.expression.parser;
import java.io.StringReader;
import java.util.logging.Logger;
import prefuse.data.expression.AndPredicate;
import prefuse.data.expression.ArithmeticExpression;
import prefuse.data.expression.BooleanLiteral;
import prefuse.data.expression.ColumnExpression;
import prefuse.data.expression.ComparisonPredicate;
import prefuse.data.expression.Expression;
import prefuse.data.expression.Function;
import prefuse.data.expression.FunctionTable;
import prefuse.data.expression.IfExpression;
import prefuse.data.expression.NotPredicate;
import prefuse.data.expression.NumericLiteral;
import prefuse.data.expression.ObjectLiteral;
import prefuse.data.expression.OrPredicate;
import prefuse.data.expression.Predicate;
import prefuse.data.expression.XorPredicate;
import prefuse.util.StringLib;
/**
* Parser for statements written in the prefuse expression language. Text
* expression are parsed into {@link prefuse.data.expression.Expression}
* instances, and can be used as predicates or to create derived
* table columns. This parser is implemented using the
* <a href="https://javacc.dev.java.net/">JavaCC package</a>. To parse
* a text String to an {@link prefuse.data.expression.Expression}, use
* the {@link #parse(String)} method. If a parse error occurs, the method
* will fail silently and return null. Any generated exception can be
* later retrieved using the {@link #getError()} method. One can also
* use the {@link #parse(String, boolean)} with a <code>true</code>
* boolean argument to request that Exceptions be thrown when
* errors occur.
*
* <h1>Prefuse Expression Language Reference</h1>
* <p>
* The prefuse expression language provides a convenient way of creating manipulable statements
* over data in a prefuse data structure. For example, the expression language can be used to
* write {@link prefuse.data.expression.Predicate} instances for querying and filtering a table
* or graph, or to create arbitrary expressions over a data set to generate new, derived data
* fields that can in turn be subject to additional processing or visualization. For example,
* the {@link prefuse.data.tuple.TupleSet#tuples(prefuse.data.expression.Predicate)} method
* uses a Predicate to filter the requested set of tuples, and the
* {@link prefuse.data.Table#addColumn(java.lang.String,prefuse.data.expression.Expression)}
* method creates a new table column whose values are generated by the provided Expression.
* The expression machinery is used
* throughout the toolkit -- it underlies the filtering and query optimization features,
* is a key component of {@link prefuse.data.query dynamic query bindings}, and is used to
* create the rule chains evaluated by the
* {@link prefuse.render.DefaultRendererFactory},
* {@link prefuse.action.assignment.ColorAction},
* {@link prefuse.action.assignment.ShapeAction},
* {@link prefuse.action.assignment.FontAction}, and
* {@link prefuse.action.assignment.SizeAction} classes.
* </p>
* <p>
* The {@link prefuse.data.expression.Expression} interface is quite simple: given a single
* Tuple, compute and return a value. The returned value could be an Object, a boolean, an int,
* or other primitive type. Individual methods for each type are available, and which ones are
* legal to call for any given Expression depends on the type of Expression.
* </p>
* <p>
* Expressions can be created directly in Java, by instantiating and chaining together the
* desired Expression instances. This process, however, can be somewhat tedious, so prefuse
* also provides a built-in parser/compiler for generating these chains of Expression
* instances from a textual language. The language is based on a subset of SQL, the
* standard language for database queries. If you have ever written a "WHERE" clause in
* a SQL "SELECT" query, you probably know most of the language already. To parse an
* expression, simply pass a text string containing an expression statement to the
* {@link prefuse.data.expression.parser.ExpressionParser#parse(java.lang.String)}
* method. If the string parses successfully, the parsed Expression instance will be
* returned.
* </p>
* <p>
* Below is the reference for the language, including literal types, data field references,
* basic operators, and included functions. If need be, you can also introduce a new
* function by creating a new instance of the {@link prefuse.data.expression.Function} interface
* and registering it with the {@link prefuse.data.expression.FunctionTable} class.
* </p>
* <p>
* All keywords and functions in the prefuse expression language can be written in
* either uppercase or lowercase. Writing in mixed-case, however, will likely result in parse
* errors.
* </p>
*
* <h2>Literal Values and Data Field References</h2>
* <p>The fundamental building blocks of the expression language, representing data values
* or referencing the contents of a Tuple data field.</p>
* <ul>
* <li><strong>Boolean literals (<code>TRUE, FALSE</code>)</strong><br/>
* The boolean literals representing true and false conditions, parsed to type <code>boolean</code>
* </li>
* <li><strong>Integer literals (<code>1, -5, 12340</code>)</strong><br/>
* Undecorated, non-decimal numbers are parsed as numbers of type <code>int</code>
* </li>
* <li><strong>Long literals (<code>1L, -5L, 12340L</code>)</strong><br/>
* Integer values decorated with the suffix "L" are parsed as numbers of type <code>long</code>
* </li>
* <li><strong>Double literals (<code>1.0, 3.1415, 1e-35, 2.3e6</code>)</strong><br/>
* Numbers with decimals or exponents in scientific notation are parsed as numbers of type <code>double</code>
* </li>
* <li><strong>Float literals (<code>1.0f, 3.1415f, 1e-35f, 2.3e6f</code>)</strong><br/>
* Floating-point values decorated with the suffix "f" are parsed as numbers of type <code>float</code>
* </li>
* <li><strong>String literals (<code>"some text", 'a label'</code>)</strong><br/>
* Text strings placed in double (") or single (') quotations are parsed as <code>String</code> literals
* </li>
* <li><strong>Null literal (<code>null</code>)</strong><br/>
* The string <code>null</code> is parsed as an ObjectLiteral of type null.
* </li>
* <li><strong>Data field references (<code>_strokeColor, [a data field]</code>)</strong><br/>
* Free-standing strings or those placed within brackets are parsed as a reference to the
* data field of that name. Brackets are required for any fields that include spaces or other
* unusual characters in their name (e.g., characters like +, -, *, etc), or conflict with
* an existing keyword For example, <code>true</code> parses to a boolean literal while
* <code>[true]</code> parses to a reference to a data field named 'true'.
* </li>
* </ul>
*
* <h2>Operators and Control Flow</h2>
* <p>Basic operators and control flow structures for the expression language.</p>
* <ul>
* <li><strong><code>x + y</code> (addition)</strong><br/>
* Add <code>x</code> and <code>y</code>
* </li>
* <li><strong><code>x - y</code> (subtraction)</strong><br/>
* Subtract <code>y</code> from <code>x</code>
* </li>
* <li><strong><code>x * y</code> (multiplication)</strong><br/>
* Multiply <code>x</code> and <code>y</code>
* </li>
* <li><strong><code>x / y</code> (division)</strong><br/>
* Divide <code>x</code> by <code>y</code>
* </li>
* <li><strong><code>x ^ y</code> (exponentiation, pow)</strong><br/>
* Raise <code>x</code> to the exponent <code>y</code>
* </li>
* <li><strong><code>x % y</code> (modulo)</strong><br/>
* Return the remainder of <code>x</code> divded by <code>y</code>
* </li>
* <li><strong><code>x = y, x == y</code> (equality)</strong><br/>
* Indicates if <code>x</code> and <code>y</code> are equal
* </li>
* <li><strong><code>x != y, x <> y</code> (inequality)</strong><br/>
* Indicates if <code>x</code> and <code>y</code> are not equal
* </li>
* <li><strong><code>x > y</code> (greater than)</strong><br/>
* Indicates if <code>x</code> is greater than <code>y</code>
* </li>
* <li><strong><code>x >= y</code> (greater than or equal to)</strong><br/>
* Indicates if <code>x</code> is greater than or equal to <code>y</code>
* </li>
* <li><strong><code>x < y</code> (less than)</strong><br/>
* Indicates if <code>x</code> is less than <code>y</code>
* </li>
* <li><strong><code>x <= y</code> (less than or equal to)</strong><br/>
* Indicates if <code>x</code> is less than or equal to <code>y</code>
* </li>
* <li><strong><code>x AND y, x && y</code> (and)</strong><br/>
* Indicates if both <code>x</code> and <code>y</code> are true
* </li>
* <li><strong><code>x OR y, x || y</code> (or)</strong><br/>
* Indicates if either <code>x</code> or <code>y</code> is true
* </li>
* <li><strong><code>NOT x, !x</code> (not)</strong><br/>
* Indicates if the negation of <code>x</code> is true
* </li>
* <li><strong><code>x XOR y</code> (exclusive or)</strong><br/>
* Indicates if one, but not both, of <code>x</code> or <code>y</code> is true
* </li>
* <li><strong><code>IF test THEN x ELSE y</code> (if-then-else)</strong><br/>
* Evaluates the predicate <code>test</code>, and if true evaluates and returns the
* expression <code>x</code>, and if false evaluates and returns the expression
* <code>y</code>
* </li>
* <li><strong><code>()</code> (parentheses)</strong><br/>
* Groups expressions together to enfore a particular order of evaluation. For example,
* <code>1+2*3</code> evaluates to <code>7</code>, while <code>(1+2)*3</code> evaluates
* to <code>9</code>.
* </li>
* </ul>
*
* <h2>General Functions</h2>
* <p>General purpose functions.</p>
* <ul>
* <li><strong><code>ROW()</code></strong><br/>
* Returns the table row number (or -1 if none) of the current Tuple.
* </li>
* <li><strong><code>ISNODE()</code></strong><br/>
* Returns true if the current Tuple is a graph Node.
* </li>
* <li><strong><code>ISEDGE()</code></strong><br/>
* Returns true if the current Tuple is a graph Edge.
* </li>
* <li><strong><code>DEGREE()</code></strong><br/>
* If the current Tuple is graph Node, returns the Node degree
* (the total number of incident edges). Otherwise returns 0.
* </li>
* <li><strong><code>INDEGREE()</code></strong><br/>
* If the current Tuple is graph Node, returns the Node indegree
* (the number of incident edges pointing towards this node).
* Otherwise returns 0.
* </li>
* <li><strong><code>OUTDEGREE()</code></strong><br/>
* If the current Tuple is graph Node, returns the Node outdegree
* (the number of incident edges pointing away from the node).
* Otherwise returns 0.
* </li>
* <li><strong><code>CHILDCOUNT()</code></strong><br/>
* If the current Tuple is graph Node, returns the number of tree
* children nodes. If the Tuple is not a Node, this method returns 0.
* If the Node is part of a Graph (not a Tree), the number of children
* nodes in the current spanning tree is returned. If no spanning tree has
* been computed, a new spanning tree will be computed using the default
* method. See {@link prefuse.data.Graph#getSpanningTree()} for more.
* </li>
* <li><strong><code>TREEDEPTH()</code></strong><br/>
* If the current Tuple is graph Node, returns the depth of this Node
* in its Tree or SpanningTree. If the Tuple is not a Node, this method
* returns 0. If the Node is part of a Graph (not a Tree), the tree depth
* of the node in the current spanning tree is returned. If no spanning
* tree has been computed, a new spanning tree will be computed using the
* default method. See {@link prefuse.data.Graph#getSpanningTree()} for
* more.
* </li>
* </ul>
*
* <h2>Mathematical Functions</h2>
* <p>Functions for performing mathematical calculations.</p>
* <ul>
* <li><strong><code>ABS(x)</code></strong><br/>
* Returns the absolute value of <code>x</code>
* </li>
* <li><strong><code>ACOS(x)</code></strong><br/>
* Returns the inverse cosine (arc cosine) of a <code>x</code>
* </li>
* <li><strong><code>ASIN(x)</code></strong><br/>
* Returns the inverse sine (arc sine) of a <code>x</code>
* </li>
* <li><strong><code>ATAN(x)</code></strong><br/>
* Returns the inverse tangent (arc tangent) of a <code>x</code>
* </li>
* <li><strong><code>ATAN2(y, x)</code></strong><br/>
* For the Cartesian coordinates <code>x</code>, <code>y</code> return the polar coordinate angle theta
* </li>
* <li><strong><code>CEIL(x), CEILING(x)</code></strong><br/>
* Returns the nearest integer value greater than or equal to <code>x</code>.
* </li>
* <li><strong><code>COS(x)</code></strong><br/>
* Returns the cosine of <code>x</code>
* </li>
* <li><strong><code>COT(x)</code></strong><br/>
* Returns the cotangent of <code>x</code>
* </li>
* <li><strong><code>DEGREES(x)</code></strong><br/>
* Converts <code>x</code> from radians to degrees
* </li>
* <li><strong><code>EXP(x)</code></strong><br/>
* Returns the value of <em>e</em> (the base of natural logarithms) raised to the <code>x</code> power
* </li>
* <li><strong><code>FLOOR(x)</code></strong><br/>
* Returns the nearest integer value less than or equal to <code>x</code>.
* </li>
* <li><strong><code>LOG(x), LOG(b, x)</code></strong><br/>
* With one argument, returns the natural logarithm (logarithm base <em>e</em>) of <code>x</code><br/>
* With two arguments, returns the logarithm of <code>x</code> for the provided base <code>b</code>
* </li>
* <li><strong><code>LOG2(x)</code></strong><br/>
* Returns the logarithm base 2 of <code>x</code>
* </li>
* <li><strong><code>LOG10(x)</code></strong><br/>
* Returns the logarithm base 10 of <code>x</code>
* </li>
* <li><strong><code>MAX(a, b, c, ...)</code></strong><br/>
* Returns the maximum value among the provided arguments
* </li>
* <li><strong><code>MIN(a, b, c, ...)</code></strong><br/>
* Returns the minimum value among the provided arguments
* </li>
* <li><strong><code>MOD(x, y)</code></strong><br/>
* Returns <code>x</code> modulo <code>y</code> (the remainder of <code>x</code> divided by <code>y</code>)
* </li>
* <li><strong><code>PI()</code></strong><br/>
* Returns the constant π (= 3.1415926535...), the ratio between the circumference and diameter of a circle
* </li>
* <li><strong><code>POW(x, y), POWER(x, y)</code></strong><br/>
* Return the value of <code>x</code> raised to the exponent <code>y</code>
* </li>
* <li><strong><code>RADIANS(x)</code></strong><br/>
* Converts <code>x</code> from degrees to radians
* </li>
* <li><strong><code>RAND()</code></strong><br/>
* Returns a random floating-point value between 0 and 1
* </li>
* <li><strong><code>ROUND(x)</code></strong><br/>
* Returns the value of <code>x</code> rounded to the nearest integer
* </li>
* <li><strong><code>SIGN(x)</code></strong><br/>
* Returns the sign of <code>x</code>: 1 for positive, -1 for negative
* </li>
* <li><strong><code>SIN(x)</code></strong><br/>
* Returns the sine of <code>x</code>
* </li>
* <li><strong><code>SQRT(x)</code></strong><br/>
* Returns the square root of <code>x</code>
* </li>
* <li><strong><code>SUM(a, b, c, ...)</code></strong><br/>
* Returns the sum of the provided input value
* </li>
* <li><strong><code>TAN(x)</code></strong><br/>
* Returns the tangent of <code>x</code>
* </li>
* <li><strong><code>SAFELOG10(x)</code></strong><br/>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -