Skip to content

Commit

Permalink
Support SystemVerilog DPI and DPI-C import statements
Browse files Browse the repository at this point in the history
Ref: Section "35.5.4 Import declarations" from SystemVerilog standard
IEEE 1800-2017.
  • Loading branch information
kaushalmodi authored and alecthomas committed Mar 5, 2019
1 parent e10834d commit c67f8fe
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions lexers/s/systemverilog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
11 changes: 11 additions & 0 deletions lexers/testdata/systemverilog.actual
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Comment

program top;

import "DPI-C" hello=task hello();

initial begin
hello();
end

endprogram : top
35 changes: 35 additions & 0 deletions lexers/testdata/systemverilog.expected
Original file line number Diff line number Diff line change
@@ -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"}
]

0 comments on commit c67f8fe

Please sign in to comment.