com.lonniepryor.blues.util
Class Expression

java.lang.Object
  |
  +--com.lonniepryor.blues.util.Expression

public final class Expression
extends java.lang.Object

Helper class for parsing logical expressions and combining them using the AND, OR, and NOT operations. Expression parses according to the following format:

   expression  ::=  or
   or          ::=  and [ ( "|" | "||" ) and ]...
   and         ::=  not [ ( "&" | "&&" ) not ]...
   not         ::=  [ "!" ] statement
   statement   ::=  predicate  |  "(" expression ")"
   predicate   ::=  See below.
 
The information in the "predicate" type must start with any non-whitespace character except parenthesis, '|', &', and '!'; but thereafter can use any characters, provided any of the aforementioned characters are contained in matching pairs of parenthesis. This allows nesting expressions in method-like grammars. Example:
  foo((him | her) & !me) & !bar | baz (This is my message)
 
The above will be parsed into: "foo((him | her) & !me)", the AND operator, the NOT operator, "bar", the OR operator, and "baz (This is my message)".

Version:
$Revision: 1.1 $
Author:
Lonnie Pryor

Nested Class Summary
static interface Expression.Builder
          Strategy interface used to construct in-memory representations of an expression.
 
Method Summary
static int ltrim(java.lang.String text, int start, int end)
          Searches the string for the greatest index less than or equal to the end parameter that is not a whitespace character.
static java.lang.Object parse(java.lang.String expression, Expression.Builder builder)
          Parses the supplied expression string into objects provided by the specified Builder.
static int rtrim(java.lang.String text, int start, int end)
          Searches the string for the smallest index greater than or equal to the start parameter that is not a whitespace character.
static int statementBeginsAt(java.lang.String text, int begin, int statementEnd)
          Returns the index in the string of the first character of the statement that ends at the supplied index.
static int statementBeginsAt(java.lang.String text, int begin, int statementEnd, java.lang.String terminators)
          Returns the index in the string of the first character of the statement that ends at the supplied index, using the supplied statement terminators.
static int statementEndsAt(java.lang.String text, int statementBegin, int end)
          Returns the index in the string of the first character past the end of the statement that begins at the supplied index.
static int statementEndsAt(java.lang.String text, int statementBegin, int end, java.lang.String terminators)
          Returns the index in the string of the first character past the end of the statement that begins at the supplied index, using the supplied statement terminators.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

parse

public static java.lang.Object parse(java.lang.String expression,
                                     Expression.Builder builder)
Parses the supplied expression string into objects provided by the specified Builder.

Parameters:
expression - The expression to parse.
builder - The Builder to construct objects with.
Returns:
The Builder-supplied value of the expression.
Throws:
ParseException - if the supplied string is invalid.

statementEndsAt

public static int statementEndsAt(java.lang.String text,
                                  int statementBegin,
                                  int end)
Returns the index in the string of the first character past the end of the statement that begins at the supplied index.

Parameters:
text - The text to search.
statementBegin - The index of the first character in the statement.
end - The point at which to stop searching.
Returns:
The index in the string of the first character past the end of the statement that begins at the supplied index, or -1 if a matching parenthesis is not found.

statementEndsAt

public static int statementEndsAt(java.lang.String text,
                                  int statementBegin,
                                  int end,
                                  java.lang.String terminators)
Returns the index in the string of the first character past the end of the statement that begins at the supplied index, using the supplied statement terminators.

Parameters:
text - The text to search.
statementBegin - The index of the first character in the statement.
end - The point at which to stop searching.
terminators - Any characters that signal the end of the statement.
Returns:
The index in the string of the first character past the end of the statement that begins at the supplied index, or -1 if a matching parenthesis is not found.

statementBeginsAt

public static int statementBeginsAt(java.lang.String text,
                                    int begin,
                                    int statementEnd)
Returns the index in the string of the first character of the statement that ends at the supplied index.

Parameters:
text - The text to search.
begin - The point at which to stop searching.
statementEnd - The index of the character following the end of the statement.
Returns:
The index in the string of the first character of the statement that ends at the supplied index, or -1 if a matching parenthesis is not found.

statementBeginsAt

public static int statementBeginsAt(java.lang.String text,
                                    int begin,
                                    int statementEnd,
                                    java.lang.String terminators)
Returns the index in the string of the first character of the statement that ends at the supplied index, using the supplied statement terminators.

Parameters:
text - The text to search.
begin - The point at which to stop searching.
statementEnd - The index of the character following the end of the statement.
terminators - Any characters that signal the end of the statement.
Returns:
The index in the string of the first character of the statement that ends at the supplied index, or -1 if a matching parenthesis is not found.

ltrim

public static int ltrim(java.lang.String text,
                        int start,
                        int end)
Searches the string for the greatest index less than or equal to the end parameter that is not a whitespace character.

Parameters:
text - The text to search.
start - The beginning of the section to search.
end - The end of the section to search.
Returns:
The new start value.

rtrim

public static int rtrim(java.lang.String text,
                        int start,
                        int end)
Searches the string for the smallest index greater than or equal to the start parameter that is not a whitespace character.

Parameters:
text - The text to search.
start - The beginning of the section to search.
end - The end of the section to search.
Returns:
The new end value.


Copyright © 2003 Blues Framework. All Rights Reserved.