nano-devel
[Top][All Lists]
Advanced

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

Re: [Nano-devel] ruby syntax highlighting patterns


From: David Lawrence Ramsey
Subject: Re: [Nano-devel] ruby syntax highlighting patterns
Date: Mon, 22 May 2006 13:28:52 -0400
User-agent: Thunderbird 1.5.0.2 (X11/20060420)

John M. Gabriele wrote:

<snip>

> Here's some common-looking Ruby snippets which don't highlight
> correctly with those patterns:
>
> title.gsub( /"/, "&quot;" )

Thanks for the feedback.  I've made a new version.  See attached.

The problem here is the unescaped quote, which is treated as part of a
string.

> # Only works with one (and only one) letter appended. Regexes
> # can have more than one trailing modifier letter.
> some_regex = %r{^abc$}

Fixed as far as I can tell.

> # Not sure why this one doesn't work:
> CodeEscapeRegexp = %r{( \* | _ | \{ | \} | \[ | \] | \\ )}x

Fixed as far as I can tell.

> foo = lambda {|char| "&#%03d;" % char}

Fixed as far as I can tell.

> return %{<a href="%s">%s</a>} % [ rval, rval.sub(/.+?:/, '') ]

The problem here is the unescaped quote, which is treated as part of a
string.

> text += %{>#{link}</a>}

The problem here is the unescaped }, which is treated as the end of the
string as well as the end of the expression substitution.

The problems with the regexes here occur occasionally with the "nanorc"
regex intended to highlight bad commands, and would occur with the
"c-file" regexes if C accepted unescaped quotes inside strings. Unfortunately, I'm not sure how to fix them properly, but at least
things should be better than they were.

## Here is an example for Ruby.
##
syntax "ruby" "\.rb$"
## General
color white ".+"
## Operators
color brightyellow 
"::|\*\*|!|~|\*|/|%|\+|-|&|<<|>>|\|\^|>|>=|<|<=|<=>|\|\||!=|=~|!~|&&|\+=|-=|=|\.\.|\.\.\.|\<not\>|\<and\>|\<or\>"
## Keywords
color brightyellow 
"\<(BEGIN|END|alias|and|begin|break|case|class|def|defined|do|else|elsif|end|ensure|for|if|in|module|next|not|or|redo|rescue|retry|return|self|super|then|undef|unless|until|when|while|yield)\>"
## false, nil, true
color magenta "\<(false|nil|true)\>"
## Above must not match 'nil?'
color white "\<nil\?"
## External stuff
color brightgreen "\<(load|require|%!|%Q|%q|%r|%x)"
## Iterators
icolor brightgreen "\|[0-9A-Z_]*\|"
## Constants
color yellow "\<[A-Z][0-9A-Za-z_]*\>"
## Symbols
icolor yellow "([        ]|^):(@|@@|\$)?[0-9A-Z_]+\>"
## Strings
color green ""(\\.|[^"])*"|'(\\.|[^'])*'"
icolor green "%[QW]?\{(\\.|[^}])*\}" "%[QW]?\((\\.|[^)])*\)"
## Backticks
color green "`(\\.|[^\\"])*`" "%x\{[^}]*\}"
## Regular expressions
color green "/(\\.|[^\\/])*/[imox]*" "%r\{(\\.|[^}])*\}[imox]*"
## Escapes
color red "\\["'abefnrst\\]" "'\\(([0-3]?[0-7]{1,2}))'" "'\\x[0-9A-Fa-f]{1,2}'" 
"(\\c|\\C-|\\M-|\\M-\\C-)."
## Expression substitution
icolor red "#\{[^}]*\}|#(@|@@|\$)[0-9A-Z_]+"
## Simple comments
color cyan "^#([^{].*)?$"
## Shebang
color brightcyan "^#!.*"
## Multiline comments
color cyan start="^=begin" end="^=end"

reply via email to

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