Ruby syntax highlighting for Ruby

  • Thread starter Josef 'Jupp' SCHUGT
  • Start date
J

Josef 'Jupp' SCHUGT

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
 
J

Josef 'Jupp' SCHUGT

Hi!

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

Josef 'Jupp' Schugt
 
C

Chris Pine

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: (e-mail address removed) Web: http://www.nano-editor.org/
Compiled
options: --disable-justify --enable-color --enable-multibuffer --enable-nano
rc
 
J

Josef 'Jupp' SCHUGT

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
 
D

denis

Josef 'Jupp' SCHUGT said:
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+"
 
J

Josef 'Jupp' SCHUGT

Hi!

* denis:
Josef 'Jupp' SCHUGT said:
[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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top