Skip to content

grammar

The grammar module contains the Gerber X3 grammar implemented using the pyparsing library.

Optimization

Bases: IntFlag

Namespace class holding optimization level constants.

SyntaxSwitches

Bases: BaseModel

The SyntaxSwitches class contains switches for toggling support for different variants of Gerber derived grammars not compatible with Gerber X3.

allow_d01_without_code class-attribute instance-attribute

allow_d01_without_code: bool = True

Allow D01 commands with D01 literal omitted.

Example:
X2331205Y10807331I4J-31018*

allow_non_standalone_d_codes class-attribute instance-attribute

allow_non_standalone_d_codes: bool = True

Allow G codes merged with D codes.

Example:
G01X2241001Y10806845D02*

Grammar

Internal representation of the Gerber X3 grammar.

build

build() -> ParserElement

Build the grammar.

build_resilient

build_resilient() -> ParserElement

Build the grammar.

get_cls

get_cls(node_cls: Type[T]) -> Type[T]

Get the class of the node.

string

string() -> ParserElement

Create a parser element capable of parsing strings.

comma

comma() -> ParserElement

Create a parser element capable of parsing commas.

name

name() -> ParserElement

Create a parser element capable of parsing names.

user_name

user_name() -> ParserElement

Create a parser element capable of parsing user attribute names.

field

field() -> ParserElement

Create a parser element capable of parsing user attribute names.

double

double() -> ParserElement

Create a parser element capable of parsing doubles.

integer

integer() -> ParserElement

Create a parser element capable of parsing integers.

boolean

boolean() -> ParserElement

Create a parser element capable of parsing integers.

aperture_id

aperture_id() -> ParserElement

Create a parser element capable of parsing aperture identifiers.

make_unpack_callback

make_unpack_callback(
    node_type: Type[Node], **kwargs: Any
) -> Callable[[str, int, ParseResults], Node]

Create a callback for unpacking the results of the parser.

aperture

aperture() -> ParserElement

Create a parser element capable of parsing apertures.

aperture_block

aperture_block() -> ParserElement

Create a parser element capable of parsing aperture blocks.

ab_open

ab_open() -> ParserElement

Create a parser element capable of parsing AB-open.

ab_close

ab_close() -> ParserElement

Create a parser element capable of parsing AB-close.

macro

macro() -> ParserElement

Create a parser element capable of parsing macros.

am_open

am_open() -> ParserElement

Create a parser element capable of parsing AM-open.

am_close

am_close() -> ParserElement

Create a parser element capable of parsing AM-close.

step_repeat

step_repeat() -> ParserElement

Create a parser element capable of parsing step repeats.

sr_open

sr_open() -> ParserElement

Create a parser element capable of parsing SR-open.

sr_close

sr_close() -> ParserElement

Create a parser element capable of parsing SR-close.

add_aperture

add_aperture() -> ParserElement

Create a parser element capable of parsing add-aperture commands.

add_aperture_circle

add_aperture_circle() -> ParserElement

Create a parser element capable of parsing add-aperture-circle commands.

add_aperture_rectangle

add_aperture_rectangle(
    symbol: Literal["R", "O"], cls: Type[Node]
) -> ParserElement

Create a parser element capable of parsing add-aperture-rectangle commands.

add_aperture_polygon

add_aperture_polygon() -> ParserElement

Create a parser element capable of parsing add-aperture-polygon commands.

add_aperture_macro

add_aperture_macro() -> ParserElement

Create a parser element capable of parsing add-aperture-polygon commands.

attribute

attribute() -> ParserElement

Create a parser element capable of parsing attributes.

ta

ta() -> ParserElement

Create a parser element capable of parsing TA attributes.

td

td() -> ParserElement

Create a parser element capable of parsing TD attributes.

tf

tf() -> ParserElement

Create a parser element capable of parsing TF attributes.

to

to() -> ParserElement

Create a parser element capable of parsing TO attributes.

d_codes_standalone

d_codes_standalone() -> ParserElement

Create a parser element capable of parsing standalone D-codes.

d_codes_non_standalone

d_codes_non_standalone() -> ParserElement

Create a parser element capable of parsing standalone D-codes.

g_codes

g_codes() -> ParserElement

Create a parser element capable of parsing G-codes.

load_commands

load_commands() -> ParserElement

Create a parser element capable of parsing Load-commands.

ln

ln() -> ParserElement

Create a parser for the LN command.

lp

lp() -> ParserElement

Create a parser for the LP command.

lr

lr() -> ParserElement

Create a parser for the LR command.

ls

ls() -> ParserElement

Create a parser for the LS command.

lm

lm() -> ParserElement

Create a parser for the LM command.

m_codes

m_codes() -> ParserElement

Create a parser element capable of parsing M-codes.

m

m(value: int, cls: Type[Node]) -> ParserElement

Create a parser element capable of parsing particular D-code.

expression

expression() -> ParserElement

Create a parser element capable of parsing expressions.

constant

constant() -> ParserElement

Create a parser element capable of parsing constants.

variable

variable() -> ParserElement

Create a parser element capable of parsing variables.

assignment

assignment() -> ParserElement

Create a parser element capable of parsing assignments.

primitives

primitives() -> ParserElement

Create a parser element capable of parsing macro primitives.

primitive

primitive(
    cls: Type[Node], code: int, fields: ParserElement
) -> ParserElement

Create a parser element capable of parsing a primitive.

properties

properties() -> ParserElement

Create a parser element capable of parsing Properties-commands.

fs

fs() -> ParserElement

Create a parser for the FS command.

ip

ip() -> ParserElement

Create a parser for the IP command.

ir

ir() -> ParserElement

Create a parser for the IR command.

mo

mo() -> ParserElement

Create a parser for the MO command.

of

of() -> ParserElement

Create a parser for the MO command.

as_

as_() -> ParserElement

Create a parser element capable of parsing AS-commands.

mi

mi() -> ParserElement

Create a parser for the MI command.

in_

in_() -> ParserElement

Create a parser for the IN command.

sf

sf() -> ParserElement

Create a parser for the SF command.

take_only

take_only(expr: ParserElement, name: str) -> ParserElement

Add parse action to extract single named parse result from a parse result.