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: Tom Levy
Subject: Re: [Nano-devel] [PATCH] syntax: go: fix bugs in number literal regex
Date: Sun, 18 Feb 2018 22:57:03 +1300

Benno wrote:
>>>     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?\>"

Tom wrote:
>> Doesn't match 09.0 or 09i :(

Benno wrote:
> Hm.  But does anyone _want_ to write things that way?  Wouldn't it
> be more likely that those were typos for 90.0 and 90i?

Tom wrote:
>> 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\>"

Benno wrote:
> Anyone else who has an opinion on this?
>
> Benno

It's been a while and nobody responded. Here is my view:

Valid code should be highlighted correctly, even if it has poor style.
It's not our place to say that "09.0" is an error.

Suppose I'm editing a Go file written by somebody else containing the
following:

    prices := []float64{
        32.50,
        09.00,
        10.80,
    }

It's a bad habit to left-pad with zeroes because it turns int literals
into octal, but these are float literals so the code is valid and
behaves as expected. If nano colours the first and third elements but
not the second, I would think there is a syntax error when there is
none.

>From the perspective of a nano contributor, it helps that the syntax
highlighting rules match the language specification. It is easier to
check for correctness and update the rules when the language changes.

I attached a patch that updates the rules to the version I proposed
earlier:

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

Cheers,
Tom


P.S.1. The regexes in the patch are equivalent to commit a794c331, but
reordered to match the language spec. Like that version, they fail to
match a trailing dot (so the valid float "09." is not highlighted).

P.S.2. The problem of identifying accidental octal integers is a bit
beyond the scope of this discussion, but I would suggest giving octal
literals a different colour (it then becomes important to handle
trailing dots correctly, otherwise the decimal float "010." would be
highlighted as octal).

Attachment: 0001-syntax-go-revert-changes-to-number-literal-regexes.patch
Description: Text Data


reply via email to

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