Update
This commit is contained in:
120
public/admin/plugins/codemirror/mode/verilog/index.html
vendored
Normal file
120
public/admin/plugins/codemirror/mode/verilog/index.html
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Verilog/SystemVerilog mode</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="../../addon/edit/matchbrackets.js"></script>
|
||||
<script src="verilog.js"></script>
|
||||
<style>.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
||||
<div id=nav>
|
||||
<a href="https://codemirror.net/5"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../../index.html">Home</a>
|
||||
<li><a href="../../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/codemirror/codemirror5">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a href="../index.html">Language modes</a>
|
||||
<li><a class=active href="#">Verilog/SystemVerilog</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>SystemVerilog mode</h2>
|
||||
|
||||
<div><textarea id="code" name="code">
|
||||
// Literals
|
||||
1'b0
|
||||
1'bx
|
||||
1'bz
|
||||
16'hDC78
|
||||
'hdeadbeef
|
||||
'b0011xxzz
|
||||
1234
|
||||
32'd5678
|
||||
3.4e6
|
||||
-128.7
|
||||
|
||||
// Macro definition
|
||||
`define BUS_WIDTH = 8;
|
||||
|
||||
// Module definition
|
||||
module block(
|
||||
input clk,
|
||||
input rst_n,
|
||||
input [`BUS_WIDTH-1:0] data_in,
|
||||
output [`BUS_WIDTH-1:0] data_out
|
||||
);
|
||||
|
||||
always @(posedge clk or negedge rst_n) begin
|
||||
|
||||
if (~rst_n) begin
|
||||
data_out <= 8'b0;
|
||||
end else begin
|
||||
data_out <= data_in;
|
||||
end
|
||||
|
||||
if (~rst_n)
|
||||
data_out <= 8'b0;
|
||||
else
|
||||
data_out <= data_in;
|
||||
|
||||
if (~rst_n)
|
||||
begin
|
||||
data_out <= 8'b0;
|
||||
end
|
||||
else
|
||||
begin
|
||||
data_out <= data_in;
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
||||
// Class definition
|
||||
class test;
|
||||
|
||||
/**
|
||||
* Sum two integers
|
||||
*/
|
||||
function int sum(int a, int b);
|
||||
int result = a + b;
|
||||
string msg = $sformatf("%d + %d = %d", a, b, result);
|
||||
$display(msg);
|
||||
return result;
|
||||
endfunction
|
||||
|
||||
task delay(int num_cycles);
|
||||
repeat(num_cycles) #1;
|
||||
endtask
|
||||
|
||||
endclass
|
||||
|
||||
</textarea></div>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
matchBrackets: true,
|
||||
mode: {
|
||||
name: "verilog",
|
||||
noIndentKeywords: ["package"]
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<p>
|
||||
Syntax highlighting and indentation for the Verilog and SystemVerilog languages (IEEE 1800).
|
||||
<h2>Configuration options:</h2>
|
||||
<ul>
|
||||
<li><strong>noIndentKeywords</strong> - List of keywords which should not cause indentation to increase. E.g. ["package", "module"]. Default: None</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-verilog</code> and <code>text/x-systemverilog</code>.</p>
|
||||
</article>
|
||||
443
public/admin/plugins/codemirror/mode/verilog/test.js
vendored
Normal file
443
public/admin/plugins/codemirror/mode/verilog/test.js
vendored
Normal file
@@ -0,0 +1,443 @@
|
||||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: https://codemirror.net/5/LICENSE
|
||||
|
||||
(function() {
|
||||
var mode = CodeMirror.getMode({indentUnit: 4}, "verilog");
|
||||
function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
|
||||
|
||||
MT("binary_literals",
|
||||
"[number 1'b0]",
|
||||
"[number 1'b1]",
|
||||
"[number 1'bx]",
|
||||
"[number 1'bz]",
|
||||
"[number 1'bX]",
|
||||
"[number 1'bZ]",
|
||||
"[number 1'B0]",
|
||||
"[number 1'B1]",
|
||||
"[number 1'Bx]",
|
||||
"[number 1'Bz]",
|
||||
"[number 1'BX]",
|
||||
"[number 1'BZ]",
|
||||
"[number 1'b0]",
|
||||
"[number 1'b1]",
|
||||
"[number 2'b01]",
|
||||
"[number 2'bxz]",
|
||||
"[number 2'b11]",
|
||||
"[number 2'b10]",
|
||||
"[number 2'b1Z]",
|
||||
"[number 12'b0101_0101_0101]",
|
||||
"[number 1'b 0]",
|
||||
"[number 'b0101]"
|
||||
);
|
||||
|
||||
MT("octal_literals",
|
||||
"[number 3'o7]",
|
||||
"[number 3'O7]",
|
||||
"[number 3'so7]",
|
||||
"[number 3'SO7]"
|
||||
);
|
||||
|
||||
MT("decimal_literals",
|
||||
"[number 0]",
|
||||
"[number 1]",
|
||||
"[number 7]",
|
||||
"[number 123_456]",
|
||||
"[number 'd33]",
|
||||
"[number 8'd255]",
|
||||
"[number 8'D255]",
|
||||
"[number 8'sd255]",
|
||||
"[number 8'SD255]",
|
||||
"[number 32'd123]",
|
||||
"[number 32 'd123]",
|
||||
"[number 32 'd 123]"
|
||||
);
|
||||
|
||||
MT("hex_literals",
|
||||
"[number 4'h0]",
|
||||
"[number 4'ha]",
|
||||
"[number 4'hF]",
|
||||
"[number 4'hx]",
|
||||
"[number 4'hz]",
|
||||
"[number 4'hX]",
|
||||
"[number 4'hZ]",
|
||||
"[number 32'hdc78]",
|
||||
"[number 32'hDC78]",
|
||||
"[number 32 'hDC78]",
|
||||
"[number 32'h DC78]",
|
||||
"[number 32 'h DC78]",
|
||||
"[number 32'h44x7]",
|
||||
"[number 32'hFFF?]"
|
||||
);
|
||||
|
||||
MT("real_number_literals",
|
||||
"[number 1.2]",
|
||||
"[number 0.1]",
|
||||
"[number 2394.26331]",
|
||||
"[number 1.2E12]",
|
||||
"[number 1.2e12]",
|
||||
"[number 1.30e-2]",
|
||||
"[number 0.1e-0]",
|
||||
"[number 23E10]",
|
||||
"[number 29E-2]",
|
||||
"[number 236.123_763_e-12]"
|
||||
);
|
||||
|
||||
MT("operators",
|
||||
"[meta ^]"
|
||||
);
|
||||
|
||||
MT("keywords",
|
||||
"[keyword logic]",
|
||||
"[keyword logic] [variable foo]",
|
||||
"[keyword reg] [variable abc]"
|
||||
);
|
||||
|
||||
MT("variables",
|
||||
"[variable _leading_underscore]",
|
||||
"[variable _if]",
|
||||
"[number 12] [variable foo]",
|
||||
"[variable foo] [number 14]"
|
||||
);
|
||||
|
||||
MT("tick_defines",
|
||||
"[def `FOO]",
|
||||
"[def `foo]",
|
||||
"[def `FOO_bar]"
|
||||
);
|
||||
|
||||
MT("system_calls",
|
||||
"[meta $display]",
|
||||
"[meta $vpi_printf]"
|
||||
);
|
||||
|
||||
MT("line_comment", "[comment // Hello world]");
|
||||
|
||||
// Alignment tests
|
||||
MT("align_port_map_style1",
|
||||
/**
|
||||
* mod mod(.a(a),
|
||||
* .b(b)
|
||||
* );
|
||||
*/
|
||||
"[variable mod] [variable mod][bracket (].[variable a][bracket (][variable a][bracket )],",
|
||||
" .[variable b][bracket (][variable b][bracket )]",
|
||||
" [bracket )];",
|
||||
""
|
||||
);
|
||||
|
||||
MT("align_port_map_style2",
|
||||
/**
|
||||
* mod mod(
|
||||
* .a(a),
|
||||
* .b(b)
|
||||
* );
|
||||
*/
|
||||
"[variable mod] [variable mod][bracket (]",
|
||||
" .[variable a][bracket (][variable a][bracket )],",
|
||||
" .[variable b][bracket (][variable b][bracket )]",
|
||||
"[bracket )];",
|
||||
""
|
||||
);
|
||||
|
||||
MT("align_assignments",
|
||||
/**
|
||||
* always @(posedge clk) begin
|
||||
* if (rst)
|
||||
* data_out <= 8'b0 +
|
||||
* 8'b1;
|
||||
* else
|
||||
* data_out = 8'b0 +
|
||||
* 8'b1;
|
||||
* data_out =
|
||||
* 8'b0 + 8'b1;
|
||||
* end
|
||||
*/
|
||||
"[keyword always] [def @][bracket (][keyword posedge] [variable clk][bracket )] [keyword begin]",
|
||||
" [keyword if] [bracket (][variable rst][bracket )]",
|
||||
" [variable data_out] [meta <=] [number 8'b0] [meta +]",
|
||||
" [number 8'b1];",
|
||||
" [keyword else]",
|
||||
" [variable data_out] [meta =] [number 8'b0] [meta +]",
|
||||
" [number 8'b1];",
|
||||
" [variable data_out] [meta =] [number 8'b0] [meta +]",
|
||||
" [number 8'b1];",
|
||||
"[keyword end]",
|
||||
""
|
||||
);
|
||||
|
||||
// Indentation tests
|
||||
MT("indent_single_statement_if",
|
||||
"[keyword if] [bracket (][variable foo][bracket )]",
|
||||
" [keyword break];",
|
||||
""
|
||||
);
|
||||
|
||||
MT("no_indent_after_single_line_if",
|
||||
"[keyword if] [bracket (][variable foo][bracket )] [keyword break];",
|
||||
""
|
||||
);
|
||||
|
||||
MT("indent_after_if_begin_same_line",
|
||||
"[keyword if] [bracket (][variable foo][bracket )] [keyword begin]",
|
||||
" [keyword break];",
|
||||
" [keyword break];",
|
||||
"[keyword end]",
|
||||
""
|
||||
);
|
||||
|
||||
MT("indent_after_if_begin_next_line",
|
||||
"[keyword if] [bracket (][variable foo][bracket )]",
|
||||
" [keyword begin]",
|
||||
" [keyword break];",
|
||||
" [keyword break];",
|
||||
" [keyword end]",
|
||||
""
|
||||
);
|
||||
|
||||
MT("indent_single_statement_if_else",
|
||||
"[keyword if] [bracket (][variable foo][bracket )]",
|
||||
" [keyword break];",
|
||||
"[keyword else]",
|
||||
" [keyword break];",
|
||||
""
|
||||
);
|
||||
|
||||
MT("indent_if_else_begin_same_line",
|
||||
"[keyword if] [bracket (][variable foo][bracket )] [keyword begin]",
|
||||
" [keyword break];",
|
||||
" [keyword break];",
|
||||
"[keyword end] [keyword else] [keyword begin]",
|
||||
" [keyword break];",
|
||||
" [keyword break];",
|
||||
"[keyword end]",
|
||||
""
|
||||
);
|
||||
|
||||
MT("indent_if_else_begin_next_line",
|
||||
"[keyword if] [bracket (][variable foo][bracket )]",
|
||||
" [keyword begin]",
|
||||
" [keyword break];",
|
||||
" [keyword break];",
|
||||
" [keyword end]",
|
||||
"[keyword else]",
|
||||
" [keyword begin]",
|
||||
" [keyword break];",
|
||||
" [keyword break];",
|
||||
" [keyword end]",
|
||||
""
|
||||
);
|
||||
|
||||
MT("indent_if_nested_without_begin",
|
||||
"[keyword if] [bracket (][variable foo][bracket )]",
|
||||
" [keyword if] [bracket (][variable foo][bracket )]",
|
||||
" [keyword if] [bracket (][variable foo][bracket )]",
|
||||
" [keyword break];",
|
||||
""
|
||||
);
|
||||
|
||||
MT("indent_case",
|
||||
"[keyword case] [bracket (][variable state][bracket )]",
|
||||
" [variable FOO]:",
|
||||
" [keyword break];",
|
||||
" [variable BAR]:",
|
||||
" [keyword break];",
|
||||
"[keyword endcase]",
|
||||
""
|
||||
);
|
||||
|
||||
MT("unindent_after_end_with_preceding_text",
|
||||
"[keyword begin]",
|
||||
" [keyword break]; [keyword end]",
|
||||
""
|
||||
);
|
||||
|
||||
MT("export_function_one_line_does_not_indent",
|
||||
"[keyword export] [string \"DPI-C\"] [keyword function] [variable helloFromSV];",
|
||||
""
|
||||
);
|
||||
|
||||
MT("export_task_one_line_does_not_indent",
|
||||
"[keyword export] [string \"DPI-C\"] [keyword task] [variable helloFromSV];",
|
||||
""
|
||||
);
|
||||
|
||||
MT("export_function_two_lines_indents_properly",
|
||||
"[keyword export]",
|
||||
" [string \"DPI-C\"] [keyword function] [variable helloFromSV];",
|
||||
""
|
||||
);
|
||||
|
||||
MT("export_task_two_lines_indents_properly",
|
||||
"[keyword export]",
|
||||
" [string \"DPI-C\"] [keyword task] [variable helloFromSV];",
|
||||
""
|
||||
);
|
||||
|
||||
MT("import_function_one_line_does_not_indent",
|
||||
"[keyword import] [string \"DPI-C\"] [keyword function] [variable helloFromC];",
|
||||
""
|
||||
);
|
||||
|
||||
MT("import_task_one_line_does_not_indent",
|
||||
"[keyword import] [string \"DPI-C\"] [keyword task] [variable helloFromC];",
|
||||
""
|
||||
);
|
||||
|
||||
MT("import_package_single_line_does_not_indent",
|
||||
"[keyword import] [variable p]::[variable x];",
|
||||
"[keyword import] [variable p]::[variable y];",
|
||||
""
|
||||
);
|
||||
|
||||
MT("covergroup_with_function_indents_properly",
|
||||
"[keyword covergroup] [variable cg] [keyword with] [keyword function] [variable sample][bracket (][keyword bit] [variable b][bracket )];",
|
||||
" [variable c] : [keyword coverpoint] [variable c];",
|
||||
"[keyword endgroup]: [variable cg]",
|
||||
""
|
||||
);
|
||||
|
||||
MT("indent_uvm_macros",
|
||||
/**
|
||||
* `uvm_object_utils_begin(foo)
|
||||
* `uvm_field_event(foo, UVM_ALL_ON)
|
||||
* `uvm_object_utils_end
|
||||
*/
|
||||
"[def `uvm_object_utils_begin][bracket (][variable foo][bracket )]",
|
||||
" [def `uvm_field_event][bracket (][variable foo], [variable UVM_ALL_ON][bracket )]",
|
||||
"[def `uvm_object_utils_end]",
|
||||
""
|
||||
);
|
||||
|
||||
MT("indent_uvm_macros2",
|
||||
/**
|
||||
* `uvm_do_with(mem_read,{
|
||||
* bar_nb == 0;
|
||||
* })
|
||||
*/
|
||||
"[def `uvm_do_with][bracket (][variable mem_read],[bracket {]",
|
||||
" [variable bar_nb] [meta ==] [number 0];",
|
||||
"[bracket })]",
|
||||
""
|
||||
);
|
||||
|
||||
MT("indent_wait_disable_fork",
|
||||
/**
|
||||
* virtual task body();
|
||||
* repeat (20) begin
|
||||
* fork
|
||||
* `uvm_create_on(t,p_seq)
|
||||
* join_none
|
||||
* end
|
||||
* wait fork;
|
||||
* disable fork;
|
||||
* endtask : body
|
||||
*/
|
||||
"[keyword virtual] [keyword task] [variable body][bracket ()];",
|
||||
" [keyword repeat] [bracket (][number 20][bracket )] [keyword begin]",
|
||||
" [keyword fork]",
|
||||
" [def `uvm_create_on][bracket (][variable t],[variable p_seq][bracket )]",
|
||||
" [keyword join_none]",
|
||||
" [keyword end]",
|
||||
" [keyword wait] [keyword fork];",
|
||||
" [keyword disable] [keyword fork];",
|
||||
"[keyword endtask] : [variable body]",
|
||||
""
|
||||
);
|
||||
|
||||
MT("indent_typedef_class",
|
||||
/**
|
||||
* typedef class asdf;
|
||||
* typedef p p_t[];
|
||||
* typedef enum {
|
||||
* ASDF
|
||||
* } t;
|
||||
*/
|
||||
"[keyword typedef] [keyword class] [variable asdf];",
|
||||
"[keyword typedef] [variable p] [variable p_t][bracket [[]]];",
|
||||
"[keyword typedef] [keyword enum] [bracket {]",
|
||||
" [variable ASDF]",
|
||||
"[bracket }] [variable t];",
|
||||
""
|
||||
);
|
||||
|
||||
MT("indent_case_with_macro",
|
||||
/**
|
||||
* // It should be assumed that Macros can have ';' inside, or 'begin'/'end' blocks.
|
||||
* // As such, 'case' statement should indent correctly with macros inside.
|
||||
* case(foo)
|
||||
* ASDF : this.foo = seqNum;
|
||||
* ABCD : `update(f)
|
||||
* EFGH : `update(g)
|
||||
* endcase
|
||||
*/
|
||||
"[keyword case][bracket (][variable foo][bracket )]",
|
||||
" [variable ASDF] : [keyword this].[variable foo] [meta =] [variable seqNum];",
|
||||
" [variable ABCD] : [def `update][bracket (][variable f][bracket )]",
|
||||
" [variable EFGH] : [def `update][bracket (][variable g][bracket )]",
|
||||
"[keyword endcase]",
|
||||
""
|
||||
);
|
||||
|
||||
MT("indent_extern_function",
|
||||
/**
|
||||
* extern virtual function void do(ref packet trans);
|
||||
* extern virtual function void do2(ref packet trans);
|
||||
*/
|
||||
"[keyword extern] [keyword virtual] [keyword function] [keyword void] [variable do1][bracket (][keyword ref] [variable packet] [variable trans][bracket )];",
|
||||
"[keyword extern] [keyword virtual] [keyword function] [keyword void] [variable do2][bracket (][keyword ref] [variable packet] [variable trans][bracket )];",
|
||||
""
|
||||
);
|
||||
|
||||
MT("indent_assignment",
|
||||
/**
|
||||
* for (int i=1;i < fun;i++) begin
|
||||
* foo = 2 << asdf || 11'h35 >> abcd
|
||||
* && 8'h6 | 1'b1;
|
||||
* end
|
||||
*/
|
||||
"[keyword for] [bracket (][keyword int] [variable i][meta =][number 1];[variable i] [meta <] [variable fun];[variable i][meta ++][bracket )] [keyword begin]",
|
||||
" [variable foo] [meta =] [number 2] [meta <<] [variable asdf] [meta ||] [number 11'h35] [meta >>] [variable abcd]",
|
||||
" [meta &&] [number 8'h6] [meta |] [number 1'b1];",
|
||||
"[keyword end]",
|
||||
""
|
||||
);
|
||||
|
||||
MT("indent_foreach_constraint",
|
||||
/**
|
||||
* `uvm_rand_send_with(wrTlp, {
|
||||
* length ==1;
|
||||
* foreach (Data[i]) {
|
||||
* payload[i] == Data[i];
|
||||
* }
|
||||
* })
|
||||
*/
|
||||
"[def `uvm_rand_send_with][bracket (][variable wrTlp], [bracket {]",
|
||||
" [variable length] [meta ==][number 1];",
|
||||
" [keyword foreach] [bracket (][variable Data][bracket [[][variable i][bracket ]])] [bracket {]",
|
||||
" [variable payload][bracket [[][variable i][bracket ]]] [meta ==] [variable Data][bracket [[][variable i][bracket ]]];",
|
||||
" [bracket }]",
|
||||
"[bracket })]",
|
||||
""
|
||||
);
|
||||
|
||||
MT("indent_compiler_directives",
|
||||
/**
|
||||
* `ifdef DUT
|
||||
* `else
|
||||
* `ifndef FOO
|
||||
* `define FOO
|
||||
* `endif
|
||||
* `endif
|
||||
* `timescale 1ns/1ns
|
||||
*/
|
||||
"[def `ifdef] [variable DUT]",
|
||||
"[def `else]",
|
||||
" [def `ifndef] [variable FOO]",
|
||||
" [def `define] [variable FOO]",
|
||||
" [def `endif]",
|
||||
"[def `endif]",
|
||||
"[def `timescale] [number 1][variable ns][meta /][number 1][variable ns]",
|
||||
""
|
||||
);
|
||||
|
||||
})();
|
||||
781
public/admin/plugins/codemirror/mode/verilog/verilog.js
vendored
Normal file
781
public/admin/plugins/codemirror/mode/verilog/verilog.js
vendored
Normal file
@@ -0,0 +1,781 @@
|
||||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: https://codemirror.net/5/LICENSE
|
||||
|
||||
(function(mod) {
|
||||
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
|
||||
mod(CodeMirror);
|
||||
})(function(CodeMirror) {
|
||||
"use strict";
|
||||
|
||||
CodeMirror.defineMode("verilog", function(config, parserConfig) {
|
||||
|
||||
var indentUnit = config.indentUnit,
|
||||
statementIndentUnit = parserConfig.statementIndentUnit || indentUnit,
|
||||
dontAlignCalls = parserConfig.dontAlignCalls,
|
||||
// compilerDirectivesUseRegularIndentation - If set, Compiler directive
|
||||
// indentation follows the same rules as everything else. Otherwise if
|
||||
// false, compiler directives will track their own indentation.
|
||||
// For example, `ifdef nested inside another `ifndef will be indented,
|
||||
// but a `ifdef inside a function block may not be indented.
|
||||
compilerDirectivesUseRegularIndentation = parserConfig.compilerDirectivesUseRegularIndentation,
|
||||
noIndentKeywords = parserConfig.noIndentKeywords || [],
|
||||
multiLineStrings = parserConfig.multiLineStrings,
|
||||
hooks = parserConfig.hooks || {};
|
||||
|
||||
function words(str) {
|
||||
var obj = {}, words = str.split(" ");
|
||||
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keywords from IEEE 1800-2012
|
||||
*/
|
||||
var keywords = words(
|
||||
"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
|
||||
unary_operator ::=
|
||||
+ | - | ! | ~ | & | ~& | | | ~| | ^ | ~^ | ^~
|
||||
binary_operator ::=
|
||||
+ | - | * | / | % | == | != | === | !== | ==? | !=? | && | || | **
|
||||
| < | <= | > | >= | & | | | ^ | ^~ | ~^ | >> | << | >>> | <<<
|
||||
| -> | <->
|
||||
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 = /[)}\]]/;
|
||||
var compilerDirectiveRegex = new RegExp(
|
||||
"^(`(?:ifdef|ifndef|elsif|else|endif|undef|undefineall|define|include|begin_keywords|celldefine|default|" +
|
||||
"nettype|end_keywords|endcelldefine|line|nounconnected_drive|pragma|resetall|timescale|unconnected_drive))\\b");
|
||||
var compilerDirectiveBeginRegex = /^(`(?:ifdef|ifndef|elsif|else))\b/;
|
||||
var compilerDirectiveEndRegex = /^(`(?:elsif|else|endif))\b/;
|
||||
|
||||
var curPunc;
|
||||
var curKeyword;
|
||||
|
||||
// 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"
|
||||
);
|
||||
|
||||
// Opening/closing pairs
|
||||
var openClose = {};
|
||||
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";
|
||||
openClose["macro_begin"] = "macro_end";
|
||||
|
||||
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 extern typedef");
|
||||
|
||||
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)
|
||||
return style;
|
||||
|
||||
if (/[,;:\.]/.test(ch)) {
|
||||
curPunc = stream.next();
|
||||
return null;
|
||||
}
|
||||
if (isBracketChar.test(ch)) {
|
||||
curPunc = stream.next();
|
||||
return "bracket";
|
||||
}
|
||||
// Macros (tick-defines)
|
||||
if (ch == '`') {
|
||||
stream.next();
|
||||
if (stream.eatWhile(/[\w\$_]/)) {
|
||||
var cur = stream.current();
|
||||
curKeyword = cur;
|
||||
// Macros that end in _begin, are start of block and end with _end
|
||||
if (cur.startsWith("`uvm_") && cur.endsWith("_begin")) {
|
||||
var keywordClose = curKeyword.substr(0,curKeyword.length - 5) + "end";
|
||||
openClose[cur] = keywordClose;
|
||||
curPunc = "newblock";
|
||||
} else {
|
||||
stream.eatSpace();
|
||||
if (stream.peek() == '(') {
|
||||
// Check if this is a block
|
||||
curPunc = "newmacro";
|
||||
}
|
||||
var withSpace = stream.current();
|
||||
// Move the stream back before the spaces
|
||||
stream.backUp(withSpace.length - cur.length);
|
||||
}
|
||||
return "def";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// System calls
|
||||
if (ch == '$') {
|
||||
stream.next();
|
||||
if (stream.eatWhile(/[\w\$_]/)) {
|
||||
return "meta";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// Time literals
|
||||
if (ch == '#') {
|
||||
stream.next();
|
||||
stream.eatWhile(/[\d_.]/);
|
||||
return "def";
|
||||
}
|
||||
// Event
|
||||
if (ch == '@') {
|
||||
stream.next();
|
||||
stream.eatWhile(/[@]/);
|
||||
return "def";
|
||||
}
|
||||
// Strings
|
||||
if (ch == '"') {
|
||||
stream.next();
|
||||
state.tokenize = tokenString(ch);
|
||||
return state.tokenize(stream, state);
|
||||
}
|
||||
// Comments
|
||||
if (ch == "/") {
|
||||
stream.next();
|
||||
if (stream.eat("*")) {
|
||||
state.tokenize = tokenComment;
|
||||
return tokenComment(stream, state);
|
||||
}
|
||||
if (stream.eat("/")) {
|
||||
stream.skipToEnd();
|
||||
return "comment";
|
||||
}
|
||||
stream.backUp(1);
|
||||
}
|
||||
|
||||
// Numeric literals
|
||||
if (stream.match(realLiteral) ||
|
||||
stream.match(decimalLiteral) ||
|
||||
stream.match(binaryLiteral) ||
|
||||
stream.match(octLiteral) ||
|
||||
stream.match(hexLiteral) ||
|
||||
stream.match(unsignedNumber) ||
|
||||
stream.match(realLiteral)) {
|
||||
return "number";
|
||||
}
|
||||
|
||||
// Operators
|
||||
if (stream.eatWhile(isOperatorChar)) {
|
||||
curPunc = stream.current();
|
||||
return "meta";
|
||||
}
|
||||
|
||||
// Keywords / plain variables
|
||||
if (stream.eatWhile(/[\w\$_]/)) {
|
||||
var cur = stream.current();
|
||||
if (keywords[cur]) {
|
||||
if (openClose[cur]) {
|
||||
curPunc = "newblock";
|
||||
if (cur === "fork") {
|
||||
// Fork can be a statement instead of block in cases of:
|
||||
// "disable fork;" and "wait fork;" (trailing semicolon)
|
||||
stream.eatSpace()
|
||||
if (stream.peek() == ';') {
|
||||
curPunc = "newstatement";
|
||||
}
|
||||
stream.backUp(stream.current().length - cur.length);
|
||||
}
|
||||
}
|
||||
if (statementKeywords[cur]) {
|
||||
curPunc = "newstatement";
|
||||
}
|
||||
curKeyword = cur;
|
||||
return "keyword";
|
||||
}
|
||||
return "variable";
|
||||
}
|
||||
|
||||
stream.next();
|
||||
return null;
|
||||
}
|
||||
|
||||
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;
|
||||
return "string";
|
||||
};
|
||||
}
|
||||
|
||||
function tokenComment(stream, state) {
|
||||
var maybeEnd = false, ch;
|
||||
while (ch = stream.next()) {
|
||||
if (ch == "/" && maybeEnd) {
|
||||
state.tokenize = tokenBase;
|
||||
break;
|
||||
}
|
||||
maybeEnd = (ch == "*");
|
||||
}
|
||||
return "comment";
|
||||
}
|
||||
|
||||
function Context(indented, column, type, scopekind, align, prev) {
|
||||
this.indented = indented;
|
||||
this.column = column;
|
||||
this.type = type;
|
||||
this.scopekind = scopekind;
|
||||
this.align = align;
|
||||
this.prev = prev;
|
||||
}
|
||||
function pushContext(state, col, type, scopekind) {
|
||||
var indent = state.indented;
|
||||
var c = new Context(indent, col, type, scopekind ? scopekind : "", 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) {
|
||||
return true;
|
||||
} else {
|
||||
// contextClosing may be multiple keywords separated by ;
|
||||
var closingKeywords = contextClosing.split(";");
|
||||
for (var i in closingKeywords) {
|
||||
if (text == closingKeywords[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function isInsideScopeKind(ctx, scopekind) {
|
||||
if (ctx == null) {
|
||||
return false;
|
||||
}
|
||||
if (ctx.scopekind === scopekind) {
|
||||
return true;
|
||||
}
|
||||
return isInsideScopeKind(ctx.prev, scopekind);
|
||||
}
|
||||
|
||||
function buildElectricInputRegEx() {
|
||||
// Reindentation should occur on any bracket char: {}()[]
|
||||
// or on a match of any of the block closing keywords, at
|
||||
// the end of a line
|
||||
var allClosings = [];
|
||||
for (var i in openClose) {
|
||||
if (openClose[i]) {
|
||||
var closings = openClose[i].split(";");
|
||||
for (var j in closings) {
|
||||
allClosings.push(closings[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
var re = new RegExp("[{}()\\[\\]]|(" + allClosings.join("|") + ")$");
|
||||
return re;
|
||||
}
|
||||
|
||||
// Interface
|
||||
return {
|
||||
|
||||
// Regex to force current line to reindent
|
||||
electricInput: buildElectricInputRegEx(),
|
||||
|
||||
startState: function(basecolumn) {
|
||||
var state = {
|
||||
tokenize: null,
|
||||
context: new Context((basecolumn || 0) - indentUnit, 0, "top", "top", false),
|
||||
indented: 0,
|
||||
compilerDirectiveIndented: 0,
|
||||
startOfLine: true
|
||||
};
|
||||
if (hooks.startState) hooks.startState(state);
|
||||
return state;
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
var ctx = state.context;
|
||||
if (stream.sol()) {
|
||||
if (ctx.align == null) ctx.align = false;
|
||||
state.indented = stream.indentation();
|
||||
state.startOfLine = true;
|
||||
}
|
||||
if (hooks.token) {
|
||||
// Call hook, with an optional return value of a style to override verilog styling.
|
||||
var style = hooks.token(stream, state);
|
||||
if (style !== undefined) {
|
||||
return style;
|
||||
}
|
||||
}
|
||||
if (stream.eatSpace()) return null;
|
||||
curPunc = null;
|
||||
curKeyword = null;
|
||||
var style = (state.tokenize || tokenBase)(stream, state);
|
||||
if (style == "comment" || style == "meta" || style == "variable") {
|
||||
if (((curPunc === "=") || (curPunc === "<=")) && !isInsideScopeKind(ctx, "assignment")) {
|
||||
// '<=' could be nonblocking assignment or lessthan-equals (which shouldn't cause indent)
|
||||
// Search through the context to see if we are already in an assignment.
|
||||
// '=' could be inside port declaration with comma or ')' afterward, or inside for(;;) block.
|
||||
pushContext(state, stream.column() + curPunc.length, "assignment", "assignment");
|
||||
if (ctx.align == null) ctx.align = true;
|
||||
}
|
||||
return style;
|
||||
}
|
||||
if (ctx.align == null) ctx.align = true;
|
||||
|
||||
var isClosingAssignment = ctx.type == "assignment" &&
|
||||
closingBracket.test(curPunc) && ctx.prev && ctx.prev.type === curPunc;
|
||||
if (curPunc == ctx.type || isClosingAssignment) {
|
||||
if (isClosingAssignment) {
|
||||
ctx = popContext(state);
|
||||
}
|
||||
ctx = popContext(state);
|
||||
if (curPunc == ")") {
|
||||
// Handle closing macros, assuming they could have a semicolon or begin/end block inside.
|
||||
if (ctx && (ctx.type === "macro")) {
|
||||
ctx = popContext(state);
|
||||
while (ctx && (ctx.type == "statement" || ctx.type == "assignment")) ctx = popContext(state);
|
||||
}
|
||||
} else if (curPunc == "}") {
|
||||
// Handle closing statements like constraint block: "foreach () {}" which
|
||||
// do not have semicolon at end.
|
||||
if (ctx && (ctx.type === "statement")) {
|
||||
while (ctx && (ctx.type == "statement")) ctx = popContext(state);
|
||||
}
|
||||
}
|
||||
} else if (((curPunc == ";" || curPunc == ",") && (ctx.type == "statement" || ctx.type == "assignment")) ||
|
||||
(ctx.type && isClosing(curKeyword, ctx.type))) {
|
||||
ctx = popContext(state);
|
||||
while (ctx && (ctx.type == "statement" || ctx.type == "assignment")) 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", "case");
|
||||
} else if (curPunc == "newstatement") {
|
||||
pushContext(state, stream.column(), "statement", curKeyword);
|
||||
} 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") {
|
||||
// Same thing for task
|
||||
} else if (curKeyword == "class" && ctx && ctx.type == "statement") {
|
||||
// Same thing for class (e.g. typedef)
|
||||
} else {
|
||||
var close = openClose[curKeyword];
|
||||
pushContext(state, stream.column(), close, curKeyword);
|
||||
}
|
||||
} else if (curPunc == "newmacro" || (curKeyword && curKeyword.match(compilerDirectiveRegex))) {
|
||||
if (curPunc == "newmacro") {
|
||||
// Macros (especially if they have parenthesis) potentially have a semicolon
|
||||
// or complete statement/block inside, and should be treated as such.
|
||||
pushContext(state, stream.column(), "macro", "macro");
|
||||
}
|
||||
if (curKeyword.match(compilerDirectiveEndRegex)) {
|
||||
state.compilerDirectiveIndented -= statementIndentUnit;
|
||||
}
|
||||
if (curKeyword.match(compilerDirectiveBeginRegex)) {
|
||||
state.compilerDirectiveIndented += statementIndentUnit;
|
||||
}
|
||||
}
|
||||
|
||||
state.startOfLine = false;
|
||||
return style;
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
if (state.tokenize != tokenBase && state.tokenize != null) return CodeMirror.Pass;
|
||||
if (hooks.indent) {
|
||||
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 closing = false;
|
||||
var possibleClosing = textAfter.match(closingBracketOrWord);
|
||||
if (possibleClosing)
|
||||
closing = isClosing(possibleClosing[0], ctx.type);
|
||||
if (!compilerDirectivesUseRegularIndentation && textAfter.match(compilerDirectiveRegex)) {
|
||||
if (textAfter.match(compilerDirectiveEndRegex)) {
|
||||
return state.compilerDirectiveIndented - statementIndentUnit;
|
||||
}
|
||||
return state.compilerDirectiveIndented;
|
||||
}
|
||||
if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit);
|
||||
else if ((closingBracket.test(ctx.type) || ctx.type == "assignment")
|
||||
&& 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);
|
||||
},
|
||||
|
||||
blockCommentStart: "/*",
|
||||
blockCommentEnd: "*/",
|
||||
lineComment: "//",
|
||||
fold: "indent"
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-verilog", {
|
||||
name: "verilog"
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-systemverilog", {
|
||||
name: "verilog"
|
||||
});
|
||||
|
||||
|
||||
|
||||
// TL-Verilog mode.
|
||||
// See tl-x.org for language spec.
|
||||
// See the mode in action at makerchip.com.
|
||||
// Contact: steve.hoover@redwoodeda.com
|
||||
|
||||
// TLV Identifier prefixes.
|
||||
// Note that sign is not treated separately, so "+/-" versions of numeric identifiers
|
||||
// are included.
|
||||
var tlvIdentifierStyle = {
|
||||
"|": "link",
|
||||
">": "property", // Should condition this off for > TLV 1c.
|
||||
"$": "variable",
|
||||
"$$": "variable",
|
||||
"?$": "qualifier",
|
||||
"?*": "qualifier",
|
||||
"-": "hr",
|
||||
"/": "property",
|
||||
"/-": "property",
|
||||
"@": "variable-3",
|
||||
"@-": "variable-3",
|
||||
"@++": "variable-3",
|
||||
"@+=": "variable-3",
|
||||
"@+=-": "variable-3",
|
||||
"@--": "variable-3",
|
||||
"@-=": "variable-3",
|
||||
"%+": "tag",
|
||||
"%-": "tag",
|
||||
"%": "tag",
|
||||
">>": "tag",
|
||||
"<<": "tag",
|
||||
"<>": "tag",
|
||||
"#": "tag", // Need to choose a style for this.
|
||||
"^": "attribute",
|
||||
"^^": "attribute",
|
||||
"^!": "attribute",
|
||||
"*": "variable-2",
|
||||
"**": "variable-2",
|
||||
"\\": "keyword",
|
||||
"\"": "comment"
|
||||
};
|
||||
|
||||
// Lines starting with these characters define scope (result in indentation).
|
||||
var tlvScopePrefixChars = {
|
||||
"/": "beh-hier",
|
||||
">": "beh-hier",
|
||||
"-": "phys-hier",
|
||||
"|": "pipe",
|
||||
"?": "when",
|
||||
"@": "stage",
|
||||
"\\": "keyword"
|
||||
};
|
||||
var tlvIndentUnit = 3;
|
||||
var tlvTrackStatements = false;
|
||||
var tlvIdentMatch = /^([~!@#\$%\^&\*-\+=\?\/\\\|'"<>]+)([\d\w_]*)/; // Matches an identifier.
|
||||
// Note that ':' is excluded, because of it's use in [:].
|
||||
var tlvFirstLevelIndentMatch = /^[! ] /;
|
||||
var tlvLineIndentationMatch = /^[! ] */;
|
||||
var tlvCommentMatch = /^\/[\/\*]/;
|
||||
|
||||
|
||||
// Returns a style specific to the scope at the given indentation column.
|
||||
// Type is one of: "indent", "scope-ident", "before-scope-ident".
|
||||
function tlvScopeStyle(state, indentation, type) {
|
||||
// Begin scope.
|
||||
var depth = indentation / tlvIndentUnit; // TODO: Pass this in instead.
|
||||
return "tlv-" + state.tlvIndentationStyle[depth] + "-" + type;
|
||||
}
|
||||
|
||||
// Return true if the next thing in the stream is an identifier with a mnemonic.
|
||||
function tlvIdentNext(stream) {
|
||||
var match;
|
||||
return (match = stream.match(tlvIdentMatch, false)) && match[2].length > 0;
|
||||
}
|
||||
|
||||
CodeMirror.defineMIME("text/x-tlv", {
|
||||
name: "verilog",
|
||||
|
||||
hooks: {
|
||||
|
||||
electricInput: false,
|
||||
|
||||
|
||||
// Return undefined for verilog tokenizing, or style for TLV token (null not used).
|
||||
// Standard CM styles are used for most formatting, but some TL-Verilog-specific highlighting
|
||||
// can be enabled with the definition of cm-tlv-* styles, including highlighting for:
|
||||
// - M4 tokens
|
||||
// - TLV scope indentation
|
||||
// - Statement delimitation (enabled by tlvTrackStatements)
|
||||
token: function(stream, state) {
|
||||
var style = undefined;
|
||||
var match; // Return value of pattern matches.
|
||||
|
||||
// Set highlighting mode based on code region (TLV or SV).
|
||||
if (stream.sol() && ! state.tlvInBlockComment) {
|
||||
// Process region.
|
||||
if (stream.peek() == '\\') {
|
||||
style = "def";
|
||||
stream.skipToEnd();
|
||||
if (stream.string.match(/\\SV/)) {
|
||||
state.tlvCodeActive = false;
|
||||
} else if (stream.string.match(/\\TLV/)){
|
||||
state.tlvCodeActive = true;
|
||||
}
|
||||
}
|
||||
// Correct indentation in the face of a line prefix char.
|
||||
if (state.tlvCodeActive && stream.pos == 0 &&
|
||||
(state.indented == 0) && (match = stream.match(tlvLineIndentationMatch, false))) {
|
||||
state.indented = match[0].length;
|
||||
}
|
||||
|
||||
// Compute indentation state:
|
||||
// o Auto indentation on next line
|
||||
// o Indentation scope styles
|
||||
var indented = state.indented;
|
||||
var depth = indented / tlvIndentUnit;
|
||||
if (depth <= state.tlvIndentationStyle.length) {
|
||||
// not deeper than current scope
|
||||
|
||||
var blankline = stream.string.length == indented;
|
||||
var chPos = depth * tlvIndentUnit;
|
||||
if (chPos < stream.string.length) {
|
||||
var bodyString = stream.string.slice(chPos);
|
||||
var ch = bodyString[0];
|
||||
if (tlvScopePrefixChars[ch] && ((match = bodyString.match(tlvIdentMatch)) &&
|
||||
tlvIdentifierStyle[match[1]])) {
|
||||
// This line begins scope.
|
||||
// Next line gets indented one level.
|
||||
indented += tlvIndentUnit;
|
||||
// Style the next level of indentation (except non-region keyword identifiers,
|
||||
// which are statements themselves)
|
||||
if (!(ch == "\\" && chPos > 0)) {
|
||||
state.tlvIndentationStyle[depth] = tlvScopePrefixChars[ch];
|
||||
if (tlvTrackStatements) {state.statementComment = false;}
|
||||
depth++;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Clear out deeper indentation levels unless line is blank.
|
||||
if (!blankline) {
|
||||
while (state.tlvIndentationStyle.length > depth) {
|
||||
state.tlvIndentationStyle.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Set next level of indentation.
|
||||
state.tlvNextIndent = indented;
|
||||
}
|
||||
|
||||
if (state.tlvCodeActive) {
|
||||
// Highlight as TLV.
|
||||
|
||||
var beginStatement = false;
|
||||
if (tlvTrackStatements) {
|
||||
// This starts a statement if the position is at the scope level
|
||||
// and we're not within a statement leading comment.
|
||||
beginStatement =
|
||||
(stream.peek() != " ") && // not a space
|
||||
(style === undefined) && // not a region identifier
|
||||
!state.tlvInBlockComment && // not in block comment
|
||||
//!stream.match(tlvCommentMatch, false) && // not comment start
|
||||
(stream.column() == state.tlvIndentationStyle.length * tlvIndentUnit); // at scope level
|
||||
if (beginStatement) {
|
||||
if (state.statementComment) {
|
||||
// statement already started by comment
|
||||
beginStatement = false;
|
||||
}
|
||||
state.statementComment =
|
||||
stream.match(tlvCommentMatch, false); // comment start
|
||||
}
|
||||
}
|
||||
|
||||
var match;
|
||||
if (style !== undefined) {
|
||||
// Region line.
|
||||
style += " " + tlvScopeStyle(state, 0, "scope-ident")
|
||||
} else if (((stream.pos / tlvIndentUnit) < state.tlvIndentationStyle.length) &&
|
||||
(match = stream.match(stream.sol() ? tlvFirstLevelIndentMatch : /^ /))) {
|
||||
// Indentation
|
||||
style = // make this style distinct from the previous one to prevent
|
||||
// codemirror from combining spans
|
||||
"tlv-indent-" + (((stream.pos % 2) == 0) ? "even" : "odd") +
|
||||
// and style it
|
||||
" " + tlvScopeStyle(state, stream.pos - tlvIndentUnit, "indent");
|
||||
// Style the line prefix character.
|
||||
if (match[0].charAt(0) == "!") {
|
||||
style += " tlv-alert-line-prefix";
|
||||
}
|
||||
// Place a class before a scope identifier.
|
||||
if (tlvIdentNext(stream)) {
|
||||
style += " " + tlvScopeStyle(state, stream.pos, "before-scope-ident");
|
||||
}
|
||||
} else if (state.tlvInBlockComment) {
|
||||
// In a block comment.
|
||||
if (stream.match(/^.*?\*\//)) {
|
||||
// Exit block comment.
|
||||
state.tlvInBlockComment = false;
|
||||
if (tlvTrackStatements && !stream.eol()) {
|
||||
// Anything after comment is assumed to be real statement content.
|
||||
state.statementComment = false;
|
||||
}
|
||||
} else {
|
||||
stream.skipToEnd();
|
||||
}
|
||||
style = "comment";
|
||||
} else if ((match = stream.match(tlvCommentMatch)) && !state.tlvInBlockComment) {
|
||||
// Start comment.
|
||||
if (match[0] == "//") {
|
||||
// Line comment.
|
||||
stream.skipToEnd();
|
||||
} else {
|
||||
// Block comment.
|
||||
state.tlvInBlockComment = true;
|
||||
}
|
||||
style = "comment";
|
||||
} else if (match = stream.match(tlvIdentMatch)) {
|
||||
// looks like an identifier (or identifier prefix)
|
||||
var prefix = match[1];
|
||||
var mnemonic = match[2];
|
||||
if (// is identifier prefix
|
||||
tlvIdentifierStyle.hasOwnProperty(prefix) &&
|
||||
// has mnemonic or we're at the end of the line (maybe it hasn't been typed yet)
|
||||
(mnemonic.length > 0 || stream.eol())) {
|
||||
style = tlvIdentifierStyle[prefix];
|
||||
if (stream.column() == state.indented) {
|
||||
// Begin scope.
|
||||
style += " " + tlvScopeStyle(state, stream.column(), "scope-ident")
|
||||
}
|
||||
} else {
|
||||
// Just swallow one character and try again.
|
||||
// This enables subsequent identifier match with preceding symbol character, which
|
||||
// is legal within a statement. (E.g., !$reset). It also enables detection of
|
||||
// comment start with preceding symbols.
|
||||
stream.backUp(stream.current().length - 1);
|
||||
style = "tlv-default";
|
||||
}
|
||||
} else if (stream.match(/^\t+/)) {
|
||||
// Highlight tabs, which are illegal.
|
||||
style = "tlv-tab";
|
||||
} else if (stream.match(/^[\[\]{}\(\);\:]+/)) {
|
||||
// [:], (), {}, ;.
|
||||
style = "meta";
|
||||
} else if (match = stream.match(/^[mM]4([\+_])?[\w\d_]*/)) {
|
||||
// m4 pre proc
|
||||
style = (match[1] == "+") ? "tlv-m4-plus" : "tlv-m4";
|
||||
} else if (stream.match(/^ +/)){
|
||||
// Skip over spaces.
|
||||
if (stream.eol()) {
|
||||
// Trailing spaces.
|
||||
style = "error";
|
||||
} else {
|
||||
// Non-trailing spaces.
|
||||
style = "tlv-default";
|
||||
}
|
||||
} else if (stream.match(/^[\w\d_]+/)) {
|
||||
// alpha-numeric token.
|
||||
style = "number";
|
||||
} else {
|
||||
// Eat the next char w/ no formatting.
|
||||
stream.next();
|
||||
style = "tlv-default";
|
||||
}
|
||||
if (beginStatement) {
|
||||
style += " tlv-statement";
|
||||
}
|
||||
} else {
|
||||
if (stream.match(/^[mM]4([\w\d_]*)/)) {
|
||||
// m4 pre proc
|
||||
style = "tlv-m4";
|
||||
}
|
||||
}
|
||||
return style;
|
||||
},
|
||||
|
||||
indent: function(state) {
|
||||
return (state.tlvCodeActive == true) ? state.tlvNextIndent : -1;
|
||||
},
|
||||
|
||||
startState: function(state) {
|
||||
state.tlvIndentationStyle = []; // Styles to use for each level of indentation.
|
||||
state.tlvCodeActive = true; // True when we're in a TLV region (and at beginning of file).
|
||||
state.tlvNextIndent = -1; // The number of spaces to autoindent the next line if tlvCodeActive.
|
||||
state.tlvInBlockComment = false; // True inside /**/ comment.
|
||||
if (tlvTrackStatements) {
|
||||
state.statementComment = false; // True inside a statement's header comment.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user