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); } ;