Commit 7e4acd86 authored by Fabrice Salvaire's avatar Fabrice Salvaire

improved Ast

parent 82f91d13
......@@ -563,7 +563,12 @@ class Word(LineItem):
def ansi_str(self):
if self._letter in 'GM':
if self._machine:
gm = self._machine.GM_LETTERS
else:
gm = 'GM'
if self._letter in gm:
return Line.ANSI_G(str(self))
else:
return Line.ANSI_X(self._letter) + Line.ANSI_VALUE(str(self._value))
......@@ -577,15 +582,24 @@ class Word(LineItem):
##############################################
@property
def is_valid_gcode(self):
def is_gm_gcode(self):
self._check_machine()
return str(self) in self._machine.config.gcodes
return self._machine.is_gm_word(self)
##############################################
@property
def is_valid_gcode(self):
if self.is_gm_gcode:
return str(self) in self._machine.config.gcodes
else:
return True
##############################################
@property
def meaning(self):
if self.is_valid_gcode:
if self.is_gm_gcode:
return self._machine.config.gcodes[str(self)].meaning
else:
return self._machine.config.letters[self.letter].meaning
......@@ -594,7 +608,7 @@ class Word(LineItem):
@property
def modal_group(self):
if self.is_valid_gcode:
if self.is_gm_gcode:
return self._machine.config.modal_groups[str(self)]
else:
return None
......@@ -603,7 +617,7 @@ class Word(LineItem):
@property
def execution_order(self):
if self.is_valid_gcode:
if self.is_gm_gcode:
return self._machine.config.execution_order[str(self)]
else:
return None
......
......@@ -40,6 +40,8 @@ class GcodeMachine:
PARSER_CLS = GcodeParser
GM_LETTERS = 'GM'
##############################################
def __init__(self):
......@@ -85,3 +87,11 @@ class GcodeMachine:
pass
##############################################
def is_gm_letter(self, letter):
return letter in self.GM_LETTERS
##############################################
def is_gm_word(self, word):
return self.is_gm_letter(word.letter)
......@@ -69,11 +69,12 @@ for line in program:
# print(line.ansi_str()) # Fixme: pyterate
print(str(line))
for word in line.iter_on_word():
if word.is_valid_gcode:
if word.is_gm_gcode:
margin = ' '*9
print(meaning_format.format(str(word), word.meaning))
print(margin + 'Modal group: {}'.format(word.modal_group.meaning))
print(margin + 'Execution order: {}'.format(word.execution_order.index))
print(margin + 'Valid G-code: {}'.format(word.is_valid_gcode))
else:
print(meaning_format.format(word.letter, word.meaning))
#o#
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment