This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Alice's profile picture

GNU nano syntax files and improvements

Started by Alice, 03 July 2015 - 09:09 PM
Alice #1
Posted 03 July 2015 - 11:09 PM
So I've been doing a bit of work with GNU nano (commonly just 'nano') and I've actually gotten to writing some syntax highlighting scripts. I'm interested in seeing what everyone else has been able to do with this.
Luasyntax "lua" ".*\.lua$"

## General
color white ".+"

## Statements
color magenta "\<(do|end|while|repeat|until|if|elseif|then|else|for|in|function|local|return)\>"

## Operators
color brightyellow "&amp;|\||:|\*\*|\*|/|%|\+|-|\^|>>|>|>=|<|<=|<<|~|~=|=|\.\.|,|\<(not|and|or)\>"

## Keywords
color brightyellow "\<(debug|string|math|table|io|coroutine|os)\>\.[A-Za-z_][0-9A-Za-z_]*"
color yellow "(_G|_VERSION)"
color brightcyan "[^\.A-Za-z0-9](assert|collectgarbage|dofile|error|getfenv|getmetatable|ipairs|load|loadfile|module|next|pairs|pcall|print|rawequal|rawget|rawset|require|select|setfenv|setmetatable|tonumber|tostring|type|unpack|xpcall) *[\(\"{]"

## Standard library
color brightyellow "io *\. *\<(close|flush|input|lines|open|output|popen|read|tmpfile|type|write)\>"
color brightyellow "math *\. *\<(abs|acos|asin|atan2|atan|ceil|cosh|cos|deg|exp|floor|fmod|frexp|huge|ldexp|log10|log|max|min|modf|pi|pow|rad|random|randomseed|sinh|tan)\>"
color brightyellow "os *\. *\<(clock|date|difftime|execute|exit|getenv|remove|rename|setlocale|time|tmpname)\>"
color brightyellow "package *\. *\<(cpath|loaded|loadlib|path|preload|seeall)\>"
color brightyellow "string *\. *\<(byte|char|dump|find|format|gmatch|gsub|len|lower|match|rep|reverse|sub|upper)\>"
color brightyellow "table *\. *\<(concat|insert|maxn|remove|sort)\>"
color brightyellow "coroutine *\. *\<(create|resume|running|status|wrap|yield)\>"
color brightyellow "debug *\. *\<(debug|getfenv|gethook|getinfo|getlocal|getmetatable|getregistry|getupvalue|setfenv|sethook|setlocal|setmetatable|setupvalue|traceback)\>"

## false, nil, true
color magenta "\<(false|nil|true)\>"

## vararg
color brightmagenta "\.\.\."

## External files
color brightgreen "(\<(dofile|require|include)|%q|%!|%Q|%r|%x)\>"

## Table indexing
color yellow "[A-Za-z_][A-Za-z_0-9]* *[:\.] *[A-Za-z_][A-Za-z_0-9]*"

## Table index calls
color brightgreen "[\.:] *[A-Za-z_][A-Za-z_0-9]* *[\(\"{]"

## File handle methods
color brightred "\: *\<(close|flush|lines|read|seek|setvbuf|write)\>"

## Numbers
color cyan "\<([0-9]+)\>"

## Symbols
color cyan "\(|\)|\[|\]|\{|\}"

## Strings
color brightgreen "\"(\\.|[^\\\"])*\"|'(\\.|[^\\'])*'"

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

## Shebang
color cyan "^#!.*"

## Simple comments
color green "(\-\-[^\[].*$|\-\-\[([^\[].*)?$|–$)"

## Multiline comments
color green start="\-\-\[\[" end="]]?"
HTML## Highlight tags, comments, and DOCTYPE

syntax "html" "\.html$"
color cyan start="<" end=">"
color green start="<!–" end="–>"
color yellow start="<!DOCTYPE" end=">"

## Fix this later?

color red "&amp;[^;[[:space:]]]*;"
MindenCucc #2
Posted 05 July 2015 - 01:49 PM
You can use custom syntax highlighting in nano? I never knew that :P/> I'll have to try this out :D/>
Alice #3
Posted 05 July 2015 - 07:27 PM
You can use custom syntax highlighting in nano? I never knew that :P/> I'll have to try this out :D/>

I didn't until rather recently. Still trying to work it out but it's based on whether you can match a RegExp string. It's a gift that it's that simple but it also makes things difficult, such as HTML syntax coloring.
Alice #4
Posted 06 July 2015 - 04:50 AM
Just to note I now have them put in here and here. If you're on zsh, run the update-nano comand in the dotfiles' bin folder and it'll automatically give you a nanorc file. :D/>