Skip to content

Commit

Permalink
Syntax: Improve method detection
Browse files Browse the repository at this point in the history
* Exclude instance port lists from matching
* Include #( to also highlight module name in instances with parameters

Related with #191
  • Loading branch information
vhda committed Jun 12, 2020
1 parent e2449da commit da9c42e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
4 changes: 2 additions & 2 deletions syntax/verilog_systemverilog.vim
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ syn match verilogEscape "\\\o\o\=\o\=" contained

syn keyword verilogMethod new
if v:version >= 704
syn match verilogMethod "\(^\s\+\.\)\@30<!\<\w\+\ze("
syn match verilogMethod "\(\(\s\|[(/]\|^\)\.\)\@2<!\<\w\+\ze#\?("
else
syn match verilogMethod "\(^\s\+\.\)\@<!\<\w\+\ze("
syn match verilogMethod "\(\(\s\|[(/]\|^\)\.\)\@<!\<\w\+\ze#\?("
endif

syn match verilogLabel "\<\k\+\>\ze\s*:\s*\<\(assert\|assume\|cover\(point\)\?\|cross\)\>"
Expand Down
28 changes: 14 additions & 14 deletions test/indent.sv.html
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@
device d1 <span class="Special">(</span>
<span class="Special">.</span>port <span class="Special">(</span>port<span class="Special">[</span><span class="Constant">1</span><span class="Special">]),</span>
<span class="Comment">// .port1(), comment</span>
<span class="Comment">/**/</span><span class="Special">.</span><span class="Identifier">port2</span><span class="Special">(),</span> <span class="Comment">// comment</span>
<span class="Comment">/**/</span><span class="Special">.</span>port2<span class="Special">(),</span> <span class="Comment">// comment</span>
<span class="Comment">/*.port3(), */</span>
<span class="Comment">// .port4(), comment</span>
<span class="Special">.</span>portA<span class="Special">(</span>port<span class="Special">[</span><span class="Constant">2</span><span class="Special">])</span>
Expand All @@ -603,22 +603,22 @@
device d2 <span class="Special">(</span> out<span class="Special">,</span> portA<span class="Special">,</span> portB <span class="Special">);</span>
<span class="PreProc">`endif</span>
<span class="PreProc">`elsif</span> <span class="Constant">V2K</span>
device d2 <span class="Special">(</span> <span class="Special">.</span><span class="Identifier">out</span><span class="Special">(</span>out<span class="Special">),</span> <span class="Special">.*</span> <span class="Special">);</span>
device d2 <span class="Special">(</span> <span class="Special">.</span>out<span class="Special">(</span>out<span class="Special">),</span> <span class="Special">.*</span> <span class="Special">);</span>
device d2 <span class="Special">(</span> out<span class="Special">,</span> portA<span class="Special">,</span> portB <span class="Special">);</span>
<span class="PreProc">`ifndef</span> <span class="Constant">SWAP</span>
device d3 <span class="Special">(</span> <span class="Special">.</span><span class="Identifier">out</span><span class="Special">(</span>out<span class="Special">),</span> <span class="Special">.*</span> <span class="Special">);</span>
device d2 <span class="Special">(</span> <span class="Special">.</span><span class="Identifier">out</span><span class="Special">(</span>out<span class="Special">),</span> <span class="Special">.*</span> <span class="Special">);</span>
device d3 <span class="Special">(</span> <span class="Special">.</span>out<span class="Special">(</span>out<span class="Special">),</span> <span class="Special">.*</span> <span class="Special">);</span>
device d2 <span class="Special">(</span> <span class="Special">.</span>out<span class="Special">(</span>out<span class="Special">),</span> <span class="Special">.*</span> <span class="Special">);</span>
<span class="PreProc">`else</span>
device d3 <span class="Special">(</span> <span class="Special">.</span><span class="Identifier">out</span><span class="Special">(</span>out<span class="Special">),</span> <span class="Special">.</span><span class="Identifier">portA</span><span class="Special">(</span>portB<span class="Special">),</span> <span class="Special">.</span><span class="Identifier">portB</span><span class="Special">(</span>portA<span class="Special">)</span> <span class="Special">);</span>
device d2 <span class="Special">(</span> <span class="Special">.</span><span class="Identifier">out</span><span class="Special">(</span>out<span class="Special">),</span> <span class="Special">.*</span> <span class="Special">);</span>
device d3 <span class="Special">(</span> <span class="Special">.</span>out<span class="Special">(</span>out<span class="Special">),</span> <span class="Special">.</span>portA<span class="Special">(</span>portB<span class="Special">),</span> <span class="Special">.</span>portB<span class="Special">(</span>portA<span class="Special">)</span> <span class="Special">);</span>
device d2 <span class="Special">(</span> <span class="Special">.</span>out<span class="Special">(</span>out<span class="Special">),</span> <span class="Special">.*</span> <span class="Special">);</span>
<span class="PreProc">`endif</span>
<span class="PreProc">`endif</span>
<span class="PreProc">`ifndef</span> <span class="Constant">SWAP</span>
device d3 <span class="Special">(</span> <span class="Special">.</span><span class="Identifier">out</span><span class="Special">(</span>out<span class="Special">),</span> <span class="Special">.*</span> <span class="Special">);</span>
device d2 <span class="Special">(</span> <span class="Special">.</span><span class="Identifier">out</span><span class="Special">(</span>out<span class="Special">),</span> <span class="Special">.*</span> <span class="Special">);</span>
device d3 <span class="Special">(</span> <span class="Special">.</span>out<span class="Special">(</span>out<span class="Special">),</span> <span class="Special">.*</span> <span class="Special">);</span>
device d2 <span class="Special">(</span> <span class="Special">.</span>out<span class="Special">(</span>out<span class="Special">),</span> <span class="Special">.*</span> <span class="Special">);</span>
<span class="PreProc">`else</span>
device d3 <span class="Special">(</span> <span class="Special">.</span><span class="Identifier">out</span><span class="Special">(</span>out<span class="Special">),</span> <span class="Special">.</span><span class="Identifier">portA</span><span class="Special">(</span>portB<span class="Special">),</span> <span class="Special">.</span><span class="Identifier">portB</span><span class="Special">(</span>portA<span class="Special">)</span> <span class="Special">);</span>
device d2 <span class="Special">(</span> <span class="Special">.</span><span class="Identifier">out</span><span class="Special">(</span>out<span class="Special">),</span> <span class="Special">.*</span> <span class="Special">);</span>
device d3 <span class="Special">(</span> <span class="Special">.</span>out<span class="Special">(</span>out<span class="Special">),</span> <span class="Special">.</span>portA<span class="Special">(</span>portB<span class="Special">),</span> <span class="Special">.</span>portB<span class="Special">(</span>portA<span class="Special">)</span> <span class="Special">);</span>
device d2 <span class="Special">(</span> <span class="Special">.</span>out<span class="Special">(</span>out<span class="Special">),</span> <span class="Special">.*</span> <span class="Special">);</span>
<span class="PreProc">`endif</span>

<span class="Statement">endmodule</span>
Expand Down Expand Up @@ -863,10 +863,10 @@

<span class="Comment">// comment</span>

<span class="Statement">virtual</span> <span class="Statement">class</span> DataTypes_packer<span class="Special">#(</span><span class="Statement">type</span> <span class="Constant">T</span><span class="Special">,</span> <span class="Statement">int</span> <span class="Constant">L</span><span class="Special">,</span> <span class="Statement">int</span> <span class="Constant">W</span><span class="Special">,</span> <span class="Statement">int</span> <span class="Constant">I</span><span class="Special">);</span>
<span class="Statement">virtual</span> <span class="Statement">class</span> <span class="Identifier">DataTypes_packer</span><span class="Special">#(</span><span class="Statement">type</span> <span class="Constant">T</span><span class="Special">,</span> <span class="Statement">int</span> <span class="Constant">L</span><span class="Special">,</span> <span class="Statement">int</span> <span class="Constant">W</span><span class="Special">,</span> <span class="Statement">int</span> <span class="Constant">I</span><span class="Special">);</span>

<span class="Statement">extern</span> <span class="Statement">static</span> <span class="Statement">function</span> <span class="Statement">void</span> <span class="Identifier">unpack</span><span class="Special">(</span><span class="Statement">const</span> <span class="Statement">ref</span> <span class="Statement">bit</span> <span class="Special">[</span><span class="Constant">L</span><span class="Special">-</span><span class="Constant">1</span><span class="Special">:</span><span class="Constant">0</span><span class="Special">]</span> in<span class="Special">,</span> <span class="Statement">ref</span> <span class="Constant">T</span> out<span class="Special">[]);</span>
<span class="Statement">extern</span> <span class="Statement">static</span> <span class="Statement">function</span> <span class="Statement">void</span> <span class="Identifier">unpack5</span><span class="Special">(</span><span class="Statement">const</span> <span class="Statement">ref</span> <span class="Statement">bit</span> <span class="Special">[</span><span class="Constant">L</span><span class="Special">-</span><span class="Constant">1</span><span class="Special">:</span><span class="Constant">0</span><span class="Special">]</span> in<span class="Special">,</span> <span class="Statement">ref</span> t5<span class="Special">#(</span><span class="Constant">W</span><span class="Special">,</span><span class="Constant">I</span><span class="Special">)</span> out<span class="Special">[],</span> <span class="Statement">input</span> <span class="Statement">int</span> n_MSB2ignore<span class="Special">=</span><span class="Constant">0</span><span class="Special">);</span>
<span class="Statement">extern</span> <span class="Statement">static</span> <span class="Statement">function</span> <span class="Statement">void</span> <span class="Identifier">unpack5</span><span class="Special">(</span><span class="Statement">const</span> <span class="Statement">ref</span> <span class="Statement">bit</span> <span class="Special">[</span><span class="Constant">L</span><span class="Special">-</span><span class="Constant">1</span><span class="Special">:</span><span class="Constant">0</span><span class="Special">]</span> in<span class="Special">,</span> <span class="Statement">ref</span> <span class="Identifier">t5</span><span class="Special">#(</span><span class="Constant">W</span><span class="Special">,</span><span class="Constant">I</span><span class="Special">)</span> out<span class="Special">[],</span> <span class="Statement">input</span> <span class="Statement">int</span> n_MSB2ignore<span class="Special">=</span><span class="Constant">0</span><span class="Special">);</span>

<span class="Comment">/*</span>
<span class="Comment"> // packing functions</span>
Expand All @@ -876,7 +876,7 @@

<span class="Comment">// unpack functions:</span>
<span class="Statement">extern</span> <span class="Statement">static</span> <span class="Statement">function</span> <span class="Statement">void</span> <span class="Identifier">unpack</span><span class="Special">(</span><span class="Statement">const</span> <span class="Statement">ref</span> <span class="Statement">bit</span> <span class="Special">[</span><span class="Constant">L</span><span class="Special">-</span><span class="Constant">1</span><span class="Special">:</span><span class="Constant">0</span><span class="Special">]</span> in<span class="Special">,</span> <span class="Statement">ref</span> <span class="Constant">T</span> out<span class="Special">[]);</span>
<span class="Statement">extern</span> <span class="Statement">static</span> <span class="Statement">function</span> <span class="Statement">void</span> <span class="Identifier">unpack5</span><span class="Special">(</span><span class="Statement">const</span> <span class="Statement">ref</span> <span class="Statement">bit</span> <span class="Special">[</span><span class="Constant">L</span><span class="Special">-</span><span class="Constant">1</span><span class="Special">:</span><span class="Constant">0</span><span class="Special">]</span> in<span class="Special">,</span> <span class="Statement">ref</span> t5<span class="Special">#(</span><span class="Constant">W</span><span class="Special">,</span><span class="Constant">I</span><span class="Special">)</span> out<span class="Special">[],</span> <span class="Statement">input</span> <span class="Statement">int</span> n_MSB2ignore<span class="Special">=</span><span class="Constant">0</span><span class="Special">);</span>
<span class="Statement">extern</span> <span class="Statement">static</span> <span class="Statement">function</span> <span class="Statement">void</span> <span class="Identifier">unpack5</span><span class="Special">(</span><span class="Statement">const</span> <span class="Statement">ref</span> <span class="Statement">bit</span> <span class="Special">[</span><span class="Constant">L</span><span class="Special">-</span><span class="Constant">1</span><span class="Special">:</span><span class="Constant">0</span><span class="Special">]</span> in<span class="Special">,</span> <span class="Statement">ref</span> <span class="Identifier">t5</span><span class="Special">#(</span><span class="Constant">W</span><span class="Special">,</span><span class="Constant">I</span><span class="Special">)</span> out<span class="Special">[],</span> <span class="Statement">input</span> <span class="Statement">int</span> n_MSB2ignore<span class="Special">=</span><span class="Constant">0</span><span class="Special">);</span>

<span class="Statement">endclass</span>

Expand Down Expand Up @@ -987,7 +987,7 @@

<span class="Statement">generate</span>
<span class="Statement">for</span> <span class="Special">(</span><span class="Statement">int</span> i <span class="Special">=</span> <span class="Constant">0</span><span class="Special">;</span> i <span class="Special">&lt;</span> <span class="Constant">9</span><span class="Special">;</span> <span class="Special">++</span>i<span class="Special">)</span> <span class="Statement">begin</span> <span class="Special">:</span> <span class="Special">gen_loop</span>
dut <span class="Identifier">u_dut</span><span class="Special">(.</span><span class="Identifier">in</span><span class="Special">(</span>i<span class="Special">));</span>
dut <span class="Identifier">u_dut</span><span class="Special">(.</span>in<span class="Special">(</span>i<span class="Special">));</span>
<span class="Statement">end</span>
<span class="Statement">endgenerate</span>

Expand Down
12 changes: 12 additions & 0 deletions test/syntax.sv
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ module #(
output wire y
);

othermodule #(.something (a),
.somethingelse(b)
) inst(.p1(), .p2(), .p3 (),
.p4(),
.p5(), .p6(), .p7(),
.p8 ()
.p9 (a)
);

mymod MOD(.IN1(), .IN2(), .OP(),
.OUT());

endmodule

`define DEF_WITH_EQ = 1'b0
Expand Down
12 changes: 12 additions & 0 deletions test/syntax.sv.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@
<span class="Statement">output</span> <span class="Statement">wire</span> y
<span class="Special">);</span>

othermodule <span class="Special">#(.</span>something <span class="Special">(</span>a<span class="Special">),</span>
<span class="Special">.</span>somethingelse<span class="Special">(</span>b<span class="Special">)</span>
<span class="Special">)</span> <span class="Identifier">inst</span><span class="Special">(.</span>p1<span class="Special">(),</span> <span class="Special">.</span>p2<span class="Special">(),</span> <span class="Special">.</span>p3 <span class="Special">(),</span>
<span class="Special">.</span>p4<span class="Special">(),</span>
<span class="Special">.</span>p5<span class="Special">(),</span> <span class="Special">.</span>p6<span class="Special">(),</span> <span class="Special">.</span>p7<span class="Special">(),</span>
<span class="Special">.</span>p8 <span class="Special">()</span>
<span class="Special">.</span>p9 <span class="Special">(</span>a<span class="Special">)</span>
<span class="Special">);</span>

mymod <span class="Identifier">MOD</span><span class="Special">(.</span><span class="Constant">IN1</span><span class="Special">(),</span> <span class="Special">.</span><span class="Constant">IN2</span><span class="Special">(),</span> <span class="Special">.</span><span class="Constant">OP</span><span class="Special">(),</span>
<span class="Special">.</span><span class="Constant">OUT</span><span class="Special">());</span>

<span class="Statement">endmodule</span>

<span class="PreProc">`define</span> <span class="Constant">DEF_WITH_EQ</span> <span class="Special">=</span> <span class="Constant">1'b0</span>
Expand Down

0 comments on commit da9c42e

Please sign in to comment.