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>
|
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 )
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.
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
PHP | _checkRegExQuotation(string $filterString, string $lQuotMark, string $rQuotMark) |
---|
Throw an error if the regular expression from the AND clause is not quoted.
Arguments
PHP | _checkSelectVars() |
---|
Check if all variables from the SELECT clause are defined in the WHERE clause
PHP | _clearWhiteSpaces() |
---|
============================================================================= *************************** helper functions ******************************** =============================================================================
Remove whitespace-tokens from the array $this->tokens
PHP | string _isDefined(unknown $var) |
---|
Check if the given variable is defined in the WHERE clause.
Arguments
string
PHP | string _replaceNamespacePrefix(string $qName, unknown $clause_error) |
---|
Replace a prefix in a given QName and return a full URI.
Arguments
PHP | array _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
PHP | boolean _validateNCName(string $token) |
---|
Check if the given token is a valid NCName.
Arguments
PHP | string _validatePrefix(string $token) |
---|
Check if the given token is a valid namespace prefix.
Arguments
PHP | boolean _validateQName(string $token, string $clause_error) |
---|
Check if the given token is a valid QName.
Arguments
PHP | string _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
PHP | string _validateVar(string $token, string $clause_error) |
---|
Check if the given token is a valid variable name (?var).
Arguments
PHP | array _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
PHP | array _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
PHP | array findAllQueryVariables() |
---|
Find all query variables used in the WHERE clause.
Return
[] = ?VARNAME
PHP | array 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
PHP | parseFilter(integer $n, string $filter) |
---|
Check if a filter from the AND clause contains an equal number of '(' and ')' and parse filter expressions.
Arguments
PHP | parseFrom() |
---|
Parse the FROM/SOURCES clause of an Rdql query When the parsing of this clause is finished, parseWhere() will be called.
PHP | array parseQuery(string $queryString) |
---|
Parse the given RDQL query string and return an array with query variables and constraints.
Arguments
Return
$this->parsedQuery
PHP | parseSelect() |
---|
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.
PHP | parseWhere() |
---|
*' 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.
PHP | string removeComments(string $query) |
---|
Remove comments from the passed query string.
Arguments
PHP | replaceNamespacePrefixes() |
---|
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.
PHP | tokenize(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