@@ -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