netlistmod 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- netlistmod/__init__.py +211 -0
- netlistmod/dialects.py +25 -0
- netlistmod/document/__init__.py +36 -0
- netlistmod/document/diagnostics.py +474 -0
- netlistmod/document/document.py +255 -0
- netlistmod/document/index.py +523 -0
- netlistmod/document/lines.py +119 -0
- netlistmod/document/model-types.json +18 -0
- netlistmod/document/models.py +43 -0
- netlistmod/document/names.py +51 -0
- netlistmod/document/topology.py +274 -0
- netlistmod/edit/__init__.py +17 -0
- netlistmod/edit/_ops_behavioral.py +62 -0
- netlistmod/edit/_ops_common.py +223 -0
- netlistmod/edit/_ops_controlled.py +59 -0
- netlistmod/edit/_ops_directives.py +246 -0
- netlistmod/edit/_ops_elements.py +281 -0
- netlistmod/edit/_ops_sources.py +244 -0
- netlistmod/edit/_ops_statements.py +84 -0
- netlistmod/edit/api.py +685 -0
- netlistmod/edit/conventions.py +64 -0
- netlistmod/edit/operations.py +77 -0
- netlistmod/edit/placement.py +133 -0
- netlistmod/edit/plan.py +122 -0
- netlistmod/edit/verify.py +184 -0
- netlistmod/errors.py +68 -0
- netlistmod/grammar/__init__.py +5 -0
- netlistmod/grammar/core.lark +547 -0
- netlistmod/grammar/formula-reserved.json +18 -0
- netlistmod/grammar/formula.lark +77 -0
- netlistmod/grammar/formula.py +113 -0
- netlistmod/grammar/formula_ltspice.lark +21 -0
- netlistmod/grammar/loader.py +461 -0
- netlistmod/grammar/ltspice-devices.json +27 -0
- netlistmod/grammar/ltspice.lark +649 -0
- netlistmod/grammar/ngspice-devices.json +28 -0
- netlistmod/grammar/ngspice.lark +571 -0
- netlistmod/model/__init__.py +145 -0
- netlistmod/model/_rules_base.py +109 -0
- netlistmod/model/_rules_behavioral.py +70 -0
- netlistmod/model/_rules_controlled.py +185 -0
- netlistmod/model/_rules_elements.py +412 -0
- netlistmod/model/_rules_sources.py +268 -0
- netlistmod/model/_rules_statements.py +559 -0
- netlistmod/model/_rules_structure.py +136 -0
- netlistmod/model/_tree.py +358 -0
- netlistmod/model/nodes.py +731 -0
- netlistmod/model/transform.py +95 -0
- netlistmod/model/values.py +131 -0
- netlistmod/py.typed +0 -0
- netlistmod/source.py +289 -0
- netlistmod-0.5.0.dist-info/METADATA +94 -0
- netlistmod-0.5.0.dist-info/RECORD +55 -0
- netlistmod-0.5.0.dist-info/WHEEL +4 -0
- netlistmod-0.5.0.dist-info/licenses/LICENSE +21 -0
netlistmod/__init__.py
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"""Source-preserving SPICE netlist editing."""
|
|
2
|
+
|
|
3
|
+
from importlib.metadata import version
|
|
4
|
+
|
|
5
|
+
from netlistmod.dialects import Dialect
|
|
6
|
+
from netlistmod.document import (
|
|
7
|
+
Connection,
|
|
8
|
+
Diagnostic,
|
|
9
|
+
DiagnosticCode,
|
|
10
|
+
ExpressionRead,
|
|
11
|
+
Line,
|
|
12
|
+
Lines,
|
|
13
|
+
Net,
|
|
14
|
+
Reference,
|
|
15
|
+
Scope,
|
|
16
|
+
TopologySignature,
|
|
17
|
+
TopologyView,
|
|
18
|
+
)
|
|
19
|
+
from netlistmod.edit import (
|
|
20
|
+
Batch,
|
|
21
|
+
DirectiveEditor,
|
|
22
|
+
Edit,
|
|
23
|
+
EditPlan,
|
|
24
|
+
Netlist,
|
|
25
|
+
ParamTable,
|
|
26
|
+
Placement,
|
|
27
|
+
SlotCheck,
|
|
28
|
+
apply_edits,
|
|
29
|
+
)
|
|
30
|
+
from netlistmod.errors import (
|
|
31
|
+
EditError,
|
|
32
|
+
EncodingError,
|
|
33
|
+
ParseError,
|
|
34
|
+
SpiceNetlistError,
|
|
35
|
+
TopologyError,
|
|
36
|
+
TopologyViolation,
|
|
37
|
+
UnsupportedConstruct,
|
|
38
|
+
)
|
|
39
|
+
from netlistmod.model import (
|
|
40
|
+
AcDirective,
|
|
41
|
+
AcSpec,
|
|
42
|
+
BehavioralSource,
|
|
43
|
+
BipolarTransistor,
|
|
44
|
+
BlankLine,
|
|
45
|
+
Capacitor,
|
|
46
|
+
Cccs,
|
|
47
|
+
Ccvs,
|
|
48
|
+
CommentLine,
|
|
49
|
+
Component,
|
|
50
|
+
ControlledSource,
|
|
51
|
+
CurrentSource,
|
|
52
|
+
CurrentSwitch,
|
|
53
|
+
DcDirective,
|
|
54
|
+
DcSweep,
|
|
55
|
+
Diode,
|
|
56
|
+
Directive,
|
|
57
|
+
ElementReference,
|
|
58
|
+
End,
|
|
59
|
+
EndsLine,
|
|
60
|
+
Flag,
|
|
61
|
+
Formula,
|
|
62
|
+
GlobalDirective,
|
|
63
|
+
IcDirective,
|
|
64
|
+
Identifier,
|
|
65
|
+
Inductor,
|
|
66
|
+
Jfet,
|
|
67
|
+
MeasureDirective,
|
|
68
|
+
Mesfet,
|
|
69
|
+
ModelReference,
|
|
70
|
+
ModelStatement,
|
|
71
|
+
Mosfet,
|
|
72
|
+
MutualCoupling,
|
|
73
|
+
Node,
|
|
74
|
+
NodeCondition,
|
|
75
|
+
NodesetDirective,
|
|
76
|
+
NumericValue,
|
|
77
|
+
OpaqueBlock,
|
|
78
|
+
OpaqueStatement,
|
|
79
|
+
OpDirective,
|
|
80
|
+
OptionItem,
|
|
81
|
+
OptionsDirective,
|
|
82
|
+
OutputVector,
|
|
83
|
+
ParamAssignment,
|
|
84
|
+
ParamStatement,
|
|
85
|
+
ParseResult,
|
|
86
|
+
Resistor,
|
|
87
|
+
SaveDirective,
|
|
88
|
+
SourceSpec,
|
|
89
|
+
StepDirective,
|
|
90
|
+
SubcktDefinition,
|
|
91
|
+
SubcktInstance,
|
|
92
|
+
SubcktReference,
|
|
93
|
+
Switch,
|
|
94
|
+
TempDirective,
|
|
95
|
+
Title,
|
|
96
|
+
TitleDirective,
|
|
97
|
+
TranDirective,
|
|
98
|
+
Transistor,
|
|
99
|
+
UnknownDirective,
|
|
100
|
+
Value,
|
|
101
|
+
ValueList,
|
|
102
|
+
Vccs,
|
|
103
|
+
Vcvs,
|
|
104
|
+
VoltageSource,
|
|
105
|
+
VoltageSwitch,
|
|
106
|
+
)
|
|
107
|
+
from netlistmod.model.transform import parse
|
|
108
|
+
from netlistmod.source import SourceText, Span
|
|
109
|
+
|
|
110
|
+
__version__ = version("netlistmod")
|
|
111
|
+
|
|
112
|
+
__all__ = [
|
|
113
|
+
"AcDirective",
|
|
114
|
+
"AcSpec",
|
|
115
|
+
"Batch",
|
|
116
|
+
"BlankLine",
|
|
117
|
+
"Capacitor",
|
|
118
|
+
"CommentLine",
|
|
119
|
+
"Component",
|
|
120
|
+
"Connection",
|
|
121
|
+
"ExpressionRead",
|
|
122
|
+
"CurrentSource",
|
|
123
|
+
"DcDirective",
|
|
124
|
+
"DcSweep",
|
|
125
|
+
"Diagnostic",
|
|
126
|
+
"DiagnosticCode",
|
|
127
|
+
"Dialect",
|
|
128
|
+
"BehavioralSource",
|
|
129
|
+
"BipolarTransistor",
|
|
130
|
+
"Diode",
|
|
131
|
+
"Jfet",
|
|
132
|
+
"Mesfet",
|
|
133
|
+
"Mosfet",
|
|
134
|
+
"Directive",
|
|
135
|
+
"DirectiveEditor",
|
|
136
|
+
"Edit",
|
|
137
|
+
"EditError",
|
|
138
|
+
"EditPlan",
|
|
139
|
+
"ElementReference",
|
|
140
|
+
"EncodingError",
|
|
141
|
+
"End",
|
|
142
|
+
"EndsLine",
|
|
143
|
+
"Flag",
|
|
144
|
+
"Formula",
|
|
145
|
+
"GlobalDirective",
|
|
146
|
+
"IcDirective",
|
|
147
|
+
"Identifier",
|
|
148
|
+
"Inductor",
|
|
149
|
+
"Line",
|
|
150
|
+
"Lines",
|
|
151
|
+
"MeasureDirective",
|
|
152
|
+
"ModelReference",
|
|
153
|
+
"ModelStatement",
|
|
154
|
+
"MutualCoupling",
|
|
155
|
+
"Net",
|
|
156
|
+
"Netlist",
|
|
157
|
+
"Node",
|
|
158
|
+
"NodeCondition",
|
|
159
|
+
"NodesetDirective",
|
|
160
|
+
"NumericValue",
|
|
161
|
+
"OpDirective",
|
|
162
|
+
"OpaqueBlock",
|
|
163
|
+
"OpaqueStatement",
|
|
164
|
+
"OptionItem",
|
|
165
|
+
"OptionsDirective",
|
|
166
|
+
"OutputVector",
|
|
167
|
+
"ParamAssignment",
|
|
168
|
+
"ParamStatement",
|
|
169
|
+
"ParamTable",
|
|
170
|
+
"ParseError",
|
|
171
|
+
"ParseResult",
|
|
172
|
+
"Placement",
|
|
173
|
+
"Reference",
|
|
174
|
+
"Resistor",
|
|
175
|
+
"SaveDirective",
|
|
176
|
+
"StepDirective",
|
|
177
|
+
"Scope",
|
|
178
|
+
"SlotCheck",
|
|
179
|
+
"SourceText",
|
|
180
|
+
"Span",
|
|
181
|
+
"SpiceNetlistError",
|
|
182
|
+
"SubcktDefinition",
|
|
183
|
+
"SourceSpec",
|
|
184
|
+
"SubcktInstance",
|
|
185
|
+
"Transistor",
|
|
186
|
+
"Cccs",
|
|
187
|
+
"ControlledSource",
|
|
188
|
+
"Ccvs",
|
|
189
|
+
"CurrentSwitch",
|
|
190
|
+
"Switch",
|
|
191
|
+
"Vccs",
|
|
192
|
+
"Vcvs",
|
|
193
|
+
"VoltageSwitch",
|
|
194
|
+
"SubcktReference",
|
|
195
|
+
"TempDirective",
|
|
196
|
+
"Title",
|
|
197
|
+
"TitleDirective",
|
|
198
|
+
"TopologyError",
|
|
199
|
+
"TopologySignature",
|
|
200
|
+
"TopologyView",
|
|
201
|
+
"TopologyViolation",
|
|
202
|
+
"TranDirective",
|
|
203
|
+
"UnknownDirective",
|
|
204
|
+
"UnsupportedConstruct",
|
|
205
|
+
"Value",
|
|
206
|
+
"ValueList",
|
|
207
|
+
"VoltageSource",
|
|
208
|
+
"__version__",
|
|
209
|
+
"apply_edits",
|
|
210
|
+
"parse",
|
|
211
|
+
]
|
netlistmod/dialects.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""SPICE dialect names supported by netlistmod."""
|
|
2
|
+
|
|
3
|
+
from enum import Enum
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Dialect(str, Enum):
|
|
7
|
+
"""A supported SPICE dialect; callers must select one explicitly."""
|
|
8
|
+
|
|
9
|
+
NGSPICE = "ngspice"
|
|
10
|
+
LTSPICE = "ltspice"
|
|
11
|
+
|
|
12
|
+
@property
|
|
13
|
+
def display_name(self) -> str:
|
|
14
|
+
"""Return the conventional display name for this dialect."""
|
|
15
|
+
return "LTspice" if self is Dialect.LTSPICE else "ngspice"
|
|
16
|
+
|
|
17
|
+
@classmethod
|
|
18
|
+
def from_name(cls, name: str) -> "Dialect":
|
|
19
|
+
"""Parse a dialect value or enum name, without regard to case."""
|
|
20
|
+
normalized = name.strip().casefold()
|
|
21
|
+
for dialect in cls:
|
|
22
|
+
if normalized in {dialect.value.casefold(), dialect.name.casefold()}:
|
|
23
|
+
return dialect
|
|
24
|
+
valid_names = ", ".join(dialect.value for dialect in cls)
|
|
25
|
+
raise ValueError(f"Unknown dialect {name!r}; valid names are: {valid_names}")
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Netlist document and read-only indexes."""
|
|
2
|
+
|
|
3
|
+
from netlistmod.document.diagnostics import Diagnostic, DiagnosticCode, Severity
|
|
4
|
+
from netlistmod.document.document import Netlist
|
|
5
|
+
from netlistmod.document.index import Reference, ReferenceKind, Scope
|
|
6
|
+
from netlistmod.document.lines import Line, Lines, ScopePath
|
|
7
|
+
from netlistmod.document.names import GROUND, fold, is_ground, net_name
|
|
8
|
+
from netlistmod.document.topology import (
|
|
9
|
+
Connection,
|
|
10
|
+
ExpressionRead,
|
|
11
|
+
Net,
|
|
12
|
+
TopologySignature,
|
|
13
|
+
TopologyView,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"GROUND",
|
|
18
|
+
"Connection",
|
|
19
|
+
"ExpressionRead",
|
|
20
|
+
"Diagnostic",
|
|
21
|
+
"DiagnosticCode",
|
|
22
|
+
"Line",
|
|
23
|
+
"Lines",
|
|
24
|
+
"Net",
|
|
25
|
+
"Netlist",
|
|
26
|
+
"Reference",
|
|
27
|
+
"ReferenceKind",
|
|
28
|
+
"Scope",
|
|
29
|
+
"ScopePath",
|
|
30
|
+
"Severity",
|
|
31
|
+
"TopologySignature",
|
|
32
|
+
"TopologyView",
|
|
33
|
+
"fold",
|
|
34
|
+
"is_ground",
|
|
35
|
+
"net_name",
|
|
36
|
+
]
|