11.1.10.9. Parser_jmgc

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.

SPICE is case insensitive.

class PySpice.Spice.Parser_jmgc.CircuitStatement(title)[source]

Bases: PySpice.Spice.Parser_jmgc.Statement

This class implements a circuit definition.

Spice syntax:

Title ...
append(statement)[source]

Append a statement to the statement’s list.

append_model(statement)[source]

Append a model to the statement’s list.

append_param(statement)[source]

Append a param to the statement’s list.

append_subcircuit(statement)[source]

Append a subcircuit to the statement’s list.

build(ground=0)[source]
property models

Models of the circuit.

property name

Name of the circuit.

property params

Parameters of the circuit.

property subcircuits

Subcircuits of the circuit.

property title

Title of the circuit.

to_python(ground=0)[source]
class PySpice.Spice.Parser_jmgc.Comment(line, statement=None)[source]

Bases: PySpice.Spice.Parser_jmgc.Statement

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

Bases: PySpice.Spice.Parser_jmgc.Statement

This class implements an element definition.

“{ expression }” are allowed in device line.

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

Name of the element

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

Bases: PySpice.Spice.Parser_jmgc.Statement

This class implements a include definition.

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

Bases: object

This class implements a line in the netlist.

append(line)[source]
property comment
static get_kwarg(text)[source]
property 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_element(prefix)[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_keyword(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. The parenthesis can be omitted.

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

Bases: PySpice.Spice.Parser_jmgc.Statement

This class implements a model definition.

Spice syntax:

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

Name of the model

to_python(netlist_name)[source]
class PySpice.Spice.Parser_jmgc.Parameter(line)[source]

Bases: PySpice.Spice.Parser_jmgc.Statement

This class implements a parameter definition.

Spice syntax:

.param name=expr
build(circuit)[source]
property name

Name of the model

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

Bases: NameError

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

Bases: object

This class represents a device prefix.

property single
class PySpice.Spice.Parser_jmgc.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:

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).

property circuit

Circuit statements.

is_only_model()[source]
is_only_subcircuit()[source]
property models

Models of the sub-circuit.

static netlist_to_python(netlist_name, statements, ground=0)[source]
property subcircuits

Subcircuits of the sub-circuit.

to_python_code(ground=0)[source]
class PySpice.Spice.Parser_jmgc.Statement(line, statement=None)[source]

Bases: object

This base 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_jmgc.SubCircuitStatement(line)[source]

Bases: PySpice.Spice.Parser_jmgc.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.

append_model(statement)[source]

Append a model to the statement’s list.

append_param(statement)[source]

Append a param to the statement’s list.

append_subcircuit(statement)[source]

Append a model to the statement’s list.

build(ground=0, parent=None)[source]
property models

Models of the sub-circuit.

property name

Name of the sub-circuit.

property nodes

Nodes of the sub-circuit.

property params

Params of the sub-circuit.

property subcircuits

Subcircuits of the sub-circuit.

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

Bases: PySpice.Spice.Parser_jmgc.Statement

This class implements a title definition.