在目前的WHERE条件中,针对where ((a > 0) and (c = 'hjd'))之间的逻辑表达式无法识别,参考oracle的语法文件,我修改了语法文件,语法已可以验证,但在遍历语法树时,TOKEN下面的子TOKEN内容无法获取,语法定义的内容如下:
/*==================================================================//
// //
// Where Condition Begin //
// //
//==================================================================*/
where_condition
: condition
{ #where_condition = #([WHERE_CONDITION, "where_condition"], #where_condition); }
;
condition
: logical_term ( ("or"^ | "或者"^) logical_term )*
;
logical_term
: logical_factor ( ("and"^ | "并且"^) logical_factor )*
;
logical_factor
: ( exp_simple compare_op exp_simple ) => (exp_simple compare_op exp_simple )
{#logical_factor = #([COMPARE_OP, "comp_op"], #logical_factor);}
| ( exp_simple ( "in" | "在于" ) ) => exp_simple ( "in" | "在于" ) exp_set
{ #logical_factor = #([LOGICAL_CONTAIN, "logic_contain"], #logical_factor); }
| ( exp_simple ( "not in" | "不在于" ) ) => exp_simple ( "not in" | "不在于" ) exp_set
{ #logical_factor = #([LOGICAL_CONTAIN, "logic_contain"], #logical_factor); }
| ( exp_simple ( "like" | "包含" ) ) => exp_simple ("like" | "包含" ) where_expression ( "escape" QUOTED_STRING )?
{ #logical_factor = #([LOGICAL_LIKE, "logic_like"], #logical_factor); }
| ( exp_simple ( "not like" | "不包含" ) ) => exp_simple ("not like" | "不包含" ) where_expression ( "escape" QUOTED_STRING )?
{ #logical_factor = #([LOGICAL_LIKE, "logic_like"], #logical_factor); }
| ( exp_simple ( "between"| "范围" ) ) => exp_simple ( "between" | "范围" ) exp_simple exp_simple
{ #logical_factor = #([LOGICAL_BETWEEN, "logic_between"], #logical_factor); }
| ( exp_simple ( "not between"| "不在范围" ) ) => exp_simple ( "not between" | "不在范围" ) exp_simple exp_simple
{ #logical_factor = #([LOGICAL_BETWEEN, "logic_between"], #logical_factor); }
| ( exp_simple ( "is null" | "为空" ) ) => exp_simple ( "is null" | "为空" )
{ #logical_factor = #([LOGICAL_NULL, "logic_null"], #logical_factor); }
| ( exp_simple ( "is not null" | "非空" ) ) => exp_simple ( "is not null" | "非空" )
{ #logical_factor = #([LOGICAL_NULL, "logic_null"], #logical_factor); }
| ( quantified_factor ) => quantified_factor
{ #logical_factor = #([LOGICAL_EXISTS, "logic_exists"], #logical_factor); }
| ( ( "not" | "非" ) condition ) => ( "not" | "非" ) condition
{ #logical_factor = #([COND_NOT, "cond_not"], #logical_factor); }
| ( LPAREN condition RPAREN )
{ #logical_factor = #([COND_PAREN, "cond_paren"], #logical_factor); }
;
quantified_factor
: ( exp_simple compare_op ( "all" | "any" )? subquery ) => exp_simple compare_op ( "all" | "any" )? subquery
| ( ( "not" )? "exists" subquery ) => ( "not" )? "exists" subquery
| subquery
;
exp_simple
: where_expression
;
where_expression
: term ( ( PLUS^ | MINUS^ | "加"^ | "减"^) term )*
;
term
: factor ( ( MUL^ | DIVIDE^ | "乘"^ | "除"^) factor )*
;
multiply
: MUL | "乘"
{ #multiply = #([MULTIPLY, "multiply"], #multiply); }
;
factor
: ( sql_literal ) => sql_literal
| ( ( PLUS | MINUS ) where_expression ) => ( PLUS | MINUS ) where_expression
| ( function_name ( LPAREN where_expression ( COMMA where_expression )* RPAREN ) ) => function_name ( LPAREN where_expression ( COMMA where_expression )* RPAREN )
{ #factor = #([NORMAL_FUNCTION, "normal_function"], #factor); }
| ( aggregate_func_name LPAREN ( STAR | "all" | "distinct" )? (where_expression)? RPAREN ) => aggregate_func_name LPAREN ( STAR | "all" | "distinct" )? (where_expression)? RPAREN
{ #factor = #([GROUP_FUNCTION, "group_function"], #factor); }
| ( LPAREN where_expression RPAREN ) => LPAREN where_expression RPAREN
{ #factor = #([EXPRESSION_PAREN, "expression_paren"], #factor); }
;
sql_literal
: constant
| field_name
;
where_expression_list
: LPAREN where_expression ( COMMA where_expression )+ RPAREN
;
exp_set
: LPAREN constexpset RPAREN
{#exp_set = #([SUBCONTAIN_OP, "subcontain_op"], #exp_set);}
// | subquery
;
constexpset
: constant (COMMA^ constant)*
// {#constexpset = #([SUBCONTAIN_CONTENT, "subcontain_content"], #constexpset);}
;
/*==================================================================//
// //
// Where Condition End //
// //
//==================================================================*/
posted on 2007-04-12 10:50
LORD BLOG 阅读(557)
评论(0) 编辑 收藏 所属分类:
工作日志