spunQ_PropertyParser Class Reference

Parser. More...

List of all members.

Public Member Functions

 tokenize ($string)
 Breaks a string down to its tokens.
 parse ($string)
 Parses a string to create a spunQ_IPLStatement.
 parseComplexStatement ($string)
 Parses a statement that could not be parsed by regular expressions.

Static Public Member Functions

static getInstance ()
 Retrieves Singleton.

Public Attributes

const TOKEN_PARENTHESIS_OPEN = 1
 Token: opening parenthesis '('.
const TOKEN_PARENTHESIS_CLOSE = 2
 Token: closing parenthesis ')'.
const TOKEN_NOT = 4
 Token: boolean negation '!'.
const TOKEN_EQUALS = 8
 Token: equality operator '='.
const TOKEN_NOT_EQUALS = 12
 Token: bitwise OR of not and equality operator '!='.
const TOKEN_LESS = 16
 Token: operator less than '<'.
const TOKEN_LESS_EQUALS = 24
 Token: bitwise OR of less than and equality operator '<='.
const TOKEN_GREATER = 32
 Token: operator greater than '>'.
const TOKEN_GREATER_EQUALS = 40
 Token: bitwise OR of greater than and equality operator '>='.
const TOKEN_BRACKET_OPEN = 64
 Token: opening bracket '['.
const TOKEN_BRACKET_CLOSE = 128
 Token: closing bracket ']'.
const TOKEN_ARRAY_ITEM_SEPARATOR = 256
 Token: separator for array contents ','.
const TOKEN_PROPERTY = 512
 Token: An object property.
const TOKEN_PROPERTY_SEPARATOR = 1024
 Token: separator for chained properties '.
const TOKEN_OR = 2048
 Token: boolean OR 'OR'.
const TOKEN_AND = 4096
 Token: boolean AND 'AND'.
const TOKEN_CONSTANT = 8192
 Token: constant string.
const TOKEN_LIKE = 16384
 Token: 'like' operator.
const TOKEN_NOT_LIKE = 16388
 Token: 'like' operator.
const TOKEN_WHITESPACE = 32768
 Token: whitespace.
const TOKEN_COLON = 65536
 Token: colon ':'.
const TOKEN_NULL = 131072
 Token: null 'NULL'.
const TOKEN_IN = 262144
 Token: in operator.
const TOKEN_NOT_IN = 262148
 Token: in operator.

Protected Member Functions

 __construct ()
 Constructor.
 getTokenUsingRegularExpression ($string, &$i, $regularExpression, $tokenConstant)
 Extracts a token using a regular expression.
 readConstantToken (&$string, &$i)
 Reads a string token and advances the string index.
 reduceParenthesisAndBrackets (&$tokens)
 Replaces all balanced parenthesis and brackets with according objects.
 parseOrStatement ($tokens, $from, $to)
 Tries to parse an OR statement.
 parseAndStatement ($tokens, $from, $to)
 Tries to parse an AND statement.
 parseComparison ($tokens, $from, $to)
 Tries to parse a comparison.
 parseValue ($tokens, $from, $to)
 Tries to parse a value.
 parsePropertyPath ($tokens, $from, $to)
 Tries to parse a value.
 parseConstantValue ($tokens, $from, $to)
 Tries to parse a constant.
 nextNonWhitespaceToken ($tokens, &$i, $to)
 Advances a token index to the next non-whitespace token.
 checkParsedToken ($tokens, $from, $to, $class)
 Checks if a given class is already present in the $tokens array.
 createStringAndPosition ($tokens, $offset, &$string, &$position)
 Constructs a string and an index for the string from the $tokens array.

Protected Attributes

 $oneCharacterTokens
 Tokens that can easily be mapped to TOKEN_* constants.

Private Attributes

 $parsedStrings = array()
 Cache for strings that have been processed.
 $cache

Static Private Attributes

static $instance
 Singleton instance.


Detailed Description

Parser.

Language syntax:

   statement:
       or-chain
     | and-chain
     | comparison
     | value

   or-chain:
       statement 'OR' statement

   and-chain:
       statement 'AND' statement

   comparison:
       value operator value

   value:
       '!' value
     | property-path
     | constant-value
     | array '.' property-path
     | parenthesis-statement
     | parenthesis-statement '.' property-path

   property-path:
       property property-modifiers
     | property property-modifiers '.' property-path

   property-modifiers:
       <void>
     | property-modifier
     | property-modifier property-modifiers
   
   property-modifier:
       '[' statement ']'
     | '[=' statement ']'
     
   constant-value:
       '{' property '}'

   array:
       '[' array-contents ']'

   array-contents:
       value
     | value ',' array-contents

   parenthesis-statement:
       '(' statement ')'

   property:
       /[_a-z][_a-z0-9]* /

   operator:
       '<'
     | '>'
     | '='
     | '<='
     | '>='
     | '!='
     | 'IN'
     | '!IN'
     | 'LIKE'
     | '!LIKE'

Definition at line 73 of file PropertyParser.class.php.


Constructor & Destructor Documentation

spunQ_PropertyParser::__construct (  )  [protected]

Constructor.

Declared to reduce visibility.

Definition at line 242 of file PropertyParser.class.php.


Member Function Documentation

spunQ_PropertyParser::checkParsedToken ( tokens,
from,
to,
class 
) [protected]

Checks if a given class is already present in the $tokens array.

Because we are processing some parts of the $tokens array in advance (namely parenthesis and brackets), it is well possible that the expected token is already present as an object in either of the parse* functions. This function checks that an object resides in the token within the range [$from-$to] (ignoring whitespace) and returns the object if it is present or NULL otherwise.

See also:
parseComplexStatement()
Parameters:
$tokens array containing the tokens (and possibly some objects).
$from The object must be between the $from and $to indexes of the $tokens array.
$to see $token parameter.
$class The name of the class to look for.
Returns:
spunQ_IPLStatement Or NULL

Definition at line 736 of file PropertyParser.class.php.

spunQ_PropertyParser::createStringAndPosition ( tokens,
offset,
&$  string,
&$  position 
) [protected]

Constructs a string and an index for the string from the $tokens array.

Needed to provide some useful feedback to the user. With this function we can display the character number that caused an error.

See also:
parseComplexStatement()
Parameters:
$tokens array containing the tokens (and possibly some objects).
$offset The token number that had the error.
$string The string that will be generated (out-parameter).
$position The position within the string of the bogus token (out-parameter).
Returns:
void

Definition at line 770 of file PropertyParser.class.php.

static spunQ_PropertyParser::getInstance (  )  [static]

Retrieves Singleton.

Returns:
spunQ_PropertyParser

Definition at line 205 of file PropertyParser.class.php.

spunQ_PropertyParser::getTokenUsingRegularExpression ( string,
&$  i,
regularExpression,
tokenConstant 
) [protected]

Extracts a token using a regular expression.

Parameters:
$string The string to extract from.
$i The index of the string the processing should start at. This parameter will point to the index after the extracted string.
$regularExpression The regular expression to use. Should not contain leading/trailing delimiters. Will be run with the modifiers i (case-insensitive) and s (match newlines).
$tokenConstant The TOKEN_* constant for this token.
Returns:
array<any> A token array. Fulfills the specification of the inner array of the return type of tokenize().

Definition at line 358 of file PropertyParser.class.php.

spunQ_PropertyParser::nextNonWhitespaceToken ( tokens,
&$  i,
to 
) [protected]

Advances a token index to the next non-whitespace token.

See also:
parseComplexStatement()
Parameters:
$tokens array containing the tokens (and possibly some objects).
$i The index to advance.
$to The maximum value $i can have.
Returns:
array<any> The next token array.

Definition at line 709 of file PropertyParser.class.php.

spunQ_PropertyParser::parse ( string  ) 

Parses a string to create a spunQ_IPLStatement.

Tries to parse using regular expressions and passes the string to parseComplexStatement() if it does not work.

Parameters:
$string the property path string
Returns:
spunQ_IPLStatement

Definition at line 296 of file PropertyParser.class.php.

spunQ_PropertyParser::parseAndStatement ( tokens,
from,
to 
) [protected]

Tries to parse an AND statement.

Next in chain: comparison

See also:
parseComplexStatement()
Parameters:
$tokens array containing the tokens (and possibly some objects).
$from Start processing at this index of the tokens array (inclusive).
$to process up to this index (inclusive).
Returns:
spunQ_IPLStatement

Definition at line 509 of file PropertyParser.class.php.

spunQ_PropertyParser::parseComparison ( tokens,
from,
to 
) [protected]

Tries to parse a comparison.

Next in chain: value

See also:
parseComplexStatement()
Parameters:
$tokens array containing the tokens (and possibly some objects).
$from Start processing at this index of the tokens array (inclusive).
$to process up to this index (inclusive).
Returns:
spunQ_IPLStatement
Todo:
Continue here: several comparisons don't make any sense, check them. Some examples:
  • (a AND b) > 4 (less/greater with boolean)
  • 1 != 2 > 4 (less/greater with boolean)
  • a < NULL (less/greater with NULL)

Definition at line 551 of file PropertyParser.class.php.

spunQ_PropertyParser::parseComplexStatement ( string  ) 

Parses a statement that could not be parsed by regular expressions.

The parsing is done with the following steps:

Parameters:
$string the statement to parse.
Returns:
spunQ_IPLStatement

Definition at line 401 of file PropertyParser.class.php.

spunQ_PropertyParser::parseConstantValue ( tokens,
from,
to 
) [protected]

Tries to parse a constant.

Next in chain: <nothing>

See also:
parseComplexStatement()
Parameters:
$tokens array containing the tokens (and possibly some objects).
$from Start processing at this index of the tokens array (inclusive).
$to process up to this index (inclusive).
Returns:
spunQ_IPLStatement

Definition at line 682 of file PropertyParser.class.php.

spunQ_PropertyParser::parseOrStatement ( tokens,
from,
to 
) [protected]

Tries to parse an OR statement.

Next in chain: AND statement

See also:
parseComplexStatement()
Parameters:
$tokens array containing the tokens (and possibly some objects).
$from Start processing at this index of the tokens array (inclusive).
$to process up to this index (inclusive).
Returns:
spunQ_IPLStatement

Definition at line 473 of file PropertyParser.class.php.

spunQ_PropertyParser::parsePropertyPath ( tokens,
from,
to 
) [protected]

Tries to parse a value.

Next in chain: propertypath or constant

See also:
parseComplexStatement()
Parameters:
$tokens array containing the tokens (and possibly some objects).
$from Start processing at this index of the tokens array (inclusive).
$to process up to this index (inclusive).
Returns:
spunQ_IPLStatement

Definition at line 624 of file PropertyParser.class.php.

spunQ_PropertyParser::parseValue ( tokens,
from,
to 
) [protected]

Tries to parse a value.

Next in chain: propertypath or constant

See also:
parseComplexStatement()
Parameters:
$tokens array containing the tokens (and possibly some objects).
$from Start processing at this index of the tokens array (inclusive).
$to process up to this index (inclusive).
Returns:
spunQ_IPLStatement

Definition at line 599 of file PropertyParser.class.php.

spunQ_PropertyParser::readConstantToken ( &$  string,
&$  i 
) [protected]

Reads a string token and advances the string index.

Parameters:
$string The string to read from
$i the index to start extracting the string from. This parameter will point at the position after the string when the operation finishes.
Returns:
array<any> A token array. Fulfills the specification of the inner array of the return type of tokenize().
Exceptions:
spunQ_PropertyPathException 

Definition at line 374 of file PropertyParser.class.php.

spunQ_PropertyParser::reduceParenthesisAndBrackets ( &$  tokens  )  [protected]

Replaces all balanced parenthesis and brackets with according objects.

Parenthesis will be replaced by the spunQ_IPLStatement they evaluate to and brackets by either spunQ_PLArrayTransformation or spunQ_PLArrayReduction.

See also:
parseComplexStatement()
Parameters:
$tokens array<array<any>> as returned by tokenize().
Returns:
array<any> Some tokens might be replaced by spunQ_IPLStatement objects.

Definition at line 417 of file PropertyParser.class.php.

spunQ_PropertyParser::tokenize ( string  ) 

Breaks a string down to its tokens.

Parameters:
$string The string to process
Returns:
array<array<any>> The inner array contains the TOKEN_* constant as the first entry and the string representation as the second.
Exceptions:
spunQ_PropertyPathException 

Definition at line 260 of file PropertyParser.class.php.


Member Data Documentation

spunQ_PropertyParser::$instance [static, private]

Singleton instance.

Type:
spunQ_PropertyParser

Definition at line 199 of file PropertyParser.class.php.

spunQ_PropertyParser::$oneCharacterTokens [protected]

Initial value:

 array(
        '(' => self::TOKEN_PARENTHESIS_OPEN,
        ')' => self::TOKEN_PARENTHESIS_CLOSE,
        '[' => self::TOKEN_BRACKET_OPEN,
        ']' => self::TOKEN_BRACKET_CLOSE,
        '<' => self::TOKEN_LESS,
        '>' => self::TOKEN_GREATER,
        '!' => self::TOKEN_NOT,
        '=' => self::TOKEN_EQUALS,
        ':' => self::TOKEN_COLON,
        '.' => self::TOKEN_PROPERTY_SEPARATOR,
        ',' => self::TOKEN_ARRAY_ITEM_SEPARATOR,
    )
Tokens that can easily be mapped to TOKEN_* constants.

Type:
map<string,integer> As associative array.

Definition at line 216 of file PropertyParser.class.php.

spunQ_PropertyParser::$parsedStrings = array() [private]

Cache for strings that have been processed.

Type:
map<string,spunQ_IPLStatement> As associative array.

Definition at line 234 of file PropertyParser.class.php.

Token: separator for chained properties '.

'

Definition at line 143 of file PropertyParser.class.php.


The documentation for this class was generated from the following file:

Generated on Fri Jul 1 11:12:43 2011 for spunQ3 by  doxygen 1.5.9