we also need to allow for places where no value is meaningful
(`Vnone`) and where we don't know what type to expect yet (`Vunknown`
which can be anything and `Vnolabel` which can be anything except a
-label). A 2 character 'tail' is included in each value as the scanner
-wants to parse that from the end of numbers and we need somewhere to
-put it. It is currently ignored but one day might allow for
-e.g. "imaginary" numbers.
+label).
Values are never shared, they are always copied when used, and freed
when no longer needed.
int bool;
void *label;
};
- char tail[2];
};
char *vtype_names[] = {"nolabel", "unknown", "none", "string",
{
struct text tx;
int neg = 0;
+ char tail[3] = "";
+
switch(vl->vtype) {
case Vnolabel:
case Vlabel:
arg++;
}
tx.txt = arg; tx.len = strlen(tx.txt);
- if (number_parse(vl->num, vl->tail, tx) == 0)
+ if (number_parse(vl->num, tail, tx) == 0)
mpq_init(vl->num);
else if (neg)
mpq_neg(vl->num, vl->num);
+ if (tail[0]) {
+ printf("Unsupported suffix: %s\n", arg);
+ return 0;
+ }
break;
case Vbool:
if (strcasecmp(arg, "true") == 0 ||
| NUMBER ${
$0 = new_pos(val, $1);
$0->val.vtype = Vnum;
- if (number_parse($0->val.num, $0->val.tail, $1.txt) == 0)
+ {
+ char tail[3];
+ if (number_parse($0->val.num, tail, $1.txt) == 0)
mpq_init($0->val.num);
- if ($0->val.tail[0])
+ if (tail[0])
tok_err(config2context(config), "error: unsupported number suffix.",
&$1);
+ }
}$
| STRING ${
$0 = new_pos(val, $1);
$0->val.vtype = Vstr;
- string_parse(&$1, '\\', &$0->val.str, $0->val.tail);
- if ($0->val.tail[0])
+ {
+ char tail[3];
+ string_parse(&$1, '\\', &$0->val.str, tail);
+ if (tail[0])
tok_err(config2context(config), "error: unsupported string suffix.",
&$1);
+ }
}$
| MULTI_STRING ${
$0 = new_pos(val, $1);
$0->val.vtype = Vstr;
- string_parse(&$1, '\\', &$0->val.str, $0->val.tail);
- if ($0->val.tail[0])
+ {
+ char tail[3];
+ string_parse(&$1, '\\', &$0->val.str, tail);
+ if (tail[0])
tok_err(config2context(config), "error: unsupported string suffix.",
&$1);
+ }
}$
###### print exec cases