Skip to main content

A simpler parsing framework

Project description

https://travis-ci.org/prophile/gobble.svg

Simpler Parsing in Python.

Usage

from gobble import *

Basic parsers:

@parser
def natural():
    digits = yield character('0123456789').star
    return int(''.join(digits))

Alternatives:

@parser
def literal_null():
    yield literal('NULL')
    return None

literal = natural / literal_null

Optional elements:

@parser
def natural():
    sign = yield character('-+').option('+')
    factor = {'-': -1, '+': 1}[sign]
    value = yield natural
    return value * factor

Sequencing with operators:

whitespace = character(' \n\r\t').star

literal_expr = literal << whitespace

Actually running a parser:

value = literal_expr.execute(input_string)
print(value)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gobble-0.1.1.tar.gz (3.4 kB view hashes)

Uploaded Source

Built Distribution

gobble-0.1.1-py3-none-any.whl (5.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page