9.1.1.5.1. Ast

Module to implement an AST for RS-274 G-code.

All classes are clonable.

class PythonicGcodeMachine.Gcode.Rs274.Ast.Program(machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.MachineMixin

Class to implement a G-code program

Usage:

program = Program()
program += line

# Array interface
for line in programs:
    print(line)

str(program)

program2 = program.clone()
clone()[source]
iter_on_not_deleted()[source]
push(line)[source]
class PythonicGcodeMachine.Gcode.Rs274.Ast.Line(deleted=False, line_number=None, comment=None, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.MachineMixin

Class to implement a G-code line

Usage:

line = Line(deleted=False, line_number=1, comment='a comment')

line.deleted = True
print(line.deleted)
# same apply for line_number and comment

# Is line not deleted ?
bool(line)

# Push some items
# Note: order doesn't matter, see RS-274 for details
line += Word('G', 0)
line += Comment('move')
line += Word('X', 10)
line += Comment('Y value')
line += Word('Y', 20.)
line += ParameterSetting('1', 1.2)

# using expression, AST way
line += Word('Z', Addition(30, Multiply(Parameter(100), Cosine(30))))
# string way
line += Word('Z', '[30 + [#100 * cos[30]]]')

# Array interface
for item in line:
    print(item)

str(line)
print(line.ansi_str()) # use ANSI colors, see Line.ANSI_... attributes

a_line = line.clone()

Values can be passed as:

  • int or float,
  • AST for expression,
  • any object that “str” evaluate to a valid G-code expression.

As a shortcut, a G/M-code operation can be passed as string:

line += 'G0'

Expression can be evaluated using float(obj.value), excepted when we must access a parameter value.

ANSI_COMMENT = functools.partial(<function color>, fg='green')
ANSI_DELETED = functools.partial(<function color>, fg='red')
ANSI_G = functools.partial(<function color>, fg='red')
ANSI_LINE_NUMBER = functools.partial(<function color>, fg='blue')
ANSI_SETTING = functools.partial(<function color>, fg='blue')
ANSI_VALUE = functools.partial(<function color>, fg='black')
ANSI_X = functools.partial(<function color>, fg='blue')
ansi_str()[source]
check_modal_group()[source]
clone()[source]
comment
deleted
iter_in_order()[source]
iter_on_g_word()[source]
iter_on_gm_word()[source]
iter_on_letter(letters)[source]
iter_on_m_word()[source]
iter_on_setting()[source]
iter_on_word()[source]
iter_on_x_word()[source]
line_number
push(item)[source]

Method to push a valid item, a ‘G/Mxxx’ shortcut string, a list or tuple

push_items(iterable)[source]

Method to push an iterable

remove_comment()[source]
remove_line_number()[source]
toggle()[source]

Toggle deleted flag

class PythonicGcodeMachine.Gcode.Rs274.Ast.Comment(text, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.LineItem

Class to implement comment

ansi_str()[source]
clone()[source]
set(text)[source]
text
class PythonicGcodeMachine.Gcode.Rs274.Ast.Word(letter, value, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.LineItem

Class to implement word

LETTERS = ('A', 'B', 'C', 'D', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'P', 'Q', 'R', 'S', 'T', 'X', 'Y', 'Z')
WORD_RE = re.compile('(G|M)(\\d+)')
ansi_str()[source]
clone()[source]
execution_order
classmethod from_str(obj)[source]
gcode_info
is_axis_gcode
is_gm_gcode
is_valid_gcode
letter
meaning
modal_group
value
class PythonicGcodeMachine.Gcode.Rs274.Ast.ParameterMixin(parameter)[source]

Bases: object

Mixin for parameter

parameter
class PythonicGcodeMachine.Gcode.Rs274.Ast.ParameterSetting(parameter, value, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.LineItem, PythonicGcodeMachine.Gcode.Rs274.Ast.ParameterMixin

Class to implement parameter setting

ansi_str()[source]
clone()[source]
value
class PythonicGcodeMachine.Gcode.Rs274.Ast.Parameter(parameter, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.RealValue, PythonicGcodeMachine.Gcode.Rs274.Ast.ParameterMixin

Class to implement parameter

clone()[source]
class PythonicGcodeMachine.Gcode.Rs274.Ast.AbsoluteValue(arg, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.UnaryOperation

class PythonicGcodeMachine.Gcode.Rs274.Ast.ArcCosine(arg, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.UnaryOperation

class PythonicGcodeMachine.Gcode.Rs274.Ast.ArcSine(arg, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.UnaryOperation

class PythonicGcodeMachine.Gcode.Rs274.Ast.ArcTangent(arg, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.UnaryOperation

class PythonicGcodeMachine.Gcode.Rs274.Ast.Cosine(arg, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.UnaryOperation

class PythonicGcodeMachine.Gcode.Rs274.Ast.ERaisedTo(arg, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.UnaryOperation

class PythonicGcodeMachine.Gcode.Rs274.Ast.FixDown(arg, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.UnaryOperation

class PythonicGcodeMachine.Gcode.Rs274.Ast.FixUp(arg, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.UnaryOperation

class PythonicGcodeMachine.Gcode.Rs274.Ast.NaturalLogOf(arg, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.UnaryOperation

class PythonicGcodeMachine.Gcode.Rs274.Ast.Round(arg, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.UnaryOperation

class PythonicGcodeMachine.Gcode.Rs274.Ast.Sine(arg, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.UnaryOperation

class PythonicGcodeMachine.Gcode.Rs274.Ast.SquareRoot(arg, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.UnaryOperation

class PythonicGcodeMachine.Gcode.Rs274.Ast.Tangent(arg, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.UnaryOperation

class PythonicGcodeMachine.Gcode.Rs274.Ast.Power(arg1, arg2, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.BinaryOperation

class PythonicGcodeMachine.Gcode.Rs274.Ast.DividedBy(arg1, arg2, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.BinaryOperation

class PythonicGcodeMachine.Gcode.Rs274.Ast.Modulo(arg1, arg2, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.BinaryOperation

class PythonicGcodeMachine.Gcode.Rs274.Ast.Multiply(arg1, arg2, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.BinaryOperation

class PythonicGcodeMachine.Gcode.Rs274.Ast.And(arg1, arg2, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.BinaryOperation

class PythonicGcodeMachine.Gcode.Rs274.Ast.ExclusiveOr(arg1, arg2, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.BinaryOperation

class PythonicGcodeMachine.Gcode.Rs274.Ast.Subtraction(arg1, arg2, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.BinaryOperation

class PythonicGcodeMachine.Gcode.Rs274.Ast.Or(arg1, arg2, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.BinaryOperation

class PythonicGcodeMachine.Gcode.Rs274.Ast.Addition(arg1, arg2, machine=None)[source]

Bases: PythonicGcodeMachine.Gcode.Rs274.Ast.BinaryOperation