1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-02-09 13:23:51 +02:00

Support SystemVerilog DPI and DPI-C import statements

Ref: Section "35.5.4 Import declarations" from SystemVerilog standard
IEEE 1800-2017.
This commit is contained in:
Kaushal Modi 2019-02-28 17:17:41 -05:00 committed by Alec Thomas
parent e10834d052
commit c67f8fee79
3 changed files with 47 additions and 0 deletions

View File

@ -18,6 +18,7 @@ var Systemverilog = internal.Register(MustNewLexer(
"root": {
{"^\\s*`define", CommentPreproc, Push("macro")},
{`^(\s*)(package)(\s+)`, ByGroups(Text, KeywordNamespace, Text), nil},
{`^(\s*)(import)(\s+)("DPI(?:-C)?")(\s+)`, ByGroups(Text, KeywordNamespace, Text, LiteralString, Text), nil},
{`^(\s*)(import)(\s+)`, ByGroups(Text, KeywordNamespace, Text), Push("import")},
{`\n`, Text, nil},
{`\s+`, Text, nil},

11
lexers/testdata/systemverilog.actual vendored Normal file
View File

@ -0,0 +1,11 @@
// Comment
program top;
import "DPI-C" hello=task hello();
initial begin
hello();
end
endprogram : top

35
lexers/testdata/systemverilog.expected vendored Normal file
View File

@ -0,0 +1,35 @@
[
{"type":"CommentSingle","value":"// Comment\n"},
{"type":"Text","value":"\n"},
{"type":"Keyword","value":"program"},
{"type":"Text","value":" "},
{"type":"Name","value":"top"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n\n "},
{"type":"KeywordNamespace","value":"import"},
{"type":"Text","value":" "},
{"type":"LiteralString","value":"\"DPI-C\""},
{"type":"Text","value":" "},
{"type":"Name","value":"hello"},
{"type":"Operator","value":"="},
{"type":"Keyword","value":"task"},
{"type":"Text","value":" "},
{"type":"Name","value":"hello"},
{"type":"Punctuation","value":"();"},
{"type":"Text","value":"\n\n "},
{"type":"Keyword","value":"initial"},
{"type":"Text","value":" "},
{"type":"Keyword","value":"begin"},
{"type":"Text","value":"\n "},
{"type":"Name","value":"hello"},
{"type":"Punctuation","value":"();"},
{"type":"Text","value":"\n "},
{"type":"Keyword","value":"end"},
{"type":"Text","value":"\n\n"},
{"type":"Keyword","value":"endprogram"},
{"type":"Text","value":" "},
{"type":"Operator","value":":"},
{"type":"Text","value":" "},
{"type":"Name","value":"top"},
{"type":"Text","value":"\n"}
]