From 4f142c1250e56a3ed22ba9a4fa02784a94b5494b Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 22 May 2012 15:57:55 -0300 Subject: [PATCH] b2/: for consistency, make "break/continue $" equivalent to "break/continue" Plus a bit of code simplification. --- b2/SUBST | 4 +++- b2/lang.y | 26 +++++++++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/b2/SUBST b/b2/SUBST index 2a7994f..2a30967 100644 --- a/b2/SUBST +++ b/b2/SUBST @@ -37,7 +37,9 @@ with curly braces: ${foo}, ... input variable (in pattern): $$ -the input variable ($) can also be used as LHS for matches and assignments + +the input variable ($) can also be used as LHS for matches, assignments, and +as break/continue target. Caveat: diff --git a/b2/lang.y b/b2/lang.y index 042da19..721a3d5 100644 --- a/b2/lang.y +++ b/b2/lang.y @@ -67,6 +67,15 @@ static const struct field *top_field(void) } +static struct subst *parse_jump(const char *keyword, const char *target) +{ + if (!strcmp(keyword, "break")) + return subst_break(target); + if (!strcmp(keyword, "continue")) + return subst_continue(target); + yyerrorf("unknown keyword \"%s\"", keyword); +} + %} @@ -607,12 +616,11 @@ block: } | WORD WORD { - if (!strcmp($1, "break")) - $$ = subst_break($2); - else if (!strcmp($1, "continue")) - $$ = subst_continue($2); - else - yyerrorf("unknown keyword \"%s\"", $1); + $$ = parse_jump($1, $2); + } + | WORD '$' + { + $$ = parse_jump($1, NULL); } | WORD { @@ -620,12 +628,8 @@ block: $$ = subst_end(); else if (!strcmp($1, "ignore")) $$ = subst_ignore(); - else if (!strcmp($1, "break")) - $$ = subst_break(NULL); - else if (!strcmp($1, "continue")) - $$ = subst_continue(NULL); else - yyerrorf("unknown keyword \"%s\"", $1); + $$ = parse_jump($1, NULL); } ;