1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-26 07:54:06 +02:00

b2/: introduce unit pattern (##), for dimensionless values

This commit is contained in:
Werner Almesberger 2012-06-03 09:50:21 -03:00
parent e93ff0e683
commit cc895fe7fc
2 changed files with 9 additions and 5 deletions

View File

@ -48,7 +48,7 @@ static char *canonicalize(const char *s, char unit)
return stralloc(s);
res = stralloc("");
while (*s) {
if (*s == unit) {
if (*s == unit && unit != '#') {
assert(!seen_unit);
if (!s[1])
break;
@ -82,7 +82,8 @@ static char *canonicalize(const char *s, char unit)
res_len--;
if (mult)
append_char(&res, &res_len, mult);
append_char(&res, &res_len, unit);
if (unit != '#')
append_char(&res, &res_len, unit);
return res;
}

View File

@ -55,9 +55,11 @@ static struct subst *alloc_subst(enum subst_type type)
static void unit_expr(char **res, int *res_len, char unit)
{
append(res, res_len, "(-?[0-9]+\\.?[0-9]*[" MULT_CHARS "]?");
append_char(res, res_len, unit);
if (unit != '#')
append_char(res, res_len, unit);
append(res, res_len, "?|-?[0-9]+[");
append_char(res, res_len, unit);
if (unit != '#')
append_char(res, res_len, unit);
append(res, res_len, MULT_CHARS "][0-9]*)");
}
@ -90,7 +92,8 @@ static char *prepare_re(const char *re, char *units)
case '(':
parens++;
if (re[1] == '#' && re[2]) {
if ((!isalpha(re[2]) && re[2] != '%') ||
if ((!isalpha(re[2]) &&
re[2] != '%' && re[2] != '#') ||
re[3] != ')')
yyerrorf("invalid (#unit) syntax");
units[parens-1] = re[2];