Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove grammar duplication #62

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 1 addition & 12 deletions sources/cql.y
Expand Up @@ -848,17 +848,7 @@ math_expr[result]:
;

expr[result]:
basic_expr { $result = $basic_expr; }
| expr[lhs] '&' expr[rhs] { $result = new_ast_bin_and($lhs, $rhs); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the problem here is that if you use math_expr for all of these then the LHS and RHS are limited to math_expr which means you cast parse something like CAST(1 as REAL) + 1

I'm adding new test cases to give a clean error on that.

| expr[lhs] '|' expr[rhs] { $result = new_ast_bin_or($lhs, $rhs); }
| expr[lhs] LS expr[rhs] { $result = new_ast_lshift($lhs, $rhs); }
| expr[lhs] RS expr[rhs] { $result = new_ast_rshift($lhs, $rhs); }
| expr[lhs] '+' expr[rhs] { $result = new_ast_add($lhs, $rhs); }
| expr[lhs] '-' expr[rhs] { $result = new_ast_sub($lhs, $rhs); }
| expr[lhs] '*' expr[rhs] { $result = new_ast_mul($lhs, $rhs); }
| expr[lhs] '/' expr[rhs] { $result = new_ast_div($lhs, $rhs); }
| expr[lhs] '%' expr[rhs] { $result = new_ast_mod($lhs, $rhs); }
| '-' expr[rhs] %prec UMINUS { $result = new_ast_uminus($rhs); }
math_expr { $result = $math_expr; }
| NOT expr[rhs] { $result = new_ast_not($rhs); }
| '~' expr[rhs] { $result = new_ast_tilde($rhs); }
| expr[lhs] COLLATE name { $result = new_ast_collate($lhs, $name); }
Expand All @@ -885,7 +875,6 @@ expr[result]:
| expr[lhs] BETWEEN math_expr[me1] AND math_expr[me2] { $result = new_ast_between($lhs, new_ast_range($me1,$me2)); }
| expr[lhs] IS_NOT expr[rhs] { $result = new_ast_is_not($lhs, $rhs); }
| expr[lhs] IS expr[rhs] { $result = new_ast_is($lhs, $rhs); }
| expr[lhs] CONCAT expr[rhs] { $result = new_ast_concat($lhs, $rhs); }
| CASE expr[cond] case_list END { $result = new_ast_case_expr($cond, new_ast_connector($case_list, NULL)); }
| CASE expr[cond1] case_list ELSE expr[cond2] END { $result = new_ast_case_expr($cond1, new_ast_connector($case_list, $cond2));}
| CASE case_list END { $result = new_ast_case_expr(NULL, new_ast_connector($case_list, NULL));}
Expand Down