1 package s
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var Systemverilog = internal.Register(MustNewLazyLexer(
10 &Config{
11 Name: "systemverilog",
12 Aliases: []string{"systemverilog", "sv"},
13 Filenames: []string{"*.sv", "*.svh"},
14 MimeTypes: []string{"text/x-systemverilog"},
15 EnsureNL: true,
16 },
17 systemvarilogRules,
18 ))
19
20 func systemvarilogRules() Rules {
21 return Rules{
22 "root": {
23 {"^\\s*`define", CommentPreproc, Push("macro")},
24 {`^(\s*)(package)(\s+)`, ByGroups(Text, KeywordNamespace, Text), nil},
25 {`^(\s*)(import)(\s+)("DPI(?:-C)?")(\s+)`, ByGroups(Text, KeywordNamespace, Text, LiteralString, Text), nil},
26 {`^(\s*)(import)(\s+)`, ByGroups(Text, KeywordNamespace, Text), Push("import")},
27 {`\n`, Text, nil},
28 {`\s+`, Text, nil},
29 {`\\\n`, Text, nil},
30 {`/(\\\n)?/(\n|(.|\n)*?[^\\]\n)`, CommentSingle, nil},
31 {`/(\\\n)?[*](.|\n)*?[*](\\\n)?/`, CommentMultiline, nil},
32 {`[{}#@]`, Punctuation, nil},
33 {`L?"`, LiteralString, Push("string")},
34 {`L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'`, LiteralStringChar, nil},
35 {`(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?`, LiteralNumberFloat, nil},
36 {`(\d+\.\d*|\.\d+|\d+[fF])[fF]?`, LiteralNumberFloat, nil},
37 {`([0-9]+)|(\'h)[0-9a-fA-F]+`, LiteralNumberHex, nil},
38 {`([0-9]+)|(\'b)[01]+`, LiteralNumberBin, nil},
39 {`([0-9]+)|(\'d)[0-9]+`, LiteralNumberInteger, nil},
40 {`([0-9]+)|(\'o)[0-7]+`, LiteralNumberOct, nil},
41 {`\'[01xz]`, LiteralNumber, nil},
42 {`\d+[Ll]?`, LiteralNumberInteger, nil},
43 {`\*/`, Error, nil},
44 {`[~!%^&*+=|?:<>/-]`, Operator, nil},
45 {`[()\[\],.;\']`, Punctuation, nil},
46 {"`[a-zA-Z_]\\w*", NameConstant, nil},
47 {Words(``, `\b`, `accept_on`, `alias`, `always`, `always_comb`, `always_ff`, `always_latch`, `and`, `assert`, `assign`, `assume`, `automatic`, `before`, `begin`, `bind`, `bins`, `binsof`, `bit`, `break`, `buf`, `bufif0`, `bufif1`, `byte`, `case`, `casex`, `casez`, `cell`, `chandle`, `checker`, `class`, `clocking`, `cmos`, `config`, `const`, `constraint`, `context`, `continue`, `cover`, `covergroup`, `coverpoint`, `cross`, `deassign`, `default`, `defparam`, `design`, `disable`, `dist`, `do`, `edge`, `else`, `end`, `endcase`, `endchecker`, `endclass`, `endclocking`, `endconfig`, `endfunction`, `endgenerate`, `endgroup`, `endinterface`, `endmodule`, `endpackage`, `endprimitive`, `endprogram`, `endproperty`, `endsequence`, `endspecify`, `endtable`, `endtask`, `enum`, `event`, `eventually`, `expect`, `export`, `extends`, `extern`, `final`, `first_match`, `for`, `force`, `foreach`, `forever`, `fork`, `forkjoin`, `function`, `generate`, `genvar`, `global`, `highz0`, `highz1`, `if`, `iff`, `ifnone`, `ignore_bins`, `illegal_bins`, `implies`, `import`, `incdir`, `include`, `initial`, `inout`, `input`, `inside`, `instance`, `int`, `integer`, `interface`, `intersect`, `join`, `join_any`, `join_none`, `large`, `let`, `liblist`, `library`, `local`, `localparam`, `logic`, `longint`, `macromodule`, `matches`, `medium`, `modport`, `module`, `nand`, `negedge`, `new`, `nexttime`, `nmos`, `nor`, `noshowcancelled`, `not`, `notif0`, `notif1`, `null`, `or`, `output`, `package`, `packed`, `parameter`, `pmos`, `posedge`, `primitive`, `priority`, `program`, `property`, `protected`, `pull0`, `pull1`, `pulldown`, `pullup`, `pulsestyle_ondetect`, `pulsestyle_onevent`, `pure`, `rand`, `randc`, `randcase`, `randsequence`, `rcmos`, `real`, `realtime`, `ref`, `reg`, `reject_on`, `release`, `repeat`, `restrict`, `return`, `rnmos`, `rpmos`, `rtran`, `rtranif0`, `rtranif1`, `s_always`, `s_eventually`, `s_nexttime`, `s_until`, `s_until_with`, `scalared`, `sequence`, `shortint`, `shortreal`, `showcancelled`, `signed`, `small`, `solve`, `specify`, `specparam`, `static`, `string`, `strong`, `strong0`, `strong1`, `struct`, `super`, `supply0`, `supply1`, `sync_accept_on`, `sync_reject_on`, `table`, `tagged`, `task`, `this`, `throughout`, `time`, `timeprecision`, `timeunit`, `tran`, `tranif0`, `tranif1`, `tri`, `tri0`, `tri1`, `triand`, `trior`, `trireg`, `type`, `typedef`, `union`, `unique`, `unique0`, `unsigned`, `until`, `until_with`, `untyped`, `use`, `uwire`, `var`, `vectored`, `virtual`, `void`, `wait`, `wait_order`, `wand`, `weak`, `weak0`, `weak1`, `while`, `wildcard`, `wire`, `with`, `within`, `wor`, `xnor`, `xor`), Keyword, nil},
48 {Words(``, `\b`, "`__FILE__", "`__LINE__", "`begin_keywords", "`celldefine", "`default_nettype", "`define", "`else", "`elsif", "`end_keywords", "`endcelldefine", "`endif", "`ifdef", "`ifndef", "`include", "`line", "`nounconnected_drive", "`pragma", "`resetall", "`timescale", "`unconnected_drive", "`undef", "`undefineall"), CommentPreproc, nil},
49 {Words(``, `\b`, `$display`, `$displayb`, `$displayh`, `$displayo`, `$dumpall`, `$dumpfile`, `$dumpflush`, `$dumplimit`, `$dumpoff`, `$dumpon`, `$dumpports`, `$dumpportsall`, `$dumpportsflush`, `$dumpportslimit`, `$dumpportsoff`, `$dumpportson`, `$dumpvars`, `$fclose`, `$fdisplay`, `$fdisplayb`, `$fdisplayh`, `$fdisplayo`, `$feof`, `$ferror`, `$fflush`, `$fgetc`, `$fgets`, `$finish`, `$fmonitor`, `$fmonitorb`, `$fmonitorh`, `$fmonitoro`, `$fopen`, `$fread`, `$fscanf`, `$fseek`, `$fstrobe`, `$fstrobeb`, `$fstrobeh`, `$fstrobeo`, `$ftell`, `$fwrite`, `$fwriteb`, `$fwriteh`, `$fwriteo`, `$monitor`, `$monitorb`, `$monitorh`, `$monitoro`, `$monitoroff`, `$monitoron`, `$plusargs`, `$random`, `$readmemb`, `$readmemh`, `$rewind`, `$sformat`, `$sformatf`, `$sscanf`, `$strobe`, `$strobeb`, `$strobeh`, `$strobeo`, `$swrite`, `$swriteb`, `$swriteh`, `$swriteo`, `$test`, `$ungetc`, `$value$plusargs`, `$write`, `$writeb`, `$writeh`, `$writememb`, `$writememh`, `$writeo`), NameBuiltin, nil},
50 {`(class)(\s+)`, ByGroups(Keyword, Text), Push("classname")},
51 {Words(``, `\b`, `byte`, `shortint`, `int`, `longint`, `integer`, `time`, `bit`, `logic`, `reg`, `supply0`, `supply1`, `tri`, `triand`, `trior`, `tri0`, `tri1`, `trireg`, `uwire`, `wire`, `wand`, `woshortreal`, `real`, `realtime`), KeywordType, nil},
52 {`[a-zA-Z_]\w*:(?!:)`, NameLabel, nil},
53 {`\$?[a-zA-Z_]\w*`, Name, nil},
54 },
55 "classname": {
56 {`[a-zA-Z_]\w*`, NameClass, Pop(1)},
57 },
58 "string": {
59 {`"`, LiteralString, Pop(1)},
60 {`\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})`, LiteralStringEscape, nil},
61 {`[^\\"\n]+`, LiteralString, nil},
62 {`\\\n`, LiteralString, nil},
63 {`\\`, LiteralString, nil},
64 },
65 "macro": {
66 {`[^/\n]+`, CommentPreproc, nil},
67 {`/[*](.|\n)*?[*]/`, CommentMultiline, nil},
68 {`//.*?\n`, CommentSingle, Pop(1)},
69 {`/`, CommentPreproc, nil},
70 {`(?<=\\)\n`, CommentPreproc, nil},
71 {`\n`, CommentPreproc, Pop(1)},
72 },
73 "import": {
74 {`[\w:]+\*?`, NameNamespace, Pop(1)},
75 },
76 }
77 }
78
View as plain text