nano-devel
[Top][All Lists]
Advanced

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

Re: [Nano-devel] ruby syntax highlight patterns REDUX


From: John M. Gabriele
Subject: Re: [Nano-devel] ruby syntax highlight patterns REDUX
Date: Fri, 26 May 2006 22:36:11 -0700 (PDT)


--- "John M. Gabriele" <address@hidden> wrote:

> [snip] Here's a first try -- [snip]

I'd forgotten a few keywords, and also backticks (i.e. "shell
commands"). Fixed "Symbols". Also changed the colors just a bit
to be more palatable. The only critical thing to fix now is to
get the comment highlighting not to interfere with expression
substitution inside double-quoted strings.

Here's what we've got so far:

--------------------------- snip ---------------------------

## Here is an example for Ruby.
syntax "ruby" "\.rb$"

## Asciibetical list of reserved words.
color yellow
"\<(__FILE__|__LINE__|BEGIN|END|alias|and|begin|break|case|class)\>"
color yellow
"\<(def|defined\?|do|else|elsif|end|ensure|false|for|if|in|module)\>"
color yellow
"\<(next|nil|not|or|redo|rescue|retry|return|self|super|then|true)\>"
color yellow "\<(undef|unless|until|when|while|yield)\>"

## Shell command expansion is in `backticks` or like %x{this}.
color brightblue "`[^`]*`"
color brightblue "%x\{[^}]*\}"

## Strings, double-quoted.
color green ""[^"]*""
color green "%[QW]?\{[^}]*\}"

# Strings, single-quoted.
color green "'[^']*'"
color green "%[qw]\{[^}]*\}"

## Expression substitution. These are for inside double-quoted strings. "Like
#{this}."
## Really, this one should *only* be for inside "", %{}, %Q{}, %W{}, or ``. XXX
color brightgreen "#\{[^}]*\}"

## Symbols.
color magenta ":[a-zA-Z0-9_]+\>"

## Regular expressions.
## Whoops. These shouldn't highlight inside strings. XXX
color red "/[^/]*/[iomx]*"
color red "%r\{[^}]*\}[iomx]*"

## Comments.
## How do I make this work everywhere *except* inside a string? XXX
color cyan "#.*$"

## Some common markers.
color brightcyan "(XXX|TODO|FIXME)"

--------------------------- snip ---------------------------

I'm learning that it's not as easy as it looks to write syntax
highlighting patterns. Besides getting patterns to work everywhere
except where they're not supposed to work (like regexes /inside/
strings), there's also this: My bet is that the programmer gets used
to the highlighting being right and tends to leans on it. If you
color something to look like correct syntax which is actually incorrect
syntax, my guess is that it could hide some pretty nasty bugs.

---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]