summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b34c3a7)
raw | patch | inline | side by side (parent: b34c3a7)
author | Sebastian Harl <sh@tokkee.org> | |
Sun, 1 Mar 2015 17:36:34 +0000 (18:36 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sun, 1 Mar 2015 17:36:34 +0000 (18:36 +0100) |
Constant expressions are evaluated early. Thus, creating an expression object
may fail if there's a semantics error. Catch this early and report a (generic)
error to avoid propagating a NULL value.
may fail if there's a semantics error. Catch this early and report a (generic)
error to avoid propagating a NULL value.
src/frontend/grammar.y | patch | blob | history |
diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y
index 323fe4feadba40715c3b43c95d0f5d93441de564..db3df642d3525c9ec729159eb45e4fd4034079bc 100644 (file)
--- a/src/frontend/grammar.y
+++ b/src/frontend/grammar.y
%type <m> matcher
compare_matcher
-%type <expr> expression object_expression
+%type <expr> expression arithmetic_expression object_expression
%type <integer> object_type object_type_plural
%type <integer> iterable
;
expression:
+ arithmetic_expression
+ {
+ if (! $1) {
+ /* we should have better error messages here
+ * TODO: maybe let the analyzer handle this instead */
+ sdb_fe_yyerrorf(&yylloc, scanner,
+ YY_("syntax error, invalid arithmetic expression"));
+ YYABORT;
+ }
+ $$ = $1;
+ }
+ |
+ object_expression
+ {
+ $$ = $1;
+ }
+ |
+ data
+ {
+ $$ = sdb_store_expr_constvalue(&$1);
+ sdb_data_free_datum(&$1);
+ }
+ ;
+
+arithmetic_expression:
'(' expression ')'
{
$$ = $2;
sdb_object_deref(SDB_OBJ($1)); $1 = NULL;
sdb_object_deref(SDB_OBJ($3)); $3 = NULL;
}
- |
- object_expression
- {
- $$ = $1;
- }
- |
- data
- {
- $$ = sdb_store_expr_constvalue(&$1);
- sdb_data_free_datum(&$1);
- }
;
object_expression: