Bases: ExtendedCommandToken
Wrapper for set unit mode token.
Sets the unit to mm or inch.
Source code in src/pygerber/gerberx3/tokenizer/tokens/mo_unit_mode.py
| class UnitMode(ExtendedCommandToken):
"""Wrapper for set unit mode token.
Sets the unit to mm or inch.
"""
def __init__(self, string: str, location: int, unit: Unit) -> None:
super().__init__(string, location)
self.unit = unit
@classmethod
def new(cls, string: str, location: int, tokens: ParseResults) -> Self:
"""Create instance of this class.
Created to be used as callback in `ParserElement.set_parse_action()`.
"""
unit: Unit = Unit(tokens["unit"])
return cls(string=string, location=location, unit=unit)
def parser2_visit_token(self, context: Parser2Context) -> None:
"""Perform actions on the context implicated by this token."""
context.get_hooks().unit_mode.pre_parser_visit_token(self, context)
context.get_hooks().unit_mode.on_parser_visit_token(self, context)
context.get_hooks().unit_mode.post_parser_visit_token(self, context)
def get_gerber_code(
self,
indent: str = "", # noqa: ARG002
endline: str = "\n", # noqa: ARG002
) -> str:
"""Get gerber code represented by this token."""
return f"MO{self.unit.value}"
|
new
classmethod
new(
string: str, location: int, tokens: ParseResults
) -> Self
Create instance of this class.
Created to be used as callback in ParserElement.set_parse_action().
Source code in src/pygerber/gerberx3/tokenizer/tokens/mo_unit_mode.py
| @classmethod
def new(cls, string: str, location: int, tokens: ParseResults) -> Self:
"""Create instance of this class.
Created to be used as callback in `ParserElement.set_parse_action()`.
"""
unit: Unit = Unit(tokens["unit"])
return cls(string=string, location=location, unit=unit)
|
parser2_visit_token
parser2_visit_token(context: Parser2Context) -> None
Perform actions on the context implicated by this token.
Source code in src/pygerber/gerberx3/tokenizer/tokens/mo_unit_mode.py
| def parser2_visit_token(self, context: Parser2Context) -> None:
"""Perform actions on the context implicated by this token."""
context.get_hooks().unit_mode.pre_parser_visit_token(self, context)
context.get_hooks().unit_mode.on_parser_visit_token(self, context)
context.get_hooks().unit_mode.post_parser_visit_token(self, context)
|
get_gerber_code
get_gerber_code(
indent: str = "", endline: str = "\n"
) -> str
Get gerber code represented by this token.
Source code in src/pygerber/gerberx3/tokenizer/tokens/mo_unit_mode.py
| def get_gerber_code(
self,
indent: str = "", # noqa: ARG002
endline: str = "\n", # noqa: ARG002
) -> str:
"""Get gerber code represented by this token."""
return f"MO{self.unit.value}"
|