@@ -74,11 +74,15 @@ def PREFIX_AND_NODES_RGX(prefix: str, nodes_min: int, nodes_max: int = None) ->
7474 return "^(?P<designator>" + prefix + "§?\\ w+)(?P<nodes>(?:\\ s+[\\ w+-\\ .¥]+){" + nodes_str + "})"
7575
7676
77+ # Optional comment at end of line. Will consume trailing spaces and is to be used on all lines.
78+ COMMENT_RGX = r"(?:\s+;.*)?\\?\s*$"
79+
7780# Potential model name, probably needs expanding. Will require a leading space
7881MODEL_OR_VALUE_RGX = r"\s+(?P<value>[\w\.\-\{\}]+)"
7982
80- # the rest of the line. Cannot be used with PARAM. Will require a leading space, and finish the line
81- ANY_VALUE_RGX = r"\s+(?P<value>.*)$"
83+ # the rest of the line. Cannot be used with PARAM.
84+ # Includes the comment regex and will expect to finish the line.
85+ ANY_VALUE_RGX = r"\s+(?P<value>.*)" + COMMENT_RGX
8286
8387# maybe a value. Will require a leading space
8488MAYBE_VALUE_RGX = r"\s+(?P<value>.*?)"
@@ -108,8 +112,9 @@ def VALUE_RGX(prefix: str, number_regex_suffix: str) -> str:
108112
109113# Parameters expression of the type: key = value.
110114# key must be a full word without signs or dots
111- # Value may be composite, and contain multiple spaces and quotes. Will expect to finish the line.
112- PARAM_RGX = r"(?P<params>(\s+\w+\s*(=\s*[\w\{\}\(\)\-\+\*\/%\.\,'\"\s]+)?)*)?\\?\s*$"
115+ # Value may be composite, and contain multiple spaces and quotes.
116+ # Includes the comment regex and will expect to finish the line.
117+ PARAM_RGX = r"(?P<params>(\s+\w+\s*(=\s*[\w\{\}\(\)\-\+\*\/%\.\,'\"\s]+)?)*)?" + COMMENT_RGX
113118
114119
115120REPLACE_REGEXS = {
@@ -153,11 +158,11 @@ def VALUE_RGX(prefix: str, number_regex_suffix: str) -> str:
153158 # Ixxx n+ n- R=<value>
154159 # Ixxx n+ n- PWL(t1 i1 t2 i2 t3 i3...)
155160 # Ixxx n+ n- wavefile=<filename> [chan=<nnn>]
156- 'I' : PREFIX_AND_NODES_RGX ("I" , 2 ) + MAYBE_VALUE_RGX + r"(?P<params>(\s+\w+\s*=\s*[\w\{\}\(\)\-\+\*\/%\.\,'\"\s]+)*)$" , # Independent Current Source
161+ 'I' : PREFIX_AND_NODES_RGX ("I" , 2 ) + MAYBE_VALUE_RGX + r"(?P<params>(\s+\w+\s*=\s*[\w\{\}\(\)\-\+\*\/%\.\,'\"\s]+)*)" + COMMENT_RGX , # Independent Current Source
157162 # Jxxx D G S <model> [area] [off] [IC=Vds, Vgs] [temp=T]
158163 'J' : PREFIX_AND_NODES_RGX ("J" , 3 ) + MODEL_OR_VALUE_RGX + PARAM_RGX , # JFET
159164 # Kxxx Lyyy Lzzz ... value
160- 'K' : PREFIX_AND_NODES_RGX ("K" , 2 , 99 ) + r"\s+(?P<value>[\+\-]?[0-9\.E+-]+[kmuµnpgt]?).*$" , # Mutual Inductance
165+ 'K' : PREFIX_AND_NODES_RGX ("K" , 2 , 99 ) + r"\s+(?P<value>[\+\-]?[0-9\.E+-]+[kmuµnpgt]?)" + COMMENT_RGX , # Mutual Inductance
161166 # Lxxx n+ n- <value> <mname> <nt=val> <m=val> ...
162167 # Lxxx n+ n- L = 'expression' <tc1=value> <tc2=value>
163168 'L' : PREFIX_AND_NODES_RGX ("L" , 2 ) + VALUE_RGX ("L" , r"(Meg|[kmuµnpgt])?H?\d*" ) + PARAM_RGX , # Inductance
@@ -192,14 +197,14 @@ def VALUE_RGX(prefix: str, number_regex_suffix: str) -> str:
192197 # Vxxx n+ n- PWL(t1 v1 t2 v2 t3 v3...)
193198 # Vxxx n+ n- wavefile=<filename> [chan=<nnn>]
194199 # ex: V1 NC_08 NC_09 PWL(1u 0 +2n 1 +1m 1 +2n 0 +1m 0 +2n -1 +1m -1 +2n 0) AC 1 2 Rser=3 Cpar=4
195- 'V' : PREFIX_AND_NODES_RGX ("V" , 2 ) + MAYBE_VALUE_RGX + r"(?P<params>(\s+\w+\s*=\s*[\w\{\}\(\)\-\+\*\/%\.\,'\"\s]+)*)$" , # Independent Voltage Source
200+ 'V' : PREFIX_AND_NODES_RGX ("V" , 2 ) + MAYBE_VALUE_RGX + r"(?P<params>(\s+\w+\s*=\s*[\w\{\}\(\)\-\+\*\/%\.\,'\"\s]+)*)" + COMMENT_RGX , # Independent Voltage Source
196201 # Wxxx n1 n2 Vnam <model> [on,off]
197202 'W' : PREFIX_AND_NODES_RGX ("W" , 3 ) + ANY_VALUE_RGX , # Current Controlled Switch
198203 # Xxxx n1 n2 n3... <subckt name> [<parameter>=<expression>]
199204 # ex: XU1 NC_01 NC_02 NC_03 NC_04 NC_05 level2 Avol=1Meg GBW=10Meg Slew=10Meg Ilimit=25m Rail=0 Vos=0 En=0 Enk=0 In=0 Ink=0 Rin=500Meg
200205 # XU1 in out1 -V +V out1 OPAx189 bla_v2 =1% bla_sp1=2 bla_sp2 = 3
201206 # XU1 in out1 -V +V out1 GND OPAx189_float
202- 'X' : PREFIX_AND_NODES_RGX ("X" , 1 , 99 ) + MODEL_OR_VALUE_RGX + r"(?:\s+(?P<params>(?:\w+\s*=\s*['\"{]?.*?['\"}]?\s*)+))?\\?\s*$" ,
207+ 'X' : PREFIX_AND_NODES_RGX ("X" , 1 , 99 ) + MODEL_OR_VALUE_RGX + r"(?:\s+(?P<params>(?:\w+\s*=\s*['\"{]?.*?['\"}]?\s*)+))?" + COMMENT_RGX , # Subcircuit Instance
203208 # (ngspice) Yxxx N1 0 N2 0 mname <LEN=LENGTH>
204209 # (qspice) Ynnn N+ N- <frequency1> dF=<value> Ctot=<value> [Q=<value>]
205210 'Y' : PREFIX_AND_NODES_RGX ("Y" , 2 , 4 ) + MODEL_OR_VALUE_RGX + PARAM_RGX , # Single Lossy Transmission Line
0 commit comments