From e4377002def89c2991ad9df96ea1cbc6b7a3d282 Mon Sep 17 00:00:00 2001
From: Jorge Juan-Chico <jjchico@gmail.com>
Date: Wed, 6 Jan 2021 20:57:41 +0100
Subject: [PATCH] Add (System)Verilog HDL syntax highlighting

Syntax highlighting definitions for Verilog and SystemVerilog HDLs.

Signed-off-by: Jorge Juan-Chico <jjchico@gmail.com>
---
 syntax/Makefile.am     |   2 +
 syntax/sverilog.nanorc | 155 +++++++++++++++++++++++++++++++++++++++++
 syntax/verilog.nanorc  | 109 +++++++++++++++++++++++++++++
 3 files changed, 266 insertions(+)
 create mode 100644 syntax/sverilog.nanorc
 create mode 100644 syntax/verilog.nanorc

diff --git a/syntax/Makefile.am b/syntax/Makefile.am
index 8d747546..ef6d4c7f 100644
--- a/syntax/Makefile.am
+++ b/syntax/Makefile.am
@@ -33,9 +33,11 @@ pkgdata_DATA =	asm.nanorc \
 		rust.nanorc \
 		sh.nanorc \
 		sql.nanorc \
+		sverilog.nanorc \
 		tcl.nanorc \
 		tex.nanorc \
 		texinfo.nanorc \
+		verilog.nanorc \
 		xml.nanorc
 
 nobase_pkgdata_DATA = \
diff --git a/syntax/sverilog.nanorc b/syntax/sverilog.nanorc
new file mode 100644
index 00000000..eece8825
--- /dev/null
+++ b/syntax/sverilog.nanorc
@@ -0,0 +1,155 @@
+## Syntax highlighting for SystemVerilog files.
+
+# Based on IEEE Std 1800-2017
+# 2021 Jorge Juan-Chico <jjchico@gmail.com>
+# This code is in the public domain
+
+# Note: if used with plain Verilog it will also highlight SystemVerilog-only
+# keywords, system tasks and compiler directives that are not part of the plain
+# Verilog Standard (IEEE Std 1364-2005). In any case, it is good advise not to
+# use SystemVerilog keywords in new Verilog code since Verilog is not a separate
+# standard anymore.
+
+syntax systemverilog "\.[sS][vV][hH]?$"
+comment "//"
+
+# Regular keywords.
+# Keywords in (System)Verilog may be escaped with "\".
+color green "([^\\]\<|^)(accept_on|alias|always|always_comb)\>"
+color green "([^\\]\<|^)(always_ff|always_latch|and|assert|assign)\>"
+color green "([^\\]\<|^)(assume|automatic|before|begin|bind|bins)\>"
+color green "([^\\]\<|^)(binsof|break|buf|bufif0|bufif1|case|casex)\>"
+color green "([^\\]\<|^)(casez|cell|checker|class|clocking|cmos)\>"
+color green "([^\\]\<|^)(config|constraint|context|continue|cover)\>"
+color green "([^\\]\<|^)(covergroup|coverpoint|cross|deassign|default)\>"
+color green "([^\\]\<|^)(defparam|design|disable|dist|do|edge|else)\>"
+color green "([^\\]\<|^)(end|endcase|endchecker|endclass|endclocking)\>"
+color green "([^\\]\<|^)(endconfig|endfunction|endgenerate|endgroup)\>"
+color green "([^\\]\<|^)(endinterface|endmodule|endpackage)\>"
+color green "([^\\]\<|^)(endprimitive|endprogram|endproperty)\>"
+color green "([^\\]\<|^)(endspecify|endsequence|endtable|endtask)\>"
+color green "([^\\]\<|^)(eventually|expect|export|extends|extern|final)\>"
+color green "([^\\]\<|^)(first_match|for|force|foreach|forever|fork)\>"
+color green "([^\\]\<|^)(forkjoin|function|generate|genvar|global)\>"
+color green "([^\\]\<|^)(highz0|highz1|if|iff|ifnone|ignore_bins)\>"
+color green "([^\\]\<|^)(illegal_bins|implements|implies|import|incdir)\>"
+color green "([^\\]\<|^)(include|initial|inout|input|inside|instance)\>"
+color green "([^\\]\<|^)(interconnect|interface|intersect|join)\>"
+color green "([^\\]\<|^)(join_any|join_none|large|let|liblist|library)\>"
+color green "([^\\]\<|^)(local|localparam|macromodule|matches|medium)\>"
+color green "([^\\]\<|^)(modport|module|nand|negedge|nettype|new)\>"
+color green "([^\\]\<|^)(nexttime|nmos|nor|noshowcancelled|not|notif0)\>"
+color green "([^\\]\<|^)(notif1|null|or|output|package|packed)\>"
+color green "([^\\]\<|^)(parameter|pmos|posedge|primitive|priority)\>"
+color green "([^\\]\<|^)(program|property|protected|pull0|pull1)\>"
+color green "([^\\]\<|^)(pulldown|pullup|pulsestyle_ondetect)\>"
+color green "([^\\]\<|^)(pulsestyle_onevent|pure|rand|randc|randcase)\>"
+color green "([^\\]\<|^)(randsequence|rcmos|ref|reject_on|release|repeat)\>"
+color green "([^\\]\<|^)(restrict|return|rnmos|rpmos|rtran|rtranif0)\>"
+color green "([^\\]\<|^)(rtranif1|s_always|s_eventually|s_nexttime)\>"
+color green "([^\\]\<|^)(s_until|s_until_with|scalared|sequence)\>"
+color green "([^\\]\<|^)(showcancelled|small|soft|solve|specify)\>"
+color green "([^\\]\<|^)(specparam|static|strong|strong0|strong1)\>"
+color green "([^\\]\<|^)(struct|super|sync_accept_on|sync_reject_on)\>"
+color green "([^\\]\<|^)(table|tagged|task|this|throughout)\>"
+color green "([^\\]\<|^)(timeprecision|timeunit|tran|tranif0|tranif1)\>"
+color green "([^\\]\<|^)(type|typedef|union|unique|unique0|until)\>"
+color green "([^\\]\<|^)(until_with|untyped|use|vectored|virtual|wait)\>"
+color green "([^\\]\<|^)(wait_order|weak|weak0|weak1|while|wildcard)\>"
+color green "([^\\]\<|^)(with|within|xnor|xor)\>"
+
+# Built-in net type keywords.
+color brightgreen "([^\\]\<|^)(supply0|supply1|tri|tri0|tri1|triand)\>"
+color brightgreen "([^\\]\<|^)(trior|trireg|uwire|wand|wire|wor)\>"
+
+# Built-in var type keywords.
+color brightgreen "([^\\]\<|^)(bit|byte|chandle|const|enum|event|int)\>"
+color brightgreen "([^\\]\<|^)(integer|logic|longint|real|realtime|reg)\>"
+color brightgreen "([^\\]\<|^)(shortint|shortreal|signed|string|time)\>"
+color brightgreen "([^\\]\<|^)(unsigned|var|void)\>"
+
+# Numbers.
+color brightmagenta "(\<[0-9]*|\B)\s*'[sS]?[dD]\s*[0-9_]+\>"
+color brightmagenta "(\<[0-9]*|\B)\s*'[sS]?[bB]\s*[0-1_xXzZ?]+\>"
+color brightmagenta "(\<[0-9]*|\B)\s*'[sS]?[oO]\s*[0-7_xXzZ?]+\>"
+color brightmagenta "(\<[0-9]*|\B)\s*'[sS]?[hH]\s*[0-9a-fA-F_xXzZ?]+\>"
+color brightmagenta "\<[0-9][0-9_]*(\.[0-9][0-9_]*)?([eE]-?[0-9][0-9_]*)?\>"
+color brightmagenta "\B'[01xXzZ]\>"
+
+# Operator characters.
+color cyan "[][~&|^><!=?:{}+*/%()@;.,#-]"
+
+# Generic system tasks and functions.
+color brightcyan "\B\$[a-zA-Z0-9_]+\>"
+
+# Standard system tasks and functions.
+color cyan "\B\$(acos|acosh|asin|asinh|assertcontrol|assertfailoff)\>"
+color cyan "\B\$(assertfailon|assertkill|assertnonvacuouson|assertoff)\>"
+color cyan "\B\$(asserton|assertpassoff|assertpasson|assertvacuousoff)\>"
+color cyan "\B\$(async\$and\$array|async\$and\$plane)\>"
+color cyan "\B\$(async\$nand\$array|async\$nand\$plane)\>"
+color cyan "\B\$(async\$nor\$array|async\$nor\$plane|async\$or\$array)\>"
+color cyan "\B\$(async\$or\$plane|atan|atan2|atanh|bits|bitstoreal)\>"
+color cyan "\B\$(bitstoshortreal|cast|ceil|changed_gclk|changed)\>"
+color cyan "\B\$(changing_gclk|clog2|cos|cosh|countbits|countones)\>"
+color cyan "\B\$(coverage_control|coverage_get_max|coverage_get)\>"
+color cyan "\B\$(coverage_merge|coverage_save|dimensions|display)\>"
+color cyan "\B\$(displayb|displayh|displayo|dist_chi_square)\>"
+color cyan "\B\$(dist_erlang|dist_exponential|dist_normal)\>"
+color cyan "\B\$(dist_poisson|dist_t|dist_uniform|dumpall|dumpfile)\>"
+color cyan "\B\$(dumpflush|dumplimit|dumpoff|dumpon|dumpports)\>"
+color cyan "\B\$(dumpportsall|dumpportsflush|dumpportslimitdumpportsoff)\>"
+color cyan "\B\$(dumpportson|dumpvars|error|error|exit|exp|falling_gclk)\>"
+color cyan "\B\$(fatal|fatal|fclose|fdisplay|fdisplayb|fdisplayh)\>"
+color cyan "\B\$(fdisplayo|fell_gclk|fell|feof|ferror|fflush|fgetc|fgets)\>"
+color cyan "\B\$(finish|floor|fmonitor|fmonitorb|fmonitorh|fmonitoro)\>"
+color cyan "\B\$(fopen|fread|fscanf|fseek|fstrobe|fstrobeb|fstrobeh)\>"
+color cyan "\B\$(fstrobeo|ftell|future_gclk|fwrite|fwriteb|fwriteh)\>"
+color cyan "\B\$(fwriteo|get_coverage|high|hypot|increment|info|info)\>"
+color cyan "\B\$(isunbounded|isunknown|itor|left|ln|load_coverage_db)\>"
+color cyan "\B\$(log10|low|monitor|monitorb|monitorh|monitoro|monitoroff)\>"
+color cyan "\B\$(monitoron|onehot|onehot0|past_gclk|past|pow)\>"
+color cyan "\B\$(printtimescale|q_add|q_exam|q_full|q_initialize)\>"
+color cyan "\B\$(q_remove|random|readmemb|readmemh|realtime|realtobits)\>"
+color cyan "\B\$(rewind|right|rising_gclk|rose_gclk|rose|rtoi|sampled)\>"
+color cyan "\B\$(set_coverage_db_name|sformat|sformatf|shortrealtobits)\>"
+color cyan "\B\$(signed|sin|sinh|size|sqrt|sscanf|stable_gclk|stable)\>"
+color cyan "\B\$(steady_gclk|stime|stop|strobe|strobeb|strobeh|strobeo)\>"
+color cyan "\B\$(swrite|swriteb|swriteh|swriteo|sync\$and\$array)\>"
+color cyan "\B\$(sync\$and\$plane|sync\$nand\$array|sync\$nand\$plane)\>"
+color cyan "\B\$(sync\$nor\$array|sync\$nor\$plane|sync\$or\$array)\>"
+color cyan "\B\$(sync\$or\$plane|systemtan|tanh|test\$plusargs|time)\>"
+color cyan "\B\$(timeformat|typename|ungetc|unpacked_dimensions)\>"
+color cyan "\B\$(unsigned|value\$plusargs|warning|write|writeb|writeh)\>"
+color cyan "\B\$(writememb|writememh|writeo)\>"
+
+# Macros.
+color brightmagenta "\B`[A-Za-z_][0-9A-Za-z_]*\>"
+
+# Strings.
+# SystemVerilog strings can span multiple lines by using a "\" at the end of the
+# line. Here we allow strings to span multiple lines regardless the "\" at the
+# end of the line.
+color brightyellow start=""" end="([^"]|\\")*""
+
+# Generic compiler directives.
+# (we want these after macros)
+color brightcyan "^[[:space:]]*`[A-Za-z_][0-9A-Za-z_]*\>"
+
+# Standard compiler directives.
+color cyan "^[[:space:]]*`(__FILE__|__LINE__|begin_keywords|celldefine)\>"
+color cyan "^[[:space:]]*`(default_nettype|define|else|elsif)\>"
+color cyan "^[[:space:]]*`(end_keywords|endcelldefine|endif|ifdef)\>"
+color cyan "^[[:space:]]*`(ifndef|include|line|nounconnected_drive)\>"
+color cyan "^[[:space:]]*`(pragma|resetall|timescale|unconnected_drive)\>"
+color cyan "^[[:space:]]*`(undef|undefineall)\>"
+
+# Comments.
+color brightblue "//.*"
+color brightblue start="/\*" end="\*/"
+
+# Reminders.
+color brightwhite,yellow "\<(FIXME|TODO|XXX)\>"
+
+# Trailing whitespace.
+color ,green "[[:space:]]+$"
\ No newline at end of file
diff --git a/syntax/verilog.nanorc b/syntax/verilog.nanorc
new file mode 100644
index 00000000..4c702448
--- /dev/null
+++ b/syntax/verilog.nanorc
@@ -0,0 +1,109 @@
+## Syntax highlighting for Verilog files.
+
+# Based on IEEE Std 1364-2005
+# 2021 Jorge Juan-Chico <jjchico@gmail.com>
+# This code is in the public domain
+
+syntax verilog "\.[vV][hH]?$"
+comment "//"
+
+# Regular keywords.
+# Keywords in (System)Verilog may be escaped with "\".
+color green "([^\\]\<|^)(always|and|assign|automatic|begin|buf)\>"
+color green "([^\\]\<|^)(bufif0|bufif1|case|casex|casez|cell|cmos)\>"
+color green "([^\\]\<|^)(config|deassign|default|defparam|design)\>"
+color green "([^\\]\<|^)(disable|edge|else|end|endcase|endconfig)\>"
+color green "([^\\]\<|^)(endfunction|endgenerate|endmodule)\>"
+color green "([^\\]\<|^)(endprimitive|endspecify|endtable|endtask)\>"
+color green "([^\\]\<|^)(event|for|force|forever|fork|function)\>"
+color green "([^\\]\<|^)(generate|genvar|highz0|highz1|if|ifnone)\>"
+color green "([^\\]\<|^)(incdir|include|initial|inout|input|instance)\>"
+color green "([^\\]\<|^)(join|large|liblist|library|localparam)\>"
+color green "([^\\]\<|^)(macromodule|medium|module|nand|negedge|nmos)\>"
+color green "([^\\]\<|^)(nor|noshowcancelled|not|notif0|notif1|or)\>"
+color green "([^\\]\<|^)(output|parameter|pmos|posedge|primitive)\>"
+color green "([^\\]\<|^)(pull0|pull1|pulldown|pullup)\>"
+color green "([^\\]\<|^)(pulsestyle_ondetect|pulsestyle_onevent)\>"
+color green "([^\\]\<|^)(rcmos|release|repeat|rnmos|rpmos|rtran)\>"
+color green "([^\\]\<|^)(rtranif0|rtranif1|scalared|showcancelled)\>"
+color green "([^\\]\<|^)(small|specify|specparam|strong0|strong1)\>"
+color green "([^\\]\<|^)(table|task|tran|tranif0|tranif1|use)\>"
+color green "([^\\]\<|^)(vectored|wait|weak0|weak1|while|xnor|xor)\>"
+
+# Built-in net type keywords.
+color brightgreen "([^\\]\<|^)(supply0|supply1|tri|tri0|tri1|triand)\>"
+color brightgreen "([^\\]\<|^)(trior|trireg|uwire|wand|wire|wor)\>"
+
+# Built-in var type keywords.
+color brightgreen "([^\\]\<|^)(event|integer|real|realtime|reg|signed)\>"
+color brightgreen "([^\\]\<|^)(time|unsigned)\>"
+
+# Numbers.
+color brightmagenta "(\<[0-9]*|\B)\s*'[sS]?[dD]\s*[0-9_]+\>"
+color brightmagenta "(\<[0-9]*|\B)\s*'[sS]?[bB]\s*[0-1_xXzZ?]+\>"
+color brightmagenta "(\<[0-9]*|\B)\s*'[sS]?[oO]\s*[0-7_xXzZ?]+\>"
+color brightmagenta "(\<[0-9]*|\B)\s*'[sS]?[hH]\s*[0-9a-fA-F_xXzZ?]+\>"
+color brightmagenta "\<[0-9][0-9_]*(\.[0-9][0-9_]*)?([eE]-?[0-9][0-9_]*)?\>"
+color brightmagenta "\B'[01xXzZ]\>"
+
+# Operator characters.
+color cyan "[][~&|^><!=?:{}+*/%()@;.,#-]"
+
+# Generic system tasks and functions.
+color brightcyan "\B\$[a-zA-Z0-9_]+\>"
+
+# Standard system tasks and functions.
+color cyan "\B\$(acos|acosh|asin|asinh|async\$and\$array)\>"
+color cyan "\B\$(async\$and\$plane|async\$nand\$array)\>"
+color cyan "\B\$(async\$nand\$plane|async\$nor\$array)\>"
+color cyan "\B\$(async\$nor\$plane|async\$or\$array|async\$or\$plane)\>"
+color cyan "\B\$(atan|atan2|atanh|bitstoreal|ceil|clog2|cos|cosh)\>"
+color cyan "\B\$(display|displayb|displayh|displayo|dist_chi_square)\>"
+color cyan "\B\$(dist_erlang|dist_exponential|dist_normal)\>"
+color cyan "\B\$(dist_poisson|dist_t|dist_uniform|exp|fclose)\>"
+color cyan "\B\$(fdisplay|fdisplayb|fdisplayh|fdisplayo|feof|ferror)\>"
+color cyan "\B\$(fflush|fgetc|fgets|finish|floor|fmonitor|fmonitorb)\>"
+color cyan "\B\$(fmonitorh|fmonitoro|fopen|fread|fscanf|fseek)\>"
+color cyan "\B\$(fstrobe|fstrobeb|fstrobeh|fstrobeo|ftell|fwrite)\>"
+color cyan "\B\$(fwriteb|fwriteh|fwriteo|hypot|itor|ln|log10)\>"
+color cyan "\B\$(monitor|monitorb|monitorh|monitoro|monitoroff)\>"
+color cyan "\B\$(monitoron|pow|printtimescale|q_add|q_exam|q_full)\>"
+color cyan "\B\$(q_initialize|q_remove|random|readmemb|readmemh)\>"
+color cyan "\B\$(realtime|realtobits|rewind|rtoi|sdf_annotate)\>"
+color cyan "\B\$(sformat|signed|sin|sinh|sqrt|sscanf|stime|stop)\>"
+color cyan "\B\$(strobe|strobeb|strobeh|strobeo|swrite|swriteb)\>"
+color cyan "\B\$(swriteh|swriteo|sync\$and\$array|sync\$and\$plane)\>"
+color cyan "\B\$(sync\$nand\$array|sync\$nand\$plane|sync\$nor\$array)\>"
+color cyan "\B\$(sync\$nor\$plane|sync\$or\$array|sync\$or\$plane)\>"
+color cyan "\B\$(tan|tanh|test\$plusargs|time|timeformat|ungetc)\>"
+color cyan "\B\$(unsigned|value\$plusargs|write|writeb|writeh|writeo)\>"
+
+# Macros.
+color brightmagenta "\B`[A-Za-z_][0-9A-Za-z_]*\>"
+
+# Strings.
+# SystemVerilog strings can span multiple lines by using a "\" at the end of the
+# line. Here we allow strings to span multiple lines regardless the "\" at the
+# end of the line.
+color brightyellow start=""" end="([^"]|\\")*""
+
+# Generic compiler directives.
+# (we want these after macros)
+color brightcyan "^[[:space:]]*`[A-Za-z_][0-9A-Za-z_]*\>"
+
+# Standard compiler directives.
+color cyan "^[[:space:]]*`(begin_keywords|celldefine|default_nettype)\>"
+color cyan "^[[:space:]]*`(define|else|elsif|end_keywords)\>"
+color cyan "^[[:space:]]*`(endcelldefine|endif|ifdef|ifndef|include)\>"
+color cyan "^[[:space:]]*`(line|nounconnected_drive|pragma|resetall)\>"
+color cyan "^[[:space:]]*`(timescale|unconnected_drive|undef)\>"
+
+# Comments.
+color brightblue "//.*"
+color brightblue start="/\*" end="\*/"
+
+# Reminders.
+color brightwhite,yellow "\<(FIXME|TODO|XXX)\>"
+
+# Trailing whitespace.
+color ,green "[[:space:]]+$"
\ No newline at end of file
-- 
2.25.1

