Browse code

script parsing: better error reporting

- more informative parse error messages for expression/rvalues
- account for the possibility of having a multi line token when
reporting an error message
- fixed ending column number in error messages

Andrei Pelinescu-Onciul authored on 12/12/2008 12:58:37
Showing 1 changed files
... ...
@@ -2013,9 +2013,9 @@ rval: intno			{$$=mk_rval_expr_v(RV_INT, (void*)$1); }
2013 2013
 	| select_id			{$$=mk_rval_expr_v(RV_SEL, $1); pkg_free($1); }
2014 2014
 	| fcmd				{$$=mk_rval_expr_v(RV_ACTION_ST, $1); }
2015 2015
 	| LBRACE actions RBRACE	{$$=mk_rval_expr_v(RV_ACTION_ST, $2); }
2016
+	| LBRACE error RBRACE	{ yyerror("bad command block"); }
2016 2017
 	| LPAREN assign_action RPAREN	{$$=mk_rval_expr_v(RV_ACTION_ST, $2); }
2017
-	//| exp 				{$$=mk_rval_expr_v(RV_BEXPR, $1);}
2018
-	/* missing/TODO: RV_ACTION_ST */
2018
+	| LPAREN error RPAREN	{ yyerror("bad expression"); }
2019 2019
 	;
2020 2020
 
2021 2021
 
... ...
@@ -2055,6 +2055,19 @@ rval_expr: rval						{ $$=$1;
2055 2055
 			{ $$=mk_rval_expr2(RVE_LOR_OP, $1, $3);}
2056 2056
 		| LPAREN rval_expr RPAREN	{ $$=$2; }
2057 2057
 		| exp_elem { $$=mk_rval_expr_v(RV_BEXPR, $1); }
2058
+		| rve_un_op %prec NOT error { yyerror("bad expression"); }
2059
+		| rval_expr PLUS error		{ yyerror("bad expression"); }
2060
+		| rval_expr MINUS error		{ yyerror("bad expression"); }
2061
+		| rval_expr STAR error		{ yyerror("bad expression"); }
2062
+		| rval_expr SLASH error		{ yyerror("bad expression"); }
2063
+		| rval_expr BIN_OR error	{ yyerror("bad expression"); }
2064
+		| rval_expr BIN_AND error	{ yyerror("bad expression"); }
2065
+		| rval_expr rve_cmpop %prec GT error
2066
+			{ yyerror("bad expression"); }
2067
+		| rval_expr rve_equalop %prec EQUAL_T error
2068
+			{ yyerror("bad expression"); }
2069
+		| rval_expr LOG_AND error	{ yyerror("bad expression"); }
2070
+		| rval_expr LOG_OR error	{ yyerror("bad expression"); }
2058 2071
 		;
2059 2072
 
2060 2073
 assign_action: lval assign_op  rval_expr	{ $$=mk_action($2, 2, LVAL_ST, $1, 
... ...
@@ -2498,12 +2511,13 @@ cmd:
2498 2498
 		}
2499 2499
 		$$ = mod_func_action;
2500 2500
 	}
2501
+	| ID error					{ yyerror("'('')' expected (function call)");}
2501 2502
 	;
2502 2503
 func_params:
2503 2504
 	/* empty */
2504 2505
 	| func_params COMMA func_param { }
2505 2506
 	| func_param {}
2506
-	| func_params error { yyerror("call params error\n"); YYABORT; }
2507
+	| func_params error { yyerror("call params error\n"); }
2507 2508
 	;
2508 2509
 func_param:
2509 2510
         NUMBER {
... ...
@@ -2532,17 +2546,32 @@ func_param:
2532 2532
 extern int line;
2533 2533
 extern int column;
2534 2534
 extern int startcolumn;
2535
+extern int startline;
2536
+
2535 2537
 static void warn(char* s)
2536 2538
 {
2537
-	LOG(L_WARN, "cfg. warning: (%d,%d-%d): %s\n", line, startcolumn,
2538
-			column, s);
2539
+	if (line!=startline)
2540
+		LOG(L_WARN, "cfg. warning: (%d,%d-%d,%d): %s\n",
2541
+					startline, startcolumn, line, column-1, s);
2542
+	else if (startcolumn!=(column-1))
2543
+		LOG(L_WARN, "cfg. warning: (%d,%d-%d): %s\n", startline, startcolumn,
2544
+					column-1, s);
2545
+	else
2546
+		LOG(L_WARN, "cfg. warning: (%d,%d): %s\n", startline, startcolumn, s);
2539 2547
 	cfg_warnings++;
2540 2548
 }
2541 2549
 
2542 2550
 static void yyerror(char* s)
2543 2551
 {
2544
-	LOG(L_CRIT, "*** PARSE ERROR *** (%d,%d-%d): %s\n", line, startcolumn,
2545
-			column, s);
2552
+	if (line!=startline)
2553
+		LOG(L_CRIT, "*** PARSE ERROR *** (%d,%d-%d,%d): %s\n", 
2554
+					startline, startcolumn, line, column-1, s);
2555
+	else if (startcolumn!=(column-1))
2556
+		LOG(L_CRIT, "*** PARSE ERROR *** (%d,%d-%d): %s\n", 
2557
+					startline, startcolumn, column-1, s);
2558
+	else
2559
+		LOG(L_CRIT, "*** PARSE ERROR *** (%d,%d): %s\n", 
2560
+					startline, startcolumn, s);
2546 2561
 	cfg_errors++;
2547 2562
 }
2548 2563