Skip to content

Commit 85b37ac

Browse files
dwiklemarijnh
authored andcommitted
[verilog mode] Fixed a few indentation issues
Fixed indentation for covergroups Fixed indentation for import/export statements Better handling of 'function' keyword in other contexts
1 parent b6a1a9d commit 85b37ac

File tree

2 files changed

+50
-11
lines changed

2 files changed

+50
-11
lines changed

mode/verilog/test.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,49 @@
225225
""
226226
);
227227

228-
MT("export_function_does_not_indent",
228+
MT("export_function_one_line_does_not_indent",
229229
"[keyword export] [string \"DPI-C\"] [keyword function] [variable helloFromSV];",
230230
""
231231
);
232232

233-
MT("export_task_does_not_indent",
233+
MT("export_task_one_line_does_not_indent",
234234
"[keyword export] [string \"DPI-C\"] [keyword task] [variable helloFromSV];",
235235
""
236236
);
237237

238+
MT("export_function_two_lines_indents_properly",
239+
"[keyword export]",
240+
" [string \"DPI-C\"] [keyword function] [variable helloFromSV];",
241+
""
242+
);
243+
244+
MT("export_task_two_lines_indents_properly",
245+
"[keyword export]",
246+
" [string \"DPI-C\"] [keyword task] [variable helloFromSV];",
247+
""
248+
);
249+
250+
MT("import_function_one_line_does_not_indent",
251+
"[keyword import] [string \"DPI-C\"] [keyword function] [variable helloFromC];",
252+
""
253+
);
254+
255+
MT("import_task_one_line_does_not_indent",
256+
"[keyword import] [string \"DPI-C\"] [keyword task] [variable helloFromC];",
257+
""
258+
);
259+
260+
MT("import_package_single_line_does_not_indent",
261+
"[keyword import] [variable p]::[variable x];",
262+
"[keyword import] [variable p]::[variable y];",
263+
""
264+
);
265+
266+
MT("covergoup_with_function_indents_properly",
267+
"[keyword covergroup] [variable cg] [keyword with] [keyword function] [variable sample][bracket (][keyword bit] [variable b][bracket )];",
268+
" [variable c] : [keyword coverpoint] [variable c];",
269+
"[keyword endgroup]: [variable cg]",
270+
""
271+
);
238272

239273
})();

mode/verilog/verilog.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ CodeMirror.defineMode("verilog", function(config, parserConfig) {
8080
// Block openings which are closed by a matching keyword in the form of ("end" + keyword)
8181
// E.g. "task" => "endtask"
8282
var blockKeywords = words(
83-
"case checker class clocking config function generate group interface module package" +
83+
"case checker class clocking config function generate interface module package" +
8484
"primitive program property specify sequence table task"
8585
);
8686

@@ -94,11 +94,7 @@ CodeMirror.defineMode("verilog", function(config, parserConfig) {
9494
openClose["casez"] = "endcase";
9595
openClose["do" ] = "while";
9696
openClose["fork" ] = "join;join_any;join_none";
97-
98-
// This is a bit of a hack but will work to not indent after import/epxort statements
99-
// as long as the function/task name is on the same line
100-
openClose["import"] = "function;task";
101-
openClose["export"] = "function;task";
97+
openClose["covergroup"] = "endgroup";
10298

10399
for (var i in noIndentKeywords) {
104100
var keyword = noIndentKeywords[i];
@@ -107,7 +103,8 @@ CodeMirror.defineMode("verilog", function(config, parserConfig) {
107103
}
108104
}
109105

110-
var statementKeywords = words("always always_comb always_ff always_latch assert assign assume else for foreach forever if initial repeat while");
106+
// Keywords which open statements that are ended with a semi-colon
107+
var statementKeywords = words("always always_comb always_ff always_latch assert assign assume else export for foreach forever if import initial repeat while");
111108

112109
function tokenBase(stream, state) {
113110
var ch = stream.peek();
@@ -320,8 +317,16 @@ CodeMirror.defineMode("verilog", function(config, parserConfig) {
320317
else if (curPunc == "newstatement") {
321318
pushContext(state, stream.column(), "statement");
322319
} else if (curPunc == "newblock") {
323-
var close = openClose[curKeyword];
324-
pushContext(state, stream.column(), close);
320+
if (curKeyword == "function" && ctx && (ctx.type == "statement" || ctx.type == "endgroup")) {
321+
// The 'function' keyword can appear in some other contexts where it actually does not
322+
// indicate a function (import/export DPI and covergroup definitions).
323+
// Do nothing in this case
324+
} else if (curKeyword == "task" && ctx && ctx.type == "statement") {
325+
// Same thing for task
326+
} else {
327+
var close = openClose[curKeyword];
328+
pushContext(state, stream.column(), close);
329+
}
325330
}
326331

327332
state.startOfLine = false;

0 commit comments

Comments
 (0)