On 11/30/20 6:26 AM, Philippe Mathieu-Daudé wrote:
>          # 'Foo=number' sets an argument field to a constant value
> -        if re.fullmatch(re_C_ident + '=[+-]?[0-9]+', t):
> +        if re.fullmatch(re_C_ident + '=[+-]?(0[bx])?[0-9]+', t):
>              (fname, value) = t.split('=')
> -            value = int(value)
> +            if re.fullmatch('[+-]?0b[0-9]+', value):
> +                base = 2
> +            elif re.fullmatch('[+-]?0x[0-9]+', value):
> +                base = 16
> +            else:
> +                base = 10
> +            value = int(value, base)
>              flds = add_field(lineno, flds, fname, ConstField(value))
>              continue

Well, the regxps are off.  No letters for the hex, and 9 accepted for binary.
I think with the right regexps, just trusting int(value, 0) is good enough.

So maybe something like

  re_C_ident + "=[+-]?([0-9]+|0x[0-9a-fA-F]+|0b[01]+)"


r~

Reply via email to