Skip to main content

A simpler parsing framework

Project description

Simpler Parsing in Python.


from gobble import *

Basic parsers:

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


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

literal = natural / literal_null

Optional elements:

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)

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 3 3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page