[ Expand All ] [ Collapse All ] - [ Properties (2) ] [ Methods (27) ] - [ Legend ]

RdqlParser Class v. V0.9.1

Object
RdqlParser

Class: RdqlParser ----------------------------------------------------------------------------------

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.

<BR><BR>History:<UL> <LI>05-12-2004 : Support for unquoted QNames added. However, backward compatibility is provided, that means, both prefix:local_name and <prefix:local_name> are allowed. In the case of unquoted QNames, the parser now also checks if a prefix is defined in the USING clause. changes: - the stracture of the class variable $parsedQuery - methods: parseFrom(), parseExpressions(), replaceNamespacePrefixes(), _validateVarUri(), _validateVarUriLiteral(), _validateUri(), _validateLiteral(), _validatePrefix() methods added: _validateQName(), _validateNCName(), _replaceNamespacePrefix() : Bug in the handling of empty Literals fixed.</LI> <LI>07-27-2003 : First release of this class</LI>

AuthorRadoslaw Oldakowski
Properties implemented by RdqlParser
private method parsedQuery

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 )

private method tokens

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.

Methods implemented by RdqlParser
private method _checkComma

PHP_checkComma(string $commaExpected, string $clause_error)

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.

Arguments

private method _checkRegExQuotation

PHP_checkRegExQuotation(string $filterString, string $lQuotMark, string $rQuotMark)

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

Arguments

private method _checkSelectVars

PHP_checkSelectVars()

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

private method _clearWhiteSpaces

PHP_clearWhiteSpaces()

============================================================================= *************************** helper functions ******************************** =============================================================================

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

private method _isDefined

PHPstring _isDefined(unknown $var)

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

Arguments

private method _replaceNamespacePrefix

PHPstring _replaceNamespacePrefix(string $qName, unknown $clause_error)

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

Arguments

private method _validateLiteral

PHParray _validateLiteral(string $token)

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

Arguments

Return

['value'] = string ['is_literal'] = boolean ['l_lang'] = string ['l_dtype'] = string ['l_dtype_is_qname'] = boolean

private method _validateNCName

PHPboolean _validateNCName(string $token)

Check if the given token is a valid NCName.

Arguments

private method _validatePrefix

PHPstring _validatePrefix(string $token)

Check if the given token is a valid namespace prefix.

Arguments

private method _validateQName

PHPboolean _validateQName(string $token, string $clause_error)

Check if the given token is a valid QName.

Arguments

private method _validateUri

PHPstring _validateUri(string $token, string $clause_error)

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

Arguments

private method _validateVar

PHPstring _validateVar(string $token, string $clause_error)

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

Arguments

private method _validateVarUri

PHParray _validateVarUri(string $token)

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.

Arguments

Return

['value'] = string

private method _validateVarUriLiteral

PHParray _validateVarUriLiteral(string $token)

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.

Arguments

Return

['value'] = string ['is_qname'] = boolean ['is_literal'] = boolean ['l_lang'] = string ['l_dtype'] = string

private method findAllQueryVariables

PHParray findAllQueryVariables()

Find all query variables used in the WHERE clause.

Return

[] = ?VARNAME

private method parseAnd

PHPparseAnd()

Parse the AND clause of an Rdql query

private method parseExpressions

PHParray parseExpressions(unknown $filterStr)

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.

Arguments

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

private method parseFilter

PHPparseFilter(integer $n, string $filter)

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

Arguments

private method parseFrom

PHPparseFrom()

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

public method parseQuery

PHParray parseQuery(string $queryString)

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

Arguments

Return

$this->parsedQuery

private method parseSelect

PHPparseSelect()

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.

private method parseUsing

PHPparseUsing()

Parse the USING clause of an Rdql query

private method parseWhere

PHPparseWhere()

*' 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.

private method removeComments

PHPstring removeComments(string $query)

Remove comments from the passed query string.

Arguments

private method replaceNamespacePrefixes

PHPreplaceNamespacePrefixes()

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.

private method startParsing

PHPstartParsing()

Start parsing of the tokenized query string.

private method tokenize

PHPtokenize(string $queryString)

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.

Arguments

Generated by PHPEdit - Copyright © 1999-2004 - Sébastien Hordeaux - WaterProof SARL