[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Nano-devel] [PATCH] syntax: go: fix bugs in number literal regex
From: |
Tom Levy |
Subject: |
Re: [Nano-devel] [PATCH] syntax: go: fix bugs in number literal regex |
Date: |
Mon, 8 Jan 2018 19:15:11 +1300 |
> Hmm. Okay. How about this:
>
> color red "\<0([0-7]*|[xX][0-9a-fA-F]+)\>"
> color red "(\<0+|\B)\.[0-9]+([Ee][+-]?[0-9]+)?i?\>"
> color red "\<[1-9][0-9]*(\.[0-9]*)?([Ee][+-]?[0-9]+)?i?\>"
Doesn't match 09.0 or 09i :(
I vote sticking with the old regex from commit a794c331, maybe with a
tiny bit of grouping and reordering to match the spec more closely:
color red "\<([1-9][0-9]*|0[0-7]*|0[xX][0-9A-Fa-f]+)\>"
color red "\<[0-9]+\.[0-9]*([eE][+-]?[0-9]+)?i?\>"
color red "\<[0-9]+[eE][+-]?[0-9]+i?\>"
color red "\B\.[0-9]+([eE][+-]?[0-9]+)?i?\>"
color red "\<[0-9]+i\>"
This matches the spec almost exactly:
rule 1 <=> int_lit = decimal_lit | octal_lit | hex_lit,
rules 2-4 <=> float_lit (with optional "i" for imaginary_lit),
rule 5 <=> the part of imaginary_lit that wasn't merged into rules 2-4.
I also changed the order of uppercase/lowercase letters to match the
spec.
Tom
>> Reference: https://golang.org/ref/spec#Integer_literals