nano-devel
[Top][All Lists]
Advanced

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

[Nano-devel] ruby syntax highlighting patterns


From: John M. Gabriele
Subject: [Nano-devel] ruby syntax highlighting patterns
Date: Sat, 20 May 2006 15:10:05 -0700 (PDT)

I found some Ruby syntax highlighting patterns in the ruby-talk archives:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/93305

With the small corrections noted here
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/93453 , and some of
my own additions (noted below) including changing the first line to just
"\.rb$", the patterns are:

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

#####################################################################
# Ruby syntax highlighting for Nano.
# Author:  Josef 'Jupp' Schugt, jupp(a)rubyforge.org
# License: GPL 2  or later
# Version: 0.1 of 2004-02-20
#####################################################################

# Automatically use for '.rb' files
syntax "ruby" "\.rb$"

# General
color white ".+"

# Operators
color brightyellow "::|\*\*|!|~|\*|/|%|\+|-|&|<<|>>|\|\^|>|>=|<|<="
color brightyellow "<=>|\|\||!=|=~|!~|&&|\+=|-=|=|\.\.|\.\.\."
color brightyellow "\<not\>|\<and\>|\<or\>"

# Keywords
color brightyellow "\<(BEGIN|END|alias|and|begin|break|case)\>"
color brightyellow "\<(class|def|defined|do|else|elsif|end)\>"
color brightyellow "\<(ensure|for|if|in|module|next|not|or|redo)\>"
color brightyellow "\<(rescue|retry|return|self|super|then|undef)\>"
color brightyellow "\<(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
color brightgreen "\|\w*\|"

# Constants
color yellow "\<[A-Z]\w*\>"

# Symbols
color yellow "([ \t]|^):(@|@@|\$)?\w+\>"

# Strings
color green "\"(\\.|[^\\\"])*\"|'(\\.|[^\\'])*'"
color green "%\{[^}]*\}"
color green "%(q|Q)\{[^}]*\}"
color green "%(w|W)\{[^}]*\}"
color green "%(w|W)\([^}]*\)"

# Backticks
color green "`(\\.|[^\\\"])*`"
color green "%x\{[^}]*\}"

# Regular expressions
color green "/(\\.|[^\\/])*/[imox]*"
color green "%r\{[^}]*\}[imox]"

# Escapes
color red "\\[0-7][0-7][0-7]|\\x[0-9a-fA-F][0-9a-fA-F]"
color red "\\[abefnrs]"
color red "(\\c|\\C-|\\M-|\\M-\\C-)."

# Expression substitution
color red "#\{[^}]*\}|#(@|@@|\$)\w+"

# Simple comments
color cyan         "#([^{].*)?$"

# Shebang
color brightcyan   "^#!.*"

# Multiline comments
color cyan         start="^=begin" end="^=end"

------------------------ /snip ------------------------


These patterns look great in my xterm.

I'd added:
------------------------ /snip ---------------------------

# (Goes with strings.)
color green "%\{[^}]*\}"
color green "%(q|Q)\{[^}]*\}"
color green "%(w|W)\{[^}]*\}"
color green "%(w|W)\([^}]*\)"

# (Goes with backticks.)
color green "%x\{[^}]*\}"

# (Goes with Regular expressions.)
color green "%r\{[^}]*\}[imox]"

------------------------ /snip ---------------------------

but I have to say that there's a lot I still don't know about these regex's.
I'd ask about it here, but don't want to get too far off-topic.

Note: Ruby allows multi-line strings for all the different string syntaxes
(syntaxi? ;) ), but I wasn't sure how to add them. Also, I'm not sure how the
ordering is supposed to go... does nano go through the defined patterns just
once? Does it ever short-circuit-out early? Are the start="" end="" patterns
always supposed to go last? For strings, I was going to try:

color green start="%(q|Q|w|W)(\(|\{)" end="\1\2"

but then, I want the ending ( or { to actually be either ) or },
respectively. How would we do that?

Ruby also has heredocs like Perl, but I see that, in Perl's syntax highlighting
patterns, they seem to only use STOP as the markers...

Does it look like these patterns could go into the sample.nanorc for the 1.4
release? Actually, will the 1.4 release move to using external files for syntax
pattern definitions? This set of Ruby patterns is a little long and might be a
good candidate...

I've emailed the author at the address noted in the above snippet to ask. That
is, I'm guessing that since GNU nano is an official GNU project all copyright
must be assigned to the FSF, but I'm not sure exactly how one does that. Maybe
just an email from Jupp?

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