From 21483995aba924e6d1f3472fc68cf8a3d0ae4959 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 15 Nov 2011 20:15:11 -0800 Subject: * match.c (h_var): when manipulating specline, propagate the source locatio info. (v_skip): Don't use specline for trace messages, because it may be nil. Use the skip spec. * parser.h (rl): Declared. (rlcp): New inline function. * parser.y (rl): Static declaration removed. Function becomes extern. (clause): Propagate location info from clause to clause list backbone. (collect_clause, COLL): Bugfix: car/cdr mixup in location info. (elem): Use rlcp function to abbreviate code. (o_elems_opt, o_elems_opt2, o_elem): Set location info. --- ChangeLog | 18 ++++++++++++++++++ match.c | 24 ++++++++++++++++-------- parser.h | 5 +++++ parser.y | 51 ++++++++++++++++++++++++++++----------------------- 4 files changed, 67 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index c91fae43..ffc7c2a1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2011-11-15 Kaz Kylheku + + * match.c (h_var): when manipulating specline, propagate the + source locatio info. + (v_skip): Don't use specline for trace messages, because + it may be nil. Use the skip spec. + + * parser.h (rl): Declared. + (rlcp): New inline function. + + * parser.y (rl): Static declaration removed. Function becomes + extern. + (clause): Propagate location info from clause to clause list + backbone. + (collect_clause, COLL): Bugfix: car/cdr mixup in location info. + (elem): Use rlcp function to abbreviate code. + (o_elems_opt, o_elems_opt2, o_elem): Set location info. + 2011-11-15 Kaz Kylheku Changing read syntax for character literals, because we are going to diff --git a/match.c b/match.c index 91f8a682..6650bac1 100644 --- a/match.c +++ b/match.c @@ -413,8 +413,9 @@ static val h_var(match_line_ctx c, match_line_ctx *cout) and it must be transformed into ( ...) */ if (pat) { + val loc = source_loc(c.specline); c.specline = cons(cdr(pair), cons(pat, rest(c.specline))); - /* TODO: propagate line number info */ + rl(car(c.specline), loc); } else if (nump(modifier)) { val past = plus(c.pos, modifier); @@ -435,7 +436,9 @@ static val h_var(match_line_ctx c, match_line_ctx *cout) c.pos = past; c.specline = cdr(c.specline); } else { + val loc = source_loc(c.specline); c.specline = cons(cdr(pair), rest(c.specline)); + rl(car(c.specline), loc); } goto repeat; } else if (consp(modifier)) { /* regex variable */ @@ -449,7 +452,9 @@ static val h_var(match_line_ctx c, match_line_ctx *cout) c.pos = past; /* This may have another variable attached */ if (pat) { + val loc = source_loc(c.specline); c.specline = cons(pat, rest(c.specline)); + rl(car(c.specline), loc); goto repeat; } } else if (nump(modifier)) { /* fixed field */ @@ -529,7 +534,9 @@ static val h_var(match_line_ctx c, match_line_ctx *cout) LOG_MATCH("double var regex (second var)", plus(fpos, flen)); c.pos = plus(fpos, flen); if (next_pat) { + val loc = source_loc(c.specline); c.specline = cons(next_pat, rest(c.specline)); + rl(car(c.specline), loc); goto repeat; } } else if (!pair) { @@ -1576,6 +1583,7 @@ static val v_skip(match_files_ctx *c) return cons(c->bindings, cons(c->data, c->data_lineno)); { + val skipspec = first(first(c->spec)); val first_spec = first(specline); val args = rest(first_spec); val max = first(args); @@ -1598,13 +1606,13 @@ static val v_skip(match_files_ctx *c) if (min) { if (reps_min != cmin) { - debuglf(specline, lit("skipped only ~a/~a lines to ~a:~a"), + debuglf(skipspec, lit("skipped only ~a/~a lines to ~a:~a"), num(reps_min), num(cmin), first(c->files), c->data_lineno, nao); uw_block_return(nil, nil); } - debuglf(specline, lit("skipped ~a lines to ~a:~a"), + debuglf(skipspec, lit("skipped ~a lines to ~a:~a"), num(reps_min), first(c->files), c->data_lineno, nao); } @@ -1617,19 +1625,19 @@ static val v_skip(match_files_ctx *c) last_good_result = result; last_good_line = c->data_lineno; } else { - debuglf(specline, lit("skip matched ~a:~a"), first(c->files), + debuglf(skipspec, lit("skip matched ~a:~a"), first(c->files), c->data_lineno, nao); break; } } else { - debuglf(specline, lit("skip didn't match ~a:~a"), + debuglf(skipspec, lit("skip didn't match ~a:~a"), first(c->files), c->data_lineno, nao); } if (!c->data) break; - debuglf(specline, lit("skip didn't match ~a:~a"), first(c->files), + debuglf(skipspec, lit("skip didn't match ~a:~a"), first(c->files), c->data_lineno, nao); c->data = rest(c->data); @@ -1641,13 +1649,13 @@ static val v_skip(match_files_ctx *c) if (result) return result; if (last_good_result) { - debuglf(specline, lit("greedy skip matched ~a:~a"), + debuglf(skipspec, lit("greedy skip matched ~a:~a"), first(c->files), last_good_line, nao); return last_good_result; } } - debuglf(specline, lit("skip failed"), nao); + debuglf(skipspec, lit("skip failed"), nao); return nil; } } diff --git a/parser.h b/parser.h index 754282d5..101acba7 100644 --- a/parser.h +++ b/parser.h @@ -41,3 +41,8 @@ void end_of_char(void); int yylex(void); void parse_init(void); val source_loc(val form); +val rl(val form, val lineno); +INLINE val rlcp(val to, val from) +{ + return rl(to, source_loc(from)); +} diff --git a/parser.y b/parser.y index 9089004c..d2ebffd7 100644 --- a/parser.y +++ b/parser.y @@ -47,7 +47,6 @@ static val repeat_rep_helper(val sym, val main, val parts); static val o_elems_transform(val output_form); static val define_transform(val define_form); static val lit_char_helper(val litchars); -static val rl(val form, val lineno); static wchar_t char_from_name(wchar_t *name); static val parsed_spec; @@ -121,17 +120,19 @@ clauses_opt : clauses { $$ = $1; } | /* empty */ { $$ = nil; } ; -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); } +clause : all_clause { $$ = list($1, nao); rlcp($$, $1); } + | some_clause { $$ = list($1, nao); rlcp($$, $1); } + | none_clause { $$ = list($1, nao); rlcp($$, $1); } + | maybe_clause { $$ = list($1, nao); rlcp($$, $1); } + | cases_clause { $$ = list($1, nao); rlcp($$, $1); } + | choose_clause { $$ = list($1, nao); rlcp($$, $1); } + | collect_clause { $$ = list($1, nao); rlcp($$, $1); } + | gather_clause { $$ = list($1, nao); rlcp($$, $1); } + | define_clause { $$ = list(define_transform($1), nao); + rlcp(car($$), $1); + rlcp($$, $1); } + | try_clause { $$ = list($1, nao); rlcp($$, $1); } + | output_clause { $$ = list($1, nao); rlcp($$, $1); } | line { $$ = $1; } | repeat_clause { $$ = nil; yyerror("repeat outside of output"); } @@ -219,10 +220,10 @@ collect_clause : COLLECT exprs_opt ')' newl | COLLECT exprs_opt ')' newl clauses until_last newl clauses END newl { $$ = list(collect_s, $5, - cons(car($6), $8), + cons(cdr($6), $8), $2, nao); rl($$, num($1)); - rl($8, cdr($6)); } + rl($8, car($6)); } | COLLECT exprs_opt ')' newl error { $$ = nil; if (yychar == UNTIL || @@ -254,9 +255,9 @@ elems_opt : elems { $$ = $1; } ; elems : elem { $$ = cons($1, nil); - rl($$, source_loc($1)); } + rlcp($$, $1); } | elem elems { $$ = cons($1, $2); - rl($$, source_loc($1)); } + rlcp($$, $1); } | rep_elem { $$ = nil; yyerror("rep outside of output"); } ; @@ -278,10 +279,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(car($5), $6), + until_last elems END { $$ = list(coll_s, $4, cons(cdr($5), $6), $2, nao); rl($$, num($1)); - rl($6, cdr($5)); } + rl($6, car($5)); } | COLL error { $$ = nil; yybadtoken(yychar, lit("coll clause")); } | ALL clause_parts_h { $$ = rl(list(all_s, t, $2, nao), num($1)); } @@ -479,11 +480,13 @@ out_clauses_opt : out_clauses { $$ = $1; } o_line : o_elems_opt '\n' { $$ = $1; } ; -o_elems_opt : o_elems { $$ = o_elems_transform($1); } +o_elems_opt : o_elems { $$ = o_elems_transform($1); + rl($$, num(lineno)); } | { $$ = nil; } ; -o_elems_opt2 : o_elems { $$ = o_elems_transform($1); } +o_elems_opt2 : o_elems { $$ = o_elems_transform($1); + rl($$, num(lineno)); } | { $$ = null_list; } ; @@ -491,8 +494,10 @@ o_elems : o_elem { $$ = cons($1, nil); } | o_elem o_elems { $$ = cons($1, $2); } ; -o_elem : TEXT { $$ = string_own($1); } - | SPACE { $$ = string_own($1); } +o_elem : TEXT { $$ = string_own($1); + rl($$, num(lineno)); } + | SPACE { $$ = string_own($1); + rl($$, num(lineno)); } | o_var { $$ = $1; } | rep_elem { $$ = $1; } ; @@ -842,7 +847,7 @@ static val lit_char_helper(val litchars) return ret; } -static val rl(val form, val lineno) +val rl(val form, val lineno) { sethash(form_to_ln_hash, form, lineno); pushhash(ln_to_forms_hash, lineno, form); -- cgit v1.2.3