: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
})(function(CodeMirror) {
CodeMirror.defineMode("verilog", function(config, parserConfig) {
var indentUnit = config.indentUnit,
statementIndentUnit = parserConfig.statementIndentUnit || indentUnit,
dontAlignCalls = parserConfig.dontAlignCalls,
noIndentKeywords = parserConfig.noIndentKeywords || [],
multiLineStrings = parserConfig.multiLineStrings,
hooks = parserConfig.hooks || {};
var obj = {}, words = str.split(" ");
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
* Keywords from IEEE 1800-2012
"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 endspecify endsequence 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 implements implies import " +
"incdir include initial inout input inside instance int integer interconnect interface intersect join join_any " +
"join_none large let liblist library local localparam logic longint macromodule matches medium modport module " +
"nand negedge nettype 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 soft 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");
/** Operators from IEEE 1800-2012
+ | - | ! | ~ | & | ~& | | | ~| | ^ | ~^ | ^~
+ | - | * | / | % | == | != | === | !== | ==? | !=? | && | || | **
| < | <= | > | >= | & | | | ^ | ^~ | ~^ | >> | << | >>> | <<<
inc_or_dec_operator ::= ++ | --
unary_module_path_operator ::=
! | ~ | & | ~& | | | ~| | ^ | ~^ | ^~
binary_module_path_operator ::=
== | != | && | || | & | | | ^ | ^~ | ~^
var isOperatorChar = /[\+\-\*\/!~&|^%=?:]/;
var isBracketChar = /[\[\]{}()]/;
var unsignedNumber = /\d[0-9_]*/;
var decimalLiteral = /\d*\s*'s?d\s*\d[0-9_]*/i;
var binaryLiteral = /\d*\s*'s?b\s*[xz01][xz01_]*/i;
var octLiteral = /\d*\s*'s?o\s*[xz0-7][xz0-7_]*/i;
var hexLiteral = /\d*\s*'s?h\s*[0-9a-fxz?][0-9a-fxz?_]*/i;
var realLiteral = /(\d[\d_]*(\.\d[\d_]*)?E-?[\d_]+)|(\d[\d_]*\.\d[\d_]*)/i;
var closingBracketOrWord = /^((\w+)|[)}\]])/;
var closingBracket = /[)}\]]/;
// Block openings which are closed by a matching keyword in the form of ("end" + keyword)
// E.g. "task" => "endtask"
var blockKeywords = words(
"case checker class clocking config function generate interface module package" +
"primitive program property specify sequence table task"
for (var keyword in blockKeywords) {
openClose[keyword] = "end" + keyword;
openClose["begin"] = "end";
openClose["casex"] = "endcase";
openClose["casez"] = "endcase";
openClose["do" ] = "while";
openClose["fork" ] = "join;join_any;join_none";
openClose["covergroup"] = "endgroup";
for (var i in noIndentKeywords) {
var keyword = noIndentKeywords[i];
if (openClose[keyword]) {
openClose[keyword] = undefined;
// Keywords which open statements that are ended with a semi-colon
var statementKeywords = words("always always_comb always_ff always_latch assert assign assume else export for foreach forever if import initial repeat while");
function tokenBase(stream, state) {
var ch = stream.peek(), style;
if (hooks[ch] && (style = hooks[ch](stream, state)) != false) return style;
if (hooks.tokenBase && (style = hooks.tokenBase(stream, state)) != false)
if (/[,;:\.]/.test(ch)) {
if (isBracketChar.test(ch)) {
if (stream.eatWhile(/[\w\$_]/)) {
if (stream.eatWhile(/[\w\$_]/)) {
stream.eatWhile(/[\d_.]/);
state.tokenize = tokenString(ch);
return state.tokenize(stream, state);
state.tokenize = tokenComment;
return tokenComment(stream, state);
if (stream.match(realLiteral) ||
stream.match(decimalLiteral) ||
stream.match(binaryLiteral) ||
stream.match(octLiteral) ||
stream.match(hexLiteral) ||
stream.match(unsignedNumber) ||
stream.match(realLiteral)) {
if (stream.eatWhile(isOperatorChar)) {
// Keywords / plain variables
if (stream.eatWhile(/[\w\$_]/)) {
var cur = stream.current();
if (statementKeywords[cur]) {
curPunc = "newstatement";
function tokenString(quote) {
return function(stream, state) {
var escaped = false, next, end = false;
while ((next = stream.next()) != null) {
if (next == quote && !escaped) {end = true; break;}
escaped = !escaped && next == "\\";
if (end || !(escaped || multiLineStrings))
state.tokenize = tokenBase;
function tokenComment(stream, state) {
var maybeEnd = false, ch;
while (ch = stream.next()) {
if (ch == "/" && maybeEnd) {
state.tokenize = tokenBase;
function Context(indented, column, type, align, prev) {
this.indented = indented;
function pushContext(state, col, type) {
var indent = state.indented;
var c = new Context(indent, col, type, null, state.context);
return state.context = c;
function popContext(state) {
var t = state.context.type;
if (t == ")" || t == "]" || t == "}") {
state.indented = state.context.indented;
return state.context = state.context.prev;
function isClosing(text, contextClosing) {
if (text == contextClosing) {
// contextClosing may be multiple keywords separated by ;
var closingKeywords = contextClosing.split(";");
for (var i in closingKeywords) {
if (text == closingKeywords[i]) {
function buildElectricInputRegEx() {
// Reindentation should occur on any bracket char: {}()[]
// or on a match of any of the block closing keywords, at
for (var i in openClose) {
var closings = openClose[i].split(";");
for (var j in closings) {
allClosings.push(closings[j]);
var re = new RegExp("[{}()\\[\\]]|(" + allClosings.join("|") + ")$");
// Regex to force current line to reindent
electricInput: buildElectricInputRegEx(),
startState: function(basecolumn) {
context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
if (hooks.startState) hooks.startState(state);
token: function(stream, state) {
if (ctx.align == null) ctx.align = false;
state.indented = stream.indentation();
state.startOfLine = true;
if (hooks.token) hooks.token(stream, state);
if (stream.eatSpace()) return null;
var style = (state.tokenize || tokenBase)(stream, state);
if (style == "comment" || style == "meta" || style == "variable") return style;
if (ctx.align == null) ctx.align = true;
if (curPunc == ctx.type) {
} else if ((curPunc == ";" && ctx.type == "statement") ||
(ctx.type && isClosing(curKeyword, ctx.type))) {
while (ctx && ctx.type == "statement") ctx = popContext(state);
} else if (curPunc == "{") {
pushContext(state, stream.column(), "}");
} else if (curPunc == "[") {
pushContext(state, stream.column(), "]");
} else if (curPunc == "(") {
pushContext(state, stream.column(), ")");
} else if (ctx && ctx.type == "endcase" && curPunc == ":") {
pushContext(state, stream.column(), "statement");
} else if (curPunc == "newstatement") {
pushContext(state, stream.column(), "statement");
} else if (curPunc == "newblock") {
if (curKeyword == "function" && ctx && (ctx.type == "statement" || ctx.type == "endgroup")) {
// The 'function' keyword can appear in some other contexts where it actually does not
// indicate a function (import/export DPI and covergroup definitions).
// Do nothing in this case
} else if (curKeyword == "task" && ctx && ctx.type == "statement") {
var close = openClose[curKeyword];
pushContext(state, stream.column(), close);
state.startOfLine = false;
indent: function(state, textAfter) {
if (state.tokenize != tokenBase && state.tokenize != null) return CodeMirror.Pass;
var fromHook = hooks.indent(state);
if (fromHook >= 0) return fromHook;
var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
var possibleClosing = textAfter.match(closingBracketOrWord);
closing = isClosing(possibleClosing[0], ctx.type);
if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit);
else if (closingBracket.test(ctx.type) && ctx.align && !dontAlignCalls) return ctx.column + (closing ? 0 : 1);
else if (ctx.type == ")" && !closing) return ctx.indented + statementIndentUnit;
else return ctx.indented + (closing ? 0 : indentUnit);
CodeMirror.defineMIME("text/x-verilog", {
CodeMirror.defineMIME("text/x-systemverilog", {
var tlvchScopePrefixes = {
">": "property", "->": "property", "-": "hr", "|": "link", "?$": "qualifier", "?*": "qualifier",
"@-": "variable-3", "@": "variable-3", "?": "qualifier"
function tlvGenIndent(stream, state) {
var rtnIndent = -1, indentUnitRq = 0, curIndent = stream.indentation();
switch (state.tlvCurCtlFlowChar) {
if (state.tlvPrevPrevCtlFlowChar == "@") {
indentUnitRq = -2; //-2 new pipe rq after cur pipe
if (tlvchScopePrefixes[state.tlvPrevCtlFlowChar])
indentUnitRq = 1; // +1 new scope
if (state.tlvPrevPrevCtlFlowChar == "@") {
indentUnitRq = -2; //-2 new inst rq after pipe
if (tlvchScopePrefixes[state.tlvPrevCtlFlowChar])
indentUnitRq = 1; // +1 new scope
if (state.tlvPrevCtlFlowChar == "S")
indentUnitRq = -1; // new pipe stage after stmts
if (state.tlvPrevCtlFlowChar == "|")
indentUnitRq = 1; // 1st pipe stage
if (state.tlvPrevCtlFlowChar == "@")
indentUnitRq = 1; // flow in pipe stage
if (tlvchScopePrefixes[state.tlvPrevCtlFlowChar])
indentUnitRq = 1; // +1 new scope
var statementIndentUnit = tlvindentUnit;
rtnIndent = curIndent + (indentUnitRq*statementIndentUnit);
return rtnIndent >= 0 ? rtnIndent : curIndent;
CodeMirror.defineMIME("text/x-tlv", {
"\\": function(stream, state) {
var vxIndent = 0, style = false;
var curPunc = stream.string;
if ((stream.sol()) && ((/\\SV/.test(stream.string)) || (/\\TLV/.test(stream.string)))) {
curPunc = (/\\TLV_version/.test(stream.string))
? "\\TLV_version" : stream.string;
if (curPunc == "\\SV" && state.vxCodeActive) {state.vxCodeActive = false;};
if ((/\\TLV/.test(curPunc) && !state.vxCodeActive)
|| (curPunc=="\\TLV_version" && state.vxCodeActive)) {state.vxCodeActive = true;};
state.tlvCurCtlFlowChar = state.tlvPrevPrevCtlFlowChar
= state.tlvPrevCtlFlowChar = "";
if (state.vxCodeActive == true) {
state.tlvCurCtlFlowChar = "\\";
vxIndent = tlvGenIndent(stream, state);
state.vxIndentRq = vxIndent;
tokenBase: function(stream, state) {
var vxIndent = 0, style = false;
var tlvisOperatorChar = /[\[\]=:]/;
var tlvkpScopePrefixs = {
"**":"variable-2", "*":"variable-2", "$$":"variable", "$":"variable",
"^^":"attribute", "^":"attribute"};
var vxCurCtlFlowCharValueAtStart = state.tlvCurCtlFlowChar;
if (state.vxCodeActive == true) {
if (/[\[\]{}\(\);\:]/.test(ch)) {
// bypass nesting and 1 char punc
state.tlvCurCtlFlowChar = "S";
style = tlvchScopePrefixes[ch];
state.tlvCurCtlFlowChar = "@";
stream.eatWhile(/[\w\$_]/);
} else if (stream.match(/\b[mM]4+/, true)) { // match: function(pattern, consume, caseInsensitive)
state.tlvCurCtlFlowChar = "M";
} else if (ch == "!" && stream.sol()) {
// state.tlvCurCtlFlowChar = "S";
} else if (tlvisOperatorChar.test(ch)) {
stream.eatWhile(tlvisOperatorChar);
state.tlvCurCtlFlowChar = (state.tlvCurCtlFlowChar == "")
? ch : state.tlvCurCtlFlowChar;
stream.eatWhile(/[+-]\d/);
} else if (tlvkpScopePrefixs.propertyIsEnumerable(ch)) {