def consume(self, name: str) -> None: """Move beyond provided token name, if at current position.""" if self.check(name):
self.read()
def check(self, name: str, *, peek: bool = False) -> bool: """Check whether the next token has the provided name.
By default, if the check succeeds, the token *must* be read before
another check. If `peek` is set to `True`, the token isnot loaded and
would need to be checked again. """ assert (
self.next_token isNone
), f"Cannot check for {name!r}, already have {self.next_token!r}" assert name in self.rules, f"Unknown token name: {name!r}"
expression = self.rules[name]
match = expression.match(self.source, self.position) if match isNone: returnFalse ifnot peek:
self.next_token = Token(name, match[0], self.position) returnTrue
def expect(self, name: str, *, expected: str) -> Token: """Expect a certain token name next, failing with a syntax error otherwise.
The token is *not* read. """ ifnot self.check(name): raise self.raise_syntax_error(f"Expected {expected}") return self.read()
def read(self) -> Token: """Consume the next token and return it."""
token = self.next_token assert token isnotNone
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.