Skip to content

invalid_token

invalid_token

Wrapper for G74 token.

InvalidToken

Bases: Token

Invalid syntax.

This is not a valid Gerber X3/X2 expression.

Source code in src\pygerber\gerberx3\tokenizer\tokens\invalid_token.py
class InvalidToken(Token):
    """Invalid syntax.

    This is not a valid Gerber X3/X2 expression.
    """

    def __init__(self, string: str, location: int, content: str) -> None:
        super().__init__(string, location)
        self.content = content

    @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()`.
        """
        content: str = str(tokens["content"])
        return cls(string=string, location=location, content=content)

    def get_token_diagnostics(self) -> Iterable[diagnostic.Diagnostic]:
        """Get diagnostics for this token."""
        yield diagnostic.Diagnostic(
            range=(
                diagnostic.Range(
                    start=self.get_token_position(),
                    end=self.get_token_end_position(),
                )
            ),
            message="Invalid syntax.",
            severity=diagnostic.DiagnosticSeverity.Error,
        )

    def parser2_visit_token(self, context: Parser2Context) -> None:
        """Perform actions on the context implicated by this token."""
        context.get_hooks().invalid_token.pre_parser_visit_token(self, context)
        context.get_hooks().invalid_token.on_parser_visit_token(self, context)
        context.get_hooks().invalid_token.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 self.content

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\invalid_token.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()`.
    """
    content: str = str(tokens["content"])
    return cls(string=string, location=location, content=content)

get_token_diagnostics

get_token_diagnostics() -> Iterable[diagnostic.Diagnostic]

Get diagnostics for this token.

Source code in src\pygerber\gerberx3\tokenizer\tokens\invalid_token.py
def get_token_diagnostics(self) -> Iterable[diagnostic.Diagnostic]:
    """Get diagnostics for this token."""
    yield diagnostic.Diagnostic(
        range=(
            diagnostic.Range(
                start=self.get_token_position(),
                end=self.get_token_end_position(),
            )
        ),
        message="Invalid syntax.",
        severity=diagnostic.DiagnosticSeverity.Error,
    )

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\invalid_token.py
def parser2_visit_token(self, context: Parser2Context) -> None:
    """Perform actions on the context implicated by this token."""
    context.get_hooks().invalid_token.pre_parser_visit_token(self, context)
    context.get_hooks().invalid_token.on_parser_visit_token(self, context)
    context.get_hooks().invalid_token.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\invalid_token.py
def get_gerber_code(
    self,
    indent: str = "",  # noqa: ARG002
    endline: str = "\n",  # noqa: ARG002
) -> str:
    """Get gerber code represented by this token."""
    return self.content