1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-22 21:23:10 +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,6 +82,7 @@ static char *canonicalize(const char *s, char unit)
res_len--;
if (mult)
append_char(&res, &res_len, mult);
if (unit != '#')
append_char(&res, &res_len, unit);
return res;
}

View File

@ -55,8 +55,10 @@ 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 "]?");
if (unit != '#')
append_char(res, res_len, unit);
append(res, res_len, "?|-?[0-9]+[");
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];