prefuse.data.expression.parser
Class ExpressionParser

java.lang.Object
  extended by prefuse.data.expression.parser.ExpressionParser
All Implemented Interfaces:
ExpressionParserConstants

public class ExpressionParser
extends java.lang.Object
implements ExpressionParserConstants

Parser for statements written in the prefuse expression language. Text expression are parsed into Expression instances, and can be used as predicates or to create derived table columns. This parser is implemented using the JavaCC package. To parse a text String to an Expression, use the 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 getError() method. One can also use the parse(String, boolean) with a true boolean argument to request that Exceptions be thrown when errors occur.

Prefuse Expression Language Reference

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 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 TupleSet.tuples(prefuse.data.expression.Predicate) method uses a Predicate to filter the requested set of tuples, and the 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 dynamic query bindings, and is used to create the rule chains evaluated by the DefaultRendererFactory, ColorAction, ShapeAction, FontAction, and SizeAction classes.

The 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.

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 parse(java.lang.String) method. If the string parses successfully, the parsed Expression instance will be returned.

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 Function interface and registering it with the FunctionTable class.

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.

Literal Values and Data Field References

The fundamental building blocks of the expression language, representing data values or referencing the contents of a Tuple data field.

Operators and Control Flow

Basic operators and control flow structures for the expression language.

General Functions

General purpose functions.

Mathematical Functions

Functions for performing mathematical calculations.

String Functions

Functions for processing text strings.

Color Functions

Functions for generating, translating, and interpolating color values.

Visualization Functions

These functions can only be used when the Tuple being evaluated is a VisualItem, and provide access to data group information of the VisualItem's Visualization. Individual visual data fields can be accessed directly using a data field reference. For example, _x, _y, _hover, _highlight, _fillColor would evaluate to references for the x-coordinate, y-coordinate, mouse hover status, highlight status, and fill color, respectively.

Author:
jeffrey heer

Field Summary
static Token jj_nt
           
static Token token
           
static ExpressionParserTokenManager token_source
           
 
Fields inherited from interface prefuse.data.expression.parser.ExpressionParserConstants
ADD, AND, DECIMAL_LITERAL, DEFAULT, DIGIT, DIV, DOUBLE, ELSE, EOF, EQ, EXPONENT, FALSE, FLOAT, GE, GT, HEX_LITERAL, IDENTIFIER, IF, INT, LE, LETTER, LONG, LPAREN, LT, MOD, MUL, NE, NOT, NULL, OCTAL_LITERAL, OR, POW, QUOTED, RPAREN, STRING, SUB, THEN, tokenImage, TRUE, XOR
 
Constructor Summary
ExpressionParser(ExpressionParserTokenManager tm)
           
ExpressionParser(java.io.InputStream stream)
           
ExpressionParser(java.io.Reader stream)
           
 
Method Summary
static Expression AdditiveExpression()
           
static Expression AndExpression()
           
static void disable_tracing()
           
static void enable_tracing()
           
static Expression EqualityExpression()
           
static Expression Expression()
           
static ParseException generateParseException()
           
static java.lang.Throwable getError()
          Get the last error, if any, generated by a parse operation.
static Token getNextToken()
           
static Token getToken(int index)
           
static Expression Identifier()
           
static Expression IfStatement()
           
static Expression Literal()
           
static Expression MultiplicativeExpression()
           
static java.lang.String Name()
           
static Expression OrExpression()
           
static Expression Parse()
           
static Expression parse(java.lang.String expr)
          Parse an expression.
static Expression parse(java.lang.String expr, boolean throwsException)
          Parse an expression.
static Predicate predicate(java.lang.String expr)
          Parse an expression as a predicate.
static Expression PrimaryExpression()
           
static java.lang.String Quoted()
           
 void ReInit(ExpressionParserTokenManager tm)
           
static void ReInit(java.io.InputStream stream)
           
static void ReInit(java.io.Reader stream)
           
static Expression RelationalExpression()
           
static Expression UnaryExpression()
           
static Expression UnaryExpressionNotPlusMinus()
           
static Expression XorExpression()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

token_source

public static ExpressionParserTokenManager token_source

token

public static Token token

jj_nt

public static Token jj_nt
Constructor Detail

ExpressionParser

public ExpressionParser(java.io.InputStream stream)

ExpressionParser

public ExpressionParser(java.io.Reader stream)

ExpressionParser

public ExpressionParser(ExpressionParserTokenManager tm)
Method Detail

parse

public static Expression parse(java.lang.String expr,
                               boolean throwsException)
Parse an expression.

Parameters:
expr - the expression text to parse
throwsException - true if this method should throw an exception if an error occurs or should fail quietly
Returns:
the parsed Expression, or null if the parse failed and throwsException is false

parse

public static Expression parse(java.lang.String expr)
Parse an expression. This method does not throw an exception if a parse error occurs. Use getError() to access any generated exceptions.

Parameters:
expr - the expression text to parse
Returns:
the parsed Expression, or null if the parse failed

predicate

public static Predicate predicate(java.lang.String expr)
Parse an expression as a predicate. This method does not throw an exception if a parse error occurs. Use getError() to access any generated exceptions.

Parameters:
expr - the expression text to parse
Returns:
the parsed Expression, or null if the parse failed

getError

public static java.lang.Throwable getError()
Get the last error, if any, generated by a parse operation.

Returns:
the last error generated during parsing

Name

public static final java.lang.String Name()
                                   throws ParseException
Throws:
ParseException

Quoted

public static final java.lang.String Quoted()
                                     throws ParseException
Throws:
ParseException

Parse

public static final Expression Parse()
                              throws ParseException
Throws:
ParseException

Expression

public static final Expression Expression()
                                   throws ParseException
Throws:
ParseException

OrExpression

public static final Expression OrExpression()
                                     throws ParseException
Throws:
ParseException

XorExpression

public static final Expression XorExpression()
                                      throws ParseException
Throws:
ParseException

AndExpression

public static final Expression AndExpression()
                                      throws ParseException
Throws:
ParseException

EqualityExpression

public static final Expression EqualityExpression()
                                           throws ParseException
Throws:
ParseException

RelationalExpression

public static final Expression RelationalExpression()
                                             throws ParseException
Throws:
ParseException

AdditiveExpression

public static final Expression AdditiveExpression()
                                           throws ParseException
Throws:
ParseException

MultiplicativeExpression

public static final Expression MultiplicativeExpression()
                                                 throws ParseException
Throws:
ParseException

UnaryExpression

public static final Expression UnaryExpression()
                                        throws ParseException
Throws:
ParseException

UnaryExpressionNotPlusMinus

public static final Expression UnaryExpressionNotPlusMinus()
                                                    throws ParseException
Throws:
ParseException

PrimaryExpression

public static final Expression PrimaryExpression()
                                          throws ParseException
Throws:
ParseException

Literal

public static final Expression Literal()
                                throws ParseException
Throws:
ParseException

Identifier

public static final Expression Identifier()
                                   throws ParseException
Throws:
ParseException

IfStatement

public static final Expression IfStatement()
                                    throws ParseException
Throws:
ParseException

ReInit

public static void ReInit(java.io.InputStream stream)

ReInit

public static void ReInit(java.io.Reader stream)

ReInit

public void ReInit(ExpressionParserTokenManager tm)

getNextToken

public static final Token getNextToken()

getToken

public static final Token getToken(int index)

generateParseException

public static ParseException generateParseException()

enable_tracing

public static final void enable_tracing()

disable_tracing

public static final void disable_tracing()


Copyright 2007 Regents of the University of California