nano-devel
[Top][All Lists]
Advanced

[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: Benno Schulenberg
Subject: Re: [Nano-devel] [PATCH] syntax: go: fix bugs in number literal regex
Date: Sat, 6 Jan 2018 18:10:25 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0

Op 04-01-18 om 03:22 schreef Tom Levy:
-color red "\<[0-9]+\.[0-9]*([Ee][+-]?[0-9]+)?i?\>"
-color red "\<[0-9]+[Ee][+-]?[0-9]+i?\>"
-color red "\<[0-9]+i\>"
+color red "\<[0-9]+(\.[0-9]*)?([Ee][+-]?[0-9]+)?i?\>"

The new regex is not equivalent to the old.

Go has an ugly inconsistency with octal literals: a leading 0 denotes
octal only in integer literals. So 010 == 8, but 010.0 == 10.0.

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?\>"

The old regex was careful not to match invalid octal integer literals
such as "09". The new regex isn't careful.

Reference: https://golang.org/ref/spec#Integer_literals

Benno



reply via email to

[Prev in Thread] Current Thread [Next in Thread]