How to use the parsita.reg function in parsita

To help you get started, we’ve selected a few parsita examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github drhagen / parsita / examples / positioned.py View on Github external
@dataclass
class Variable:
    name: str
    start: int
    length: int


@dataclass
class Plus:
    first: Variable
    second: Variable


class PlusParsers(TextParsers):
    variable = positioned(reg('[A-Za-z][A-Za-z0-9_]*') > UnfinishedVariable)
    plus = variable & '+' >> variable > splat(Plus)


if __name__ == '__main__':
    print(PlusParsers.plus.parse('abc + xyz').or_die())

parsita

Parser combinator library for Python

MIT
Latest version published 15 days ago

Package Health Score

75 / 100
Full package analysis