📄 cql.y
字号:
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; Symantec Corporation; The Open Group.//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions:// // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.////==============================================================================%{#include <Pegasus/Common/Config.h>#include <Pegasus/Common/String.h>#include <Pegasus/Common/CommonUTF.h>#include <Pegasus/Query/QueryCommon/QueryException.h>#include <Pegasus/Common/MessageLoader.h>#include <Pegasus/CQL/CQLFactory.h>#include "CQLObjects.h"#include <stdio.h>#define yyparse CQL_parse#define CQLPREDICATE 0#define CQLVALUE 1#define CQLIDENTIFIER 2#define CQLFUNCTION 3#define CQLCHAINEDIDENTIFIER 4#ifdef CQL_DEBUG_GRAMMAR#define DEBUG_GRAMMAR 1#else#define DEBUG_GRAMMAR 0#endifint yylex();static char msg[100];void printf_(char * msg){ if(DEBUG_GRAMMAR == 1) printf("%s\n",msg);}extern char * yytext;int chain_state;CQLFactory _factory = CQLFactory();extern int CQL_error(const char *err);enum CQLType { Id, CId, Val, Func, Fact, Trm, Expr, SPred, Pred, Str };typedef struct CQLObjPtr { void* _ptr; CQLType type; } CQLOBJPTR;Array<CQLObjPtr> _ptrs;CQLOBJPTR _ObjPtr;void CQL_Bison_Cleanup(){ for(Uint32 i = 0; i < _ptrs.size(); i++){ if(_ptrs[i]._ptr){ switch(_ptrs[i].type){ case Id: delete (CQLIdentifier*)_ptrs[i]._ptr; break; case CId: delete (CQLChainedIdentifier*)_ptrs[i]._ptr; break; case Val: delete (CQLValue*)_ptrs[i]._ptr; break; case Func: delete (CQLFunction*)_ptrs[i]._ptr; break; case Fact: delete (CQLFactor*)_ptrs[i]._ptr; break; case Trm: delete (CQLTerm*)_ptrs[i]._ptr; break; case Expr: delete (CQLExpression*)_ptrs[i]._ptr; break; case SPred: delete (CQLSimplePredicate*)_ptrs[i]._ptr; break; case Pred: delete (CQLPredicate*)_ptrs[i]._ptr; break; case Str: delete (String*)_ptrs[i]._ptr; } } } _ptrs.clear(); _factory.cleanup(); _factory = CQLFactory();}PEGASUS_NAMESPACE_BEGIN extern CQLParserState* CQL_globalParserState;Array<CQLPredicate> _arglist;PEGASUS_NAMESPACE_END%}%union { char * strValue; String * _string; CQLValue * _value; CQLIdentifier * _identifier; CQLChainedIdentifier * _chainedIdentifier; CQLPredicate * _predicate; ExpressionOpType _opType; void * _node;}/* terminals */%token <strValue> IDENTIFIER %token <strValue> STRING_LITERAL%token <strValue> BINARY%token <strValue> NEGATIVE_BINARY%token <strValue> HEXADECIMAL%token <strValue> NEGATIVE_HEXADECIMAL%token <strValue> INTEGER %token <strValue> NEGATIVE_INTEGER%token <strValue> REAL %token <strValue> NEGATIVE_REAL%token <strValue> _TRUE %token <strValue> _FALSE %token <strValue> SCOPED_PROPERTY%token <strValue> LPAR %token <strValue> RPAR %token <strValue> HASH%token <strValue> DOT %token <strValue> LBRKT %token <strValue> RBRKT %token <strValue> UNDERSCORE%token <strValue> COMMA %token <strValue> CONCAT %token <strValue> DBL_PIPE%token <strValue> PLUS%token <strValue> MINUS %token <strValue> TIMES %token <strValue> DIV %token <strValue> IS %token <strValue> _NULL %token <_opType> _EQ%token <_opType> _NE %token <_opType> _GT %token <_opType> _LT %token <_opType> _GE %token <_opType> _LE %token <_opType> _ISA %token <_opType> _LIKE %token <strValue> NOT _AND _OR %token <strValue> SCOPE %token <strValue> ANY EVERY IN SATISFIES %token <strValue> STAR %token <strValue> DOTDOT %token <strValue> SHARP DISTINCT %token <strValue> SELECT %token <strValue> FIRST %token <strValue> FROM %token <strValue> WHERE %token <strValue> ORDER %token <strValue> BY %token <strValue> ASC %token <strValue> DESC %token <strValue> AS %token <strValue> UNEXPECTED_CHAR/* grammar - non terminals */%type <_identifier> identifier%type <_identifier> class_name%type <_identifier> class_path%type <_identifier> scoped_property%type <_string> literal_string%type <_value> binary_value%type <_value> hex_value%type <_value> decimal_value%type <_value> real_value%type <_value> literal%type <_string> array_index%type <_string> array_index_list%type <_node> chain%type <_predicate> concat%type <_predicate> factor%type <_predicate> term%type <_predicate> arith%type <_value> value_symbol%type <_predicate> arith_or_value_symbol%type <_opType> comp_op%type <_predicate> comp%type <_predicate> expr_factor%type <_predicate> expr_term%type <_predicate> expr%type <_node> arg_list%type <_node> from_specifier%type <_node> from_criteria%type <_chainedIdentifier> star_expr%type <_node> selected_entry%type <_node> select_list%type <_node> select_list_tail%type <_node> search_condition%type <_node> optional_where%type <_node> select_statement%start select_statement%% /** The general pattern: We construct small objects first (CQLIdentifiers, CQLValues etc) which get forwared to more complex rules where more complex objects are made. Eventually we have constructed a top level CQLPredicate that gets added to the CQL_globalParserState select statement. Along the way we keep track of which rule we are processing so that any errors encountered are specific enough to actually do us some good. The CQLFactory object is used primarily to save space/coding efforts. It enables us to build complex CQL objects with one simple call, or query complex objects through one simple call. *//* CQLIdentifier */identifier : IDENTIFIER { CQL_globalParserState->currentRule = "identifier"; sprintf(msg,"BISON::identifier\n"); printf_(msg); if(isUTF8Str(CQL_lval.strValue)){ $$ = new CQLIdentifier(String(CQL_lval.strValue)); _ObjPtr._ptr = $$; _ObjPtr.type = Id; _ptrs.append(_ObjPtr); }else{ sprintf(msg,"BISON::identifier-> BAD UTF\n"); printf_(msg); throw CQLSyntaxErrorException( MessageLoaderParms(String("CQL.CQL_y.BAD_UTF8"), String("Bad UTF8 encountered parsing rule $0 in position $1."), String("identifier"), CQL_globalParserState->currentTokenPos) ); } };class_name : identifier { CQL_globalParserState->currentRule = "class_name"; sprintf(msg,"BISON::class_name = %s\n", (const char *)($1->getName().getString().getCString())); printf_(msg); $$ = $1; };class_path : class_name { CQL_globalParserState->currentRule = "class_path"; sprintf(msg,"BISON::class_path\n"); printf_(msg); $$ = $1; };/*property_scope : class_path SCOPE { sprintf(msg,"BISON::property_scope = %s\n",$1); printf_(msg); }*/;/* CQLIdentifier */scoped_property : SCOPED_PROPERTY { /* SCOPED_PROPERTY can be: - "A::prop" - "A::class.prop" - "A::class.prop#'OK' - "A::class.prop[4]" */ CQL_globalParserState->currentRule = "scoped_property"; sprintf(msg,"BISON::scoped_property = %s\n",CQL_lval.strValue); printf_(msg); if(isUTF8Str(CQL_lval.strValue)){ String tmp(CQL_lval.strValue); $$ = new CQLIdentifier(tmp); _ObjPtr._ptr = $$; _ObjPtr.type = Id; _ptrs.append(_ObjPtr); }else{ sprintf(msg,"BISON::scoped_property-> BAD UTF\n"); printf_(msg); throw CQLSyntaxErrorException( MessageLoaderParms(String("CQL.CQL_y.BAD_UTF8"), String("Bad UTF8 encountered parsing rule $0 in position $1."), String("scoped_property"), CQL_globalParserState->currentTokenPos) ); } }; /* String */literal_string : STRING_LITERAL { /* We make sure the literal is valid UTF8, then make a String */ CQL_globalParserState->currentRule = "literal_string"; sprintf(msg,"BISON::literal_string-> %s\n",CQL_lval.strValue); printf_(msg); if(isUTF8Str(CQL_lval.strValue)){ $$ = new String(CQL_lval.strValue); _ObjPtr._ptr = $$; _ObjPtr.type = Str;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -