Last active
November 30, 2022 21:47
-
-
Save SamantazFox/4b2b1cf7d9827b9d549093fc5363db8a to your computer and use it in GitHub Desktop.
Crystal syntax highlighting for the nano editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Syntax highlighting for Crystal. | |
syntax crystal "\.cr$" | |
comment "#" | |
tabgives " " | |
# Constants. | |
color brightblue "\<[A-Z]+[0-9A-Z_a-z]*|(\$|@|@@)[0-9A-Z_a-z]+" | |
# Operators | |
color red "(\|\||&[&*+-]?|[!?]|[=!*/+-]=|=>|[><]=?|=(==)?|[*/^+-])" | |
# Reserved keywords (Language) | |
color yellow "\<(require|alias|end)\>" | |
color yellow "\<(true|false|nil)\>" | |
color yellow "\<(abstract|private|module|class|struct|include|extend)\>" | |
color yellow "\<(class_)?(setter|(getter|property)[!?]?)" | |
color yellow "\<(new|self|super|finalize)\>" | |
color yellow "\<((previous_|un)?def|yield|return)\>" | |
color yellow "\<(if|unless|elsif|else)\>" | |
color yellow "\<(case|when|in|then)\>" | |
color yellow "\<(do|while|until|break|next)\>" | |
color yellow "\<(begin|rescue|ensure)\>" | |
# Reserved keywords (Top level namespace & Crystal macros) | |
color yellow "\<(abort|at_exit|caller|exit|loop|main|raise|sleep|spawn)\>" | |
color yellow "\<(gets|puts|read_line|pp?!?|s?printf?)\>" | |
color yellow "\<((host_)?flag[?]|parse_type|(instance_)?sizeof|offsetof|pointerof|typeof)\>" | |
color yellow "\<(compare_versions|debug|env|rand|run|system|timeout_select_action)\>" | |
color yellow "\<(file_exists[?]|read_file[?]?|skip_file)\>" | |
# "do" parameters | |
color red "\|\w+(,\s*\w+)*\|" | |
# Numbers | |
color blue "\b0([xX][A-Fa-f0-9_]+|[bB][01]+|o[0-7]+)(_(u8|u16|u32|u64|i8|i16|i32|i64|f32|f64))?\b" | |
color blue "\b[0-9][0-9_]*(\.[0-9][0-9_]*)?([eE][-+]?[0-9][0-9_]*)?(_(u8|u16|u32|u64|i8|i16|i32|i64|f32|f64))?\b" | |
# Common object methods | |
#color brightcyan "\<()\>" | |
color brightcyan "\<(nil[?]|not_nil!|class|dup|(pretty_)?inspect|parse|responds_to[?]|try)" | |
color brightcyan "\<(each(_(with_index|slice|key|value))?|reject!?|select|(compact_)?map|skip(_while)?|uniq)" | |
color brightcyan "\<(as_[afhius][?]?|as_bool|as_(f32|i64)[?]?|as_nil|as|is_a[?])" | |
color brightcyan "\<(clone|compact!?|delete|dig[?]?|dup|inspect|merge!?|raw|size)" | |
color brightcyan "\<(to_(json|xml|s)|to_[iu](8|16|128)[!?]?|to_[ifu](32|64)?[!?]?|to_big_[dfi])" | |
color brightcyan "\<(delete(_at)?|empty[?]|(starts|ends)_with[?]|reverse!?|split|g?sub)" | |
color brightcyan "\<(abs|ceil|fdiv|floor|round|trunc)\>" | |
# Ruby "symbols". | |
color magenta "([ ]|^):[0-9A-Za-z_]+\>" | |
color magenta "\<([0-9A-Za-z_]+\:)\>" | |
# Some unique things we want to stand out. | |
#color brightyellow "\<(__FILE__|__LINE__)\>" | |
# Regular expressions. | |
color brightmagenta "/([^/]|(\\/))*/[iomx]*" "%r\{([^}]|(\\}))*\}[iomx]*" | |
# Shell command expansion is in `backticks` or like %x{this}. These are | |
# "double-quotish" (to use a perlism). | |
color brightblue "`[^`]*`" "%x\{[^}]*\}" | |
# Strings, double-quoted. | |
color green ""([^"]|(\\"))*"" "%[QW]?\{[^}]*\}" "%[QW]?\([^)]*\)" "%[QW]?<[^>]*>" "%[QW]?\[[^]]*\]" "%[QW]?\$[^$]*\$" "%[QW]?\^[^^]*\^" "%[QW]?![^!]*!" | |
# Expression substitution. These go inside double-quoted strings, "like #{this}". | |
color brightgreen "#\{[^}]*\}" | |
# Strings, single-quoted. | |
color green "'([^']|(\\'))*'" "%[qw]\{[^}]*\}" "%[qw]\([^)]*\)" "%[qw]<[^>]*>" "%[qw]\[[^]]*\]" "%[qw]\$[^$]*\$" "%[qw]\^[^^]*\^" "%[qw]![^!]*!" | |
# Comments. | |
color cyan "#[^{].*" "#$" | |
color brightcyan "##[^{].*" "##$" | |
# "Here" docs. | |
color green start="<<-?'?EOT'?" end="^EOT" | |
# Some common markers. | |
color brightcyan "XXX|TODO|FIXME|\?\?\?" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment