nano-devel
[Top][All Lists]
Advanced

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

Re: [Nano-devel] aggressive C color highlighting


From: John M. Gabriele
Subject: Re: [Nano-devel] aggressive C color highlighting
Date: Thu, 3 Aug 2006 09:09:07 -0700 (PDT)

--- David Lawrence Ramsey <address@hidden> wrote:

> Alexey Toptygin wrote:
> 
> [snip]
> 
>  > The best thing to do, IMO, is to eliminate regions matched by earlier
>  > rules from being tested by later rules. In this case, the simplest:
>  >
>  > color brightblue "//.*"
>  > color brightblue start="/\*" end="\*/"
>  >
>  > will do exactly what we want. In your example, it would match the
>  > first line with the first rule and not test the second rule against
>  > it; the second line would not match, and comment on line 3 would be
>  > handled correctly.
>  >
>  > By letting earlier rules call 'dibs' on regions they've already
>  > matched, we would emulate what the C lexer is doing: if a // comment
>  > starts, the rest of the line is not processed in any way; if a /*
>  > comment starts, no other processing will be done until the first */.
>  > This lets us define complex syntaxes, and handle pathological cases
>  > correctly: the same way that a C (or other) compiler would. In theory,
>  > this could also save nano some effort, since no more tests will need
>  > to be done once the first one matches and the regexes can be simpler.
> 
> Interesting idea.  However, there are some cases where overlaps are
> needed.  How should a regex that allows overlaps be indicated?

I think that overlaps should be allowed only when the outer match totally
encompasses the inner match:

    match1_start       match2_start    match2_end        match1_end
                            \---------------/
         \----------------------------------------------------/

but not when they only partially overlap:

    match1_start       match2_start    match1_end        match2_end
         \----------------------------------/
                             \--------------------------------/

For example, in Ruby, you can have string interpolation work like so:

    foo = 3
    puts "I have #{foo} apples"

(Save that into a foo.rb file to see the syntax highlighting with nano.)

The #{foo} should be (and is) highlighted a different color than the rest of
the contents of the string (here, it's the same color, but bold). However, what
you really want to disallow is when the end of one match overlaps with the
beginning of the next match. For example, again, in Ruby:

    foo = 'This "is" something'
    foo.gsub!( /"/, "*" ) # Replace all double-quote marks asterisks.

The first slash starts a Ruby regular expression (and nano starts a syntax
pattern match) which contains a double quote mark. The double-quote mark then
starts another nano syntax pattern match. Then the next slash ends the first
syntax pattern match, and then the quote before the asterisk ends the 2nd
syntax pattern match.

In situations like those, I don't think you can win with the current nano
syntax highlighting engine. You can change the order of the patterns in the
syntax file, but that just flips which pattern match gets colored first. I
don't know how you'd change the nano syntax highlighting code to disallow
"half" overlapping like that.

---John


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 




reply via email to

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