nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Nano-devel] [PATCH] syntax: perl: don't color the character after a


From: Brand Huntsman
Subject: Re: [Nano-devel] [PATCH] syntax: perl: don't color the character after a variable name
Date: Thu, 8 Aug 2019 01:35:10 -0600

On Wed, 7 Aug 2019 19:26:32 +0200
Benno Schulenberg <address@hidden> wrote:

> >>> "[$@%&*]\$?(\^[][A-Z^_?\]|[0-9]+|[A-Za-z_][0-9A-Za-z_]*|[][`~!@#$%&*-=+;:'",.\\|/?()<>])|\{(\^_?[0-9A-Za-z]+|[0-9]+|[A-Za-z_][0-9A-Za-z_]*)\})"
> >>>   
> 
> In the braces fragment, why is an underscore only allowed directly
> after a leading caret?  Because with this rule, variables like
> 
>     %{^CAPTURE_ALL}
>     ${^RE_DEBUG_FLAGS}

The third paragraph says "alphanumeric" which doesn't imply underscore, but 
that same page does list those variables and many more containing underscores.


> are not colored.  So I think the braces fragment can be simplified to:
> 
>     \{(\^?[A-Za-z_][0-9A-Za-z_]*|[0-9]+)\}
> 
> Do you agree?

Yes, but the punctuation set and "\^[][A-Z^_?\]" are also valid inside braces. 
I tested it.

no braces = digits | ident | punct | \^[][A-Z^_?\]
braces = digits | \^?ident | punct | \^[][A-Z^_?\]


> Where does it say, by the way, that Perl variable names cannot start
> with a digit (unless they are all digits)?

From the first paragraph: "they must (begin with a letter or underscore) ... 
and may (contain letters, digits, underscores)"


A new issue: https://perldoc.perl.org/perlref.html#Using-References

That $ after the 5 sigils is probably related to this. The braces can contain 
any valid variable ${$var} and even expressions ${$var{"key"}}. I don't know if 
we should handle any of those cases. Diff-so-fancy uses @{$var} and it looks 
good only highlighting the $var.

And I think *+? apply to variables in regular expressions as if the variable 
was wrapped in parens.

    /^$FOO*$/
    /^($FOO)*$/

The final *$/ is highlighted as a variable. Getting rid of the $ after the 5 
sigils incorrectly only highlights the @$ in @$var. I tried getting rid of it 
anyway so regular expressions are easier to read, but that only made it worse. 
Maybe we shouldn't highlight * sigils?

    /^$FOO*$BAR*-$BAZ*$/




reply via email to

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