Nano syntax highlighting malformed regex?

0

I found this javascript syntax highlighting file for nano on google code, downloaded it and included it in my /etc/nanorc file:

File: /usr/share/nano/js.nanorc

## all *js files  ( e.g. Firefox user.js, prefs.js )
## Old version
#syntax "jsfiles" "(\.|/|)js$"
#color green "//.*$" start="\/\*" end="\*\/"
#color blue "'(\\.|[^'])*'"
#color red ""(\\.|[^\"])*""
#color brightgreen "\<(true)\>"
#color brightred "\<(false)\>" "http\:\/\/.*$"
#color brightmagenta "[0-9](\\.|[^\"])*)"
## New updated taken from http://wiki.linuxhelp.net/index.php/Nano_Syntax_Highlighting
syntax "JavaScript" "\.(js)$"
## Default
color white "^.+$"
## Decimal, octal and hexadecimal numbers
color yellow "\<[-+]?([1-9][0-9]*|0[0-7]*|0x[0-9a-fA-F]+)([uU][lL]?|[lL][uU]?)?\>"
## Floating point number with at least one digit before decimal point
color yellow "\<[-+]?([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([EePp][+-]?[0-9]+)?[fFlL]?"
color yellow "\<[-+]?([0-9]+[EePp][+-]?[0-9]+)[fFlL]?"
## Keywords
color green "\<(break|case|catch|continue|default|delete|do|else|finally)\>"
color green "\<(for|function|if|in|instanceof|new|null|return|switch)\>"
color green "\<(switch|this|throw|try|typeof|undefined|var|void|while|with)\>"
## Type specifiers
color red "\<(Array|Boolean|Date|Enumerator|Error|Function|Math)\>"
color red "\<(Number|Object|RegExp|String)\>"
color red "\<(true|false)\>"
## String
color brightyellow "L?\"(\\"|[^"])*\""
color brightyellow "L?'(\'|[^'])*'"
## Escapes
color red "\\[0-7][0-7]?[0-7]?|\\x[0-9a-fA-F]+|\\[bfnrt'\"\?\\]"
## Comments
color magenta start="/\*" end="\*/"
color magenta "//.*$"

However, now whenever I open any file using nano I am told there are errors. This line is printed for each and every line in the file which has a regular expression on it:

Error in /usr/share/nano/js.nanorc on line 11: Regex strings must begin and end with a " character

I am still able to open any file, and syntax highlighting still works for other filetypes, but there is no javascript highlighting.

Can anybody help me out here? I am very new to nano (and linux in general, really), but I can't see a problem with any of those regular expressions... they all begin and end with "s.

Luke

Posted 2013-03-18T17:25:01.010

Reputation: 281

Answers

2

An edge-case but possible scenario:

If using Cygwin on Windows, ensure the line endings are Unix style (\n) as opposed to Windows style (\r\n). I encountered this exact issue, and this is the only link I found even on the StackExchange sites. It may be an edge case, but it leads to this exact problem

sloosecannon

Posted 2013-03-18T17:25:01.010

Reputation: 121

this fixed the issue Regex strings must begin and end with a " character – Phate01 – 2019-12-12T17:50:29.487

0

In general, you could do the "divide and conquer" route. Make a copy of the file. Remove half, try the config. If the syntax has an error, it's in the half that's in the file - repeat (remove half). If not, it's in the half that you deleted. Use the half that you split out, and remove half from that, until you get to one line that's bad.

I don't know the file format, but my guess would be the line

#color red ""(\\.|[^\"])*""

It starts with ", then a " right away, closing it, then regex in between. Im guessing you need to escape the inner quotes:

#color red "\"(\\.|[^\"])*\""

Rich Homolka

Posted 2013-03-18T17:25:01.010

Reputation: 27 121

According to the error messages, every single regex string is in error. I get the same message for lines 11,13,15,17,18,20,21,22,24,25,26,28,29,31,33,34. The ones at the top are commented out anyway. – Luke – 2013-03-18T17:55:13.160