From ac867f1ec259b144405edcfd148d860f853d2a98 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 12 Nov 2011 18:30:21 -0800 Subject: Eliminate line numbers from the abstract syntax tree representation of the TXR query. * match.c (debuglf, sem_error, file_err, eval_form): Line number argument replaced with the form to which the situation pertains. Location information is pulled from the hash table entry associated with the form. (dest_set, dest_bind, eval_form, vars_to_bindings): Context argument renamed since it isn't a line number. (struct match_line_ctx): spec_lineno member removed. (ml_all, ml_bindings_specline): lineno parameter removed. (LOG_MISMATCH, LOG_MATCH, h_var, h_skip, h_coll, h_parallel, match_line): Pass elem to debuglf instead of line number. as context. (h_trailer, h_eol): define elem for LOG_MISMATCH and LOG_MATCH macros. (h_fun): Pass elem variable to debuglf instead of line number. Body stored as a simple cons cell once again (no line number). (do_output_line): Line number parameter removed. Pass specline to sem_error instead of line number. (do_output): Adjusted for one less parameter in do_output_line. (mf_from_ml): Pass one less parameter to ml_all. Conversion of specline to spec is just a wrapping into a nested list, with no line number. (spec_bind): Linenumber variable parameter removed from macro. Definition simplified. (v_skip): Pass specline to debuglf instead of spec_linenum, which is no longer computed. (v_trailer): Use new definition of specline. Pass first_spec to sem_error instead of spec_linenum. Computation of ff_specline no longer has to skip line number. (v_freeform, v_block, v_accept_fail, v_next, v_parallel, v_gather, v_collect, v_merge, v_bind, hv_trampoline, v_cat, v_output, v_try, v_defex, v_throw, v_deffilter, v_filter, match_funcall): Use new definition of specline. Pass first_spec to sem_error instead of spec_linenum. (v_forget_local): Specline computed differently since there is no linenumber to skip. (h_define): Back to implified representation of function with no extra cell for line number. (v_define, v_fun): Pass first_spec to sem_error instead of spec_linenum. Back to implified representation of function with no extra cell for line number. (match_files): first_spec_item computed differently. Pass first_spec to sem_error instead of spec_linenum. * parser.h (source_loc): Declared. * parser.l (source_loc): New function. * parser.y:x (grammar): Removed line numbers from abstract sytnax tree. A few more places needed the annotation of forms with location info, and a couple of cases of the need to propagate the info was --- parser.y | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) (limited to 'parser.y') diff --git a/parser.y b/parser.y index fd4fae34..117262fb 100644 --- a/parser.y +++ b/parser.y @@ -126,18 +126,17 @@ clauses_opt : clauses { $$ = $1; } | /* empty */ { $$ = nil; } ; -clause : all_clause { $$ = list(num(lineno - 1), $1, nao); } - | some_clause { $$ = list(num(lineno - 1), $1, nao); } - | none_clause { $$ = list(num(lineno - 1), $1, nao); } - | maybe_clause { $$ = list(num(lineno - 1), $1, nao); } - | cases_clause { $$ = list(num(lineno - 1), $1, nao); } - | choose_clause { $$ = list(num(lineno - 1), $1, nao); } - | collect_clause { $$ = list(num(lineno - 1), $1, nao); } - | gather_clause { $$ = list(num(lineno - 1), $1, nao); } - | define_clause { $$ = list(num(lineno - 1), - define_transform($1), nao); } - | try_clause { $$ = list(num(lineno - 1), $1, nao); } - | output_clause { $$ = list(num(lineno - 1), $1, nao); } +clause : all_clause { $$ = list($1, nao); } + | some_clause { $$ = list($1, nao); } + | none_clause { $$ = list($1, nao); } + | maybe_clause { $$ = list($1, nao); } + | cases_clause { $$ = list($1, nao); } + | choose_clause { $$ = list($1, nao); } + | collect_clause { $$ = list($1, nao); } + | gather_clause { $$ = list($1, nao); } + | define_clause { $$ = list(define_transform($1), nao); } + | try_clause { $$ = list($1, nao); } + | output_clause { $$ = list($1, nao); } | line { $$ = $1; } | repeat_clause { $$ = nil; yyerror("repeat outside of output"); } @@ -225,8 +224,10 @@ collect_clause : COLLECT exprs_opt ')' newl | COLLECT exprs_opt ')' newl clauses until_last newl clauses END newl { $$ = list(collect_s, $5, - cons($6, $8), $2, nao); - rl($$, num($1)); } + cons(car($6), $8), + $2, nao); + rl($$, num($1)); + rl($8, cdr($6)); } | COLLECT exprs_opt ')' newl error { $$ = nil; if (yychar == UNTIL || @@ -238,8 +239,8 @@ collect_clause : COLLECT exprs_opt ')' newl lit("collect clause")); } ; -until_last : UNTIL { $$ = until_s; } - | LAST { $$ = last_s; } +until_last : UNTIL { $$ = cons(num($1), until_s); } + | LAST { $$ = cons(num($1), last_s); } ; clause_parts : clauses additional_parts { $$ = cons($1, $2); } @@ -253,12 +254,14 @@ additional_parts : END newl { $$ = nil; } line : elems_opt '\n' { $$ = $1; } ; -elems_opt : elems { $$ = cons(num(lineno - 1), $1); } +elems_opt : elems { $$ = $1; } | { $$ = nil; } ; -elems : elem { $$ = cons($1, nil); } - | elem elems { $$ = cons($1, $2); } +elems : elem { $$ = cons($1, nil); + rl($$, source_loc($1)); } + | elem elems { $$ = cons($1, $2); + rl($$, source_loc($1)); } | rep_elem { $$ = nil; yyerror("rep outside of output"); } ; @@ -280,9 +283,10 @@ elem : TEXT { $$ = rl(string_own($1), num(lineno)); } | COLL exprs_opt ')' elems END { $$ = list(coll_s, $4, nil, $2, nao); rl($$, num($1)); } | COLL exprs_opt ')' elems - until_last elems END { $$ = list(coll_s, $4, cons($5, $6), + until_last elems END { $$ = list(coll_s, $4, cons(car($5), $6), $2, nao); - rl($$, num($1)); } + rl($$, num($1)); + rl($6, cdr($5)); } | COLL error { $$ = nil; yybadtoken(yychar, lit("coll clause")); } | ALL clause_parts_h { $$ = rl(list(all_s, t, $2, nao), num($1)); } @@ -419,7 +423,7 @@ out_clauses : out_clause { $$ = cons($1, nil); } | out_clause out_clauses { $$ = cons($1, $2); } ; -out_clause : repeat_clause { $$ = list(num(lineno - 1), $1, nao); } +out_clause : repeat_clause { $$ = cons($1, nil); } | o_line { $$ = $1; } | all_clause { $$ = nil; yyerror("match clause in output"); } @@ -480,8 +484,7 @@ out_clauses_opt : out_clauses { $$ = $1; } o_line : o_elems_opt '\n' { $$ = $1; } ; -o_elems_opt : o_elems { $$ = cons(num(lineno - 1), - o_elems_transform($1)); } +o_elems_opt : o_elems { $$ = o_elems_transform($1); } | { $$ = nil; } ; -- cgit v1.2.3