Class RdqlParser

Description

This class contains methods for parsing an Rdql query string into PHP variables.

The output of the RdqlParser is an array with variables and constraints of each query clause (Select, From, Where, And, Using). To perform an RDQL query this array has to be passed to the RdqlEngine.

  • access: public
  • author: Radoslaw Oldakowski <radol@gmx.de>
  • version: $Id: RdqlParser.html,v 1.15 2006/06/26 12:34:21 tgauss Exp $

Located in /rdql/RdqlParser.php (line 21)

Object
   |
   --RdqlParser
Variable Summary
array $parsedQuery
array $tokens
Method Summary
void parseAnd ()
array parseExpressions ( $filterStr, string $filteStr)
void parseFilter (integer $n, string $filter)
void parseFrom ()
array &parseQuery (string $queryString)
void parseSelect ()
void parseUsing ()
void parseWhere ()
string removeComments (string $query)
void startParsing ()
void tokenize (string $queryString)
void _checkComma (string $commaExpected, string $clause_error)
void _checkRegExQuotation (string $filterString, string $lQuotMark, string $rQuotMark)
string _isDefined (mixed $var)
string _replaceNamespacePrefix (string $qName,  $clause_error, string $clasue_error)
array _validateLiteral (string $token)
boolean _validateNCName (string $token)
string _validatePrefix (string $token)
boolean _validateQName (string $token, string $clause_error)
string _validateUri (string $token, string $clause_error)
string _validateVar (string $token, string $clause_error)
array _validateVarUri (string $token)
array _validateVarUriLiteral (string $token)
Variables
array $parsedQuery (line 57)

Parsed query variables and constraints.

{ } are only used within the parser class and are not returned as parsed query. ( [] stands for an integer index - 0..N )

  • var: ['selectVars'][] = ?VARNAME ['sources'][]{['value']} = URI | QName {['is_qname'] = boolean} ['patterns'][]['subject']['value'] = VARorURI {['is_qname'] = boolean} ['predicate']['value'] = VARorURI {['is_qname'] = boolean} ['object']['value'] = VARorURIorLiterl {['is_qname'] = boolean} ['is_literal'] = boolean ['l_lang'] = string ['l_dtype'] = string {['l_dtype_is_qname'] = boolean} ['filters'][]['string'] = string ['evalFilterStr'] = string ['reqexEqExprs'][]['var'] = ?VARNAME ['operator'] = (eq | ne) ['regex'] = string ['strEqExprs'][]['var'] = ?VARNAME ['operator'] = (eq | ne) ['value'] = string ['value_type'] = ('variable' | 'URI' | 'QName' | 'Literal') ['value_lang'] = string ['value_dtype'] = string {['value_dtype_is_qname'] = boolean} ['numExpr']['vars'][] = ?VARNAME {['ns'][PREFIX] = NAMESPACE}
  • access: private
array $tokens (line 68)

Query string divided into a sequence of tokens.

A token is either: ' ' or "\n" or "\r" or "\t" or ',' or '(' or ')' or a string containing any characters except from the above.

  • access: private
Methods
findAllQueryVariables (line 593)

Find all query variables used in the WHERE clause.

  • return: [] = ?VARNAME
  • access: private
array findAllQueryVariables ()
parseAnd (line 383)

Parse the AND clause of an Rdql query

  • todo: clear comments
  • access: private
  • throws: PhpError
void parseAnd ()
parseExpressions (line 502)

Parse expressions inside the passed filter: 1) regex equality expressions: ?var [~~ | =~ | !~ ] REG_EX 2a) string equality expressions: ?var [eq | ne] "literal"@lang^^dtype.

2b) string equality expressions: ?var [eq | ne] <URI> or ?var [eq | ne] prefix:local_name 3) numerical expressions: e.q. (?var1 - ?var2)*4 >= 20

In cases 1-2 parse each expression of the given filter into an array of variables. For each parsed expression put a place holder (e.g. ##RegEx_1##) into the filterStr. The RDQLengine will then replace each place holder with the outcomming boolean value of the corresponding expression. The remaining filterStr contains only numerical expressions and place holders.

  • return: ['string'] = string ['evalFilterStr'] = string ['reqexEqExprs'][]['var'] = ?VARNAME ['operator'] = (eq | ne) ['regex'] = string ['strEqExprs'][]['var'] = ?VARNAME ['operator'] = (eq | ne) ['value'] = string ['value_type'] = ('variable' | 'URI' | 'QName'| 'Literal') ['value_lang'] = string ['value_dtype'] = string ['value_dtype_is_qname'] = boolean ['numExpr']['vars'][] = ?VARNAME
  • access: private
array parseExpressions ( $filterStr, string $filteStr)
  • string $filteStr
  • $filterStr
parseFilter (line 456)

Check if a filter from the AND clause contains an equal number of '(' and ')' and parse filter expressions.

  • access: private
  • throws: PHPError
void parseFilter (integer $n, string $filter)
  • integer $n
  • string $filter
parseFrom (line 279)

Parse the FROM/SOURCES clause of an Rdql query When the parsing of this clause is finished, parseWhere() will be called.

  • access: private
  • throws: PhpError
void parseFrom ()
parseQuery (line 78)

Parse the given RDQL query string and return an array with query variables and constraints.

  • access: public
array &parseQuery (string $queryString)
  • string $queryString
parseSelect (line 207)

Parse the SELECT clause of an Rdql query.

When the parsing of the SELECT clause is finished, this method will call a suitable method to parse the subsequent clause.

  • access: private
  • throws: PhpError
void parseSelect ()
parseUsing (line 416)

Parse the USING clause of an Rdql query

  • access: private
  • throws: PhpError
void parseUsing ()
parseWhere (line 321)

' Parse the WHERE clause of an Rdql query.

When the parsing of the WHERE clause is finished, this method will call a suitable method to parse the subsequent clause if provided.

  • access: private
  • throws: PhpError
void parseWhere ()
removeComments (line 101)

Remove comments from the passed query string.

  • access: private
  • throws: PHPError
string removeComments (string $query)
  • string $query
replaceNamespacePrefixes (line 619)

Replace all namespace prefixes in the pattern and constraint clause of an rdql query with the namespaces declared in the USING clause and default namespaces.

  • access: private
void replaceNamespacePrefixes ()
startParsing (line 193)

Start parsing of the tokenized query string.

  • access: private
void startParsing ()
tokenize (line 167)

Divide the query string into tokens.

A token is either: ' ' or "\n" or "\r" or '\t' or ',' or '(' or ')' or a string containing any character except from the above.

  • access: private
void tokenize (string $queryString)
  • string $queryString
_checkComma (line 734)

Check if the query string of the given clause contains an undesired ','.

If a comma was correctly placed then remove it and clear all whitespaces.

  • access: private
  • throws: PHPError
void _checkComma (string $commaExpected, string $clause_error)
  • string $commaExpected
  • string $clause_error
_checkRegExQuotation (line 1052)

Throw an error if the regular expression from the AND clause is not quoted.

  • access: private
  • throws: PHPError
void _checkRegExQuotation (string $filterString, string $lQuotMark, string $rQuotMark)
  • string $filterString
  • string $lQuotMark
  • string $rQuotMark
_checkSelectVars (line 1018)

Check if all variables from the SELECT clause are defined in the WHERE clause

  • access: private
void _checkSelectVars ()
_clearWhiteSpaces (line 714)

Remove whitespace-tokens from the array $this->tokens

  • access: private
void _clearWhiteSpaces ()
_isDefined (line 1033)

Check if the given variable is defined in the WHERE clause.

  • access: private
  • throws: PHPError
string _isDefined (mixed $var)
_replaceNamespacePrefix (line 1004)

Replace a prefix in a given QName and return a full URI.

  • access: private
  • throws: PHPError
string _replaceNamespacePrefix (string $qName,  $clause_error, string $clasue_error)
  • string $qName
  • string $clasue_error
  • $clause_error
_validateLiteral (line 877)

Check if $token is the first token of a valid literal ("LITERAL") and return an array with literal properties (value, language, datatype).

  • return: ['value'] = string ['is_literal'] = boolean ['l_lang'] = string ['l_dtype'] = string ['l_dtype_is_qname'] = boolean
  • access: private
  • throws: PHPError
array _validateLiteral (string $token)
  • string $token
_validateNCName (line 969)

Check if the given token is a valid NCName.

  • access: private
boolean _validateNCName (string $token)
  • string $token
_validatePrefix (line 986)

Check if the given token is a valid namespace prefix.

  • access: private
  • throws: PHPError
string _validatePrefix (string $token)
  • string $token
_validateQName (line 948)

Check if the given token is a valid QName.

  • access: private
  • throws: PHPError
boolean _validateQName (string $token, string $clause_error)
  • string $token
  • string $clause_error
_validateUri (line 831)

Check if $token is the first token of a valid URI (<URI>) and return the whole URI string

  • access: private
  • throws: PHPError
string _validateUri (string $token, string $clause_error)
  • string $token
  • string $clause_error
_validateVar (line 811)

Check if the given token is a valid variable name (?var).

  • access: private
  • throws: PHPError
string _validateVar (string $token, string $clause_error)
  • string $token
  • string $clause_error
_validateVarUri (line 757)

Check if the given token is either a variable (?var) or the first token of an URI (<URI>).

In case of an URI this function returns the whole URI string.

  • return: ['value'] = string
  • access: private
  • throws: PHPError
array _validateVarUri (string $token)
  • string $token
_validateVarUriLiteral (line 785)

Check if the given token is either a variable (?var) or the first token of either an URI (<URI>) or a literal ("Literal").

In case of a literal return an array with literal properties (value, language, datatype). In case of a variable or an URI return only ['value'] = string.

  • return: ['value'] = string ['is_qname'] = boolean ['is_literal'] = boolean ['l_lang'] = string ['l_dtype'] = string
  • access: private
  • throws: PHPError
array _validateVarUriLiteral (string $token)
  • string $token

Inherited Methods

Inherited From Object

Object::toString()

Documentation generated on Mon, 26 Jun 2006 14:26:03 +0200 by phpDocumentor 1.3.0RC6