1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-23 01:41:53 +02:00

b2/: make "again" include the match; make "break" pop the stack

This commit is contained in:
Werner Almesberger 2012-05-22 15:29:27 -03:00
parent 2ce2da5c30
commit bb809b0d6c
2 changed files with 23 additions and 9 deletions

View File

@ -2,6 +2,16 @@ FN=DNP { ignore }
FN=X(*) { $=$1 } FN=X(*) { $=$1 }
/* iteration demo */
FOO=abcde
BAR=x /* BAR= wouldn't be syntactically correct. We need a non-empty value */
FOO=(*)(?) {
BAR=$BAR$2
FOO=$1
again FOO
}
BAR=x(*) { $=$1 } /* remove the "x" */
REF=R[0-9]* { REF=R[0-9]* {
T=R T=R
VAL=(#R) { R=$1 } VAL=(#R) { R=$1 }

View File

@ -183,7 +183,8 @@ static int do_match(const char **var, const regex_t *re,
static const struct subst *recurse_sub(const struct subst *sub, static const struct subst *recurse_sub(const struct subst *sub,
const struct param *in, const char *matched_var, const char *matched_val, const struct param *in, const char *matched_var, const char *matched_val,
const regmatch_t *match, const char *units, struct param **out) const regmatch_t *match, const char *units, struct param **out,
enum subst_type *cause)
{ {
const struct subst *jump; const struct subst *jump;
regmatch_t m_tmp[NMATCH]; regmatch_t m_tmp[NMATCH];
@ -200,9 +201,13 @@ static const struct subst *recurse_sub(const struct subst *sub,
in, *out, &val, m_tmp)) in, *out, &val, m_tmp))
break; break;
jump = recurse_sub(sub->u.match.block, in, jump = recurse_sub(sub->u.match.block, in,
var, val, m_tmp, sub->u.match.units, out); var, val, m_tmp, sub->u.match.units, out, cause);
if (jump && jump != sub) if (jump) {
return jump; if (jump != sub)
return jump;
if (*cause == st_again)
continue;
}
break; break;
case st_assign: case st_assign:
tmp = compose(sub->u.assign.pat, in, *out, matched_val, tmp = compose(sub->u.assign.pat, in, *out, matched_val,
@ -217,11 +222,9 @@ static const struct subst *recurse_sub(const struct subst *sub,
case st_ignore: case st_ignore:
return &jump_ignore; return &jump_ignore;
case st_break: case st_break:
sub = sub->u.jump->next;
continue;
case st_again: case st_again:
sub = sub->u.jump->u.match.block; *cause = sub->type;
continue; return sub->u.jump;
default: default:
abort(); abort();
} }
@ -236,6 +239,7 @@ int substitute(const struct subst *sub, const struct param *in,
{ {
int i; int i;
char tmp[4]; char tmp[4];
enum subst_type cause = 0;
if (!fn) { if (!fn) {
fn = unique("FN"); fn = unique("FN");
@ -245,6 +249,6 @@ int substitute(const struct subst *sub, const struct param *in,
} }
} }
*out = NULL; *out = NULL;
return recurse_sub(sub, in, NULL, NULL, NULL, NULL, out) return recurse_sub(sub, in, NULL, NULL, NULL, NULL, out, &cause)
!= &jump_ignore; != &jump_ignore;
} }