veripool / verilog-mode

Verilog-Mode for Emacs with Indentation, Hightlighting and AUTOs. Master repository for pushing to GNU, verilog.com and veripool.org.
http://veripool.org/verilog-mode
GNU General Public License v3.0
253 stars 90 forks source link

How to access multiple capture groups in AUTOINST REGEXP? #1662

Closed veripoolbot closed 4 years ago

veripoolbot commented 4 years ago

Author Name: Shareef Jalloq Original Redmine Issue: 1662 from https://www.veripool.org


Hi,

I'm wanting to pull out a number of terms from an AUTOINST regexp but can't find an example. If I have two module instance names of "u_tx0" and "utx1" with a regext of "(tx([0-9]))", I'm expecting to see two capture groups. The first would have the full "tx0" or "tx1" ; the second "0" and "1".

How do I access the second capture group? The documentation/manual talks about using multiple groups but only gives the example of using @ to get the first group.

Shareef.

veripoolbot commented 4 years ago

Original Redmine Comment Author Name: Wilson Snyder (@wsnyder) Original Date: 2020-01-27T12:03:24Z


Use backslash 1, 2, 3 etc. Please see https://github.com/veripool/verilog-mode/blob/master/FAQ.adoc#how-do-i-use-auto_template-to-match-multiple-port-names

veripoolbot commented 4 years ago

Original Redmine Comment Author Name: Shareef Jalloq Original Date: 2020-01-27T12:30:14Z


What about in the instance name rather than the ports? Or what happens if I have two lots of regex?

/* mymodule AUTO_TEMPLATE "\(tx\([0-9]+\)\)"
.\(CTRL[0-9]+\) (@_\1[X]),
); */

In the above example, I want to replace X with the second capture group from the instance name.

I want the following:


mymodule
  u_tx5 (.CTRL0 (tx5_CTRL0[5]));
veripoolbot commented 4 years ago

Original Redmine Comment Author Name: Wilson Snyder (@wsnyder) Original Date: 2020-01-27T13:17:43Z


Sorry, thought you were referring to a template of a AUTOINST. The cell name regexp attached to the AUTOINST itself only uses \1 as @. For anything else you need lisp code using vl-cell, see https://github.com/veripool/verilog-mode/blob/master/FAQ.adoc#how-do-i-have-auto_template-use-the-second-number-in-a-instance-name