def extract(self) -> str: """
Extracts the value between marker and index """ return self[self._marker : self._idx]
def inc(self, exception: type[ParseError] | None = None) -> bool: """
Increments the parser if the end of the input has not been reached.
Returns whether ornot it was able to advance. """ try:
self._idx, self._current = next(self._chars)
def inc_n(self, n: int, exception: type[ParseError] | None = None) -> bool: """
Increments the parser by n characters if the end of the input has not been reached. """ return all(self.inc(exception=exception) for _ in range(n))
def consume(self, chars, min=0, max=-1): """
Consume chars until min/max is satisfied is valid. """ while self.current in chars and max != 0:
min -= 1
max -= 1 ifnot self.inc(): break
# failed to consume minimum number of characters if min > 0: raise self.parse_error(UnexpectedCharError, self.current)
def end(self) -> bool: """
Returns Trueif the parser has reached the end of the input. """ return self._current is self.EOF
def mark(self) -> None: """
Sets the marker to the index's current position """
self._marker = self._idx
def parse_error(
self,
exception: type[ParseError] = ParseError,
*args: Any,
**kwargs: Any,
) -> ParseError: """
Creates a generic "parse error" at the current position. """
line, col = self._to_linecol()
return exception(line, col, *args, **kwargs)
def _to_linecol(self) -> tuple[int, int]:
cur = 0 for i, line in enumerate(self.splitlines()): if cur + len(line) + 1 > self.idx: return (i + 1, self.idx - cur)
cur += len(line) + 1
return len(self.splitlines()), 0
Messung V0.5
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet)
¤
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 und die Messung sind noch experimentell.