Ruby syntax highlighting for Ruby

Hi!

Add the following to $HOME/.nanorc for Ruby syntax highlighting in
Nano. Please report any issues - it is a quick and dirty hack.

···

#####################################################################

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 “”(\.|[^\"])"|’(\.|[^\’])’"

Backticks

color green “(\\.|[^\\\"])*

Regular expressions

color green “/(\.|[^\/])/[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"

#####################################################################

For this to be functional Nano must be compiled to read

$HOME/.nanorc and support syntax highlighting.

#####################################################################

Josef ‘Jupp’ SCHUGT

http://oss.erdfunkstelle.de/ruby/ - German comp.lang.ruby FAQ
http://rubyforge.org/users/jupp/ - Ruby projects at Rubyforge

Hi!

Oops :->
Well, a Ruby syntax highlighter in Ruby would be interesting, too.

Josef ‘Jupp’ Schugt

···


http://oss.erdfunkstelle.de/ruby/ - German comp.lang.ruby FAQ
http://rubyforge.org/users/jupp/ - Ruby projects at Rubyforge

Great! Thanks.

I am getting the following errors, though:

Error in /root/.nanorc on line 16: Bad regex
"<=>||||!=|=~|!~|&&|+=|-=|=|..|...": Invalid preceding regular
expression
Press return to continue starting nano

Error in /root/.nanorc on line 59: Bad regex “#{[^}]*}|#(@|@@|$)\w+”:
Invalid content of {}
Press return to continue starting nano

My nano -V gives:

GNU nano version 1.2.2 (compiled 11:27:12, Oct 11 2003)
Email: nano@nano-editor.org Web: http://www.nano-editor.org/
Compiled
options: --disable-justify --enable-color --enable-multibuffer --enable-nano
rc

Hi!

  • Chris Pine:
    [Errors while nano parses syntax highlighting for Ruby]

My nano -V gives:

GNU nano version 1.2.2 (compiled 11:27:12, Oct 11 2003)

Try nano 1.2.3 and report if the problem persists.

Josef ‘Jupp’ SCHUGT

···


E-Mail: .— …- .–. .–. .–.-. --. – -…- .-.-.- -… .
http://oss.erdfunkstelle.de/ruby/ - German comp.lang.ruby FAQ
http://rubyforge.org/users/jupp/ - Ruby projects at Rubyforge

“Josef ‘Jupp’ SCHUGT” jupp@gmx.de wrote in message news:<20040222183456.GB2853@jupp%gmx.de>…

Hi!

  • Chris Pine:
    [Errors while nano parses syntax highlighting for Ruby]

My nano -V gives:

GNU nano version 1.2.2 (compiled 11:27:12, Oct 11 2003)

Try nano 1.2.3 and report if the problem persists.

Josef ‘Jupp’ SCHUGT

There were some missing escape backslashes, here are the regexps that work for
me (nano 1.2.3)

Operators

color brightyellow “::|**|!|~|*|/|%|+|-|&|<<|>>||^|>|>=|<|<=”
color brightyellow “<=>||||!=|=~|!~|&&|+=|-=|=|..|...”
color brightyellow “<not>|<and>|<or>”

Expression substitution

color red “#{[^}]*}|#(@|@@|$)\w+”

Hi!

  • denis:

“Josef ‘Jupp’ SCHUGT” jupp@gmx.de wrote in message news:<20040222183456.GB2853@jupp%gmx.de>…

[Errors while nano parses syntax highlighting for Ruby]

There were some missing escape backslashes, here are the regexps that work for
me (nano 1.2.3)
color brightyellow “<=>||||!=|=~|!~|&&|+=|-=|=|..|...”

The difference is that ‘+=’ has been changed to ‘+=’. Very strange.
My nano should have complained about that - but it didn’t :-<

Expression substitution

color red “#{[^}]*}|#(@|@@|$)\w+”

Here ‘#{[^}]}’ has been replaced by '#{[^}]}’: Again no error
message here 8-|

Josef ‘Jupp’ Schugt

···


E-Mail: .— …- .–. .–. .–.-. --. – -…- .-.-.- -… .
http://oss.erdfunkstelle.de/ruby/ - German comp.lang.ruby FAQ
http://rubyforge.org/users/jupp/ - Ruby projects at Rubyforge