11.1.9.8. Parser

This module implements a partial SPICE netlist parser.

See the cir2py tool for an example of usage of the parser.

It would be difficult to implement a full parser for Ngspice since the syntax is mainly contextual.

class PySpice.Spice.Parser.Comment(line, statement=None)[source]

Bases: PySpice.Spice.Parser.Statement

class PySpice.Spice.Parser.Element(line)[source]

Bases: PySpice.Spice.Parser.Statement

This class implements an element definition.

“{ expression }” are allowed in device line.

build(circuit, ground=0)[source]
name

Name of the element

to_python(netlist_name, ground=0)[source]
translate_ground_node(ground)[source]
class PySpice.Spice.Parser.Include(line)[source]

Bases: PySpice.Spice.Parser.Statement

This class implements a include definition.

to_python(netlist_name)[source]
class PySpice.Spice.Parser.Line(line, line_range, end_of_line_comment)[source]

Bases: object

This class implements a line in the netlist.

append(line)[source]
comment
static get_kwarg(text)[source]
is_comment
lower_case_statement(statement)[source]

Lower case the statement

read_words(start_location, number_of_words)[source]

Read a fixed number of words separated by space.

right_of(text)[source]
split_line(keyword)[source]

Split the line according to the following pattern:

keyword parameter1 parameter2 ... key1=value1 key2=value2 ...

Return the list of parameters and the dictionary.

split_words(start_location, until=None)[source]
class PySpice.Spice.Parser.Model(line)[source]

Bases: PySpice.Spice.Parser.Statement

This class implements a model definition.

Spice syntax:

.model mname type (pname1=pval1 pname2=pval2)
build(circuit)[source]
name

Name of the model

to_python(netlist_name)[source]
exception PySpice.Spice.Parser.ParseError[source]

Bases: NameError

class PySpice.Spice.Parser.PrefixData(prefix, classes)[source]

Bases: object

This class represents a device prefix.

single
class PySpice.Spice.Parser.SpiceParser(path=None, source=None, end_of_line_comment=('$', '//', ';'))[source]

Bases: object

This class parse a Spice netlist file and build a syntax tree.

Public Attributes:

circuit

models

subcircuits

build_circuit(ground=0)[source]

Build a Circuit instance.

Use the ground parameter to specify the node which must be translated to 0 (SPICE ground node).

is_only_model()[source]
is_only_subcircuit()[source]
static netlist_to_python(netlist_name, statements, ground=0)[source]
to_python_code(ground=0)[source]
class PySpice.Spice.Parser.Statement(line, statement=None)[source]

Bases: object

This class implements a statement, in fact a line in a Spice netlist.

join_args(args)[source]
kwargs_to_python(kwargs)[source]
value_to_python(x)[source]
values_to_python(values)[source]
class PySpice.Spice.Parser.SubCircuitStatement(line)[source]

Bases: PySpice.Spice.Parser.Statement

This class implements a sub-circuit definition.

Spice syntax:

.SUBCKT name node1 ... param1=value1 ...
append(statement)[source]

Append a statement to the statement’s list.

build(ground=0)[source]
name

Name of the sub-circuit.

nodes

Nodes of the sub-circuit.

to_python(ground=0)[source]
class PySpice.Spice.Parser.Title(line)[source]

Bases: PySpice.Spice.Parser.Statement

This class implements a title definition.