Skip to main content

A parser combinator library (and soon-to-be formatter combinator library as well) that's easy to use and that provides informative error messages.

Project description

Parcon is a parser combinator library. It can be used for parsing both normal text and binary data. It’s designed to be easy to use and to provide informative error messages.

All of the classes, and most of the functions, in Parcon are comprehensively documented. The best place to look for help is in Parcon’s module documentation.

Here’s an example of a simple expression evaluator written using Parcon:

from parcon import *
from decimal import Decimal
import operator
expr = Forward()
number = (+Digit() + -(SignificantLiteral(".") + +Digit()))[flatten]["".join][Decimal]
term = number | "(" + expr + ")"
term = InfixExpr(term, [("*", operator.mul), ("/", operator.truediv)])
term = InfixExpr(term, [("+", operator.add), ("-", operator.sub)])
expr << term

This expression evaluator can be used thus:

print expr.parseString("1+2") # prints 3
print expr.parseString("1+2+3") # prints 6
print expr.parseString("1+2+3+4") # prints 10
print expr.parseString("3*4") # prints 12
print expr.parseString("5+3*4") # prints 17
print expr.parseString("(5+3)*4") # prints 32
print expr.parseString("10/4") # prints 2.5

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

parcon-0.1.9.tar.gz (29.0 kB view details)

Uploaded Source

File details

Details for the file parcon-0.1.9.tar.gz.

File metadata

  • Download URL: parcon-0.1.9.tar.gz
  • Upload date:
  • Size: 29.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for parcon-0.1.9.tar.gz
Algorithm Hash digest
SHA256 aadf1d2b567cf5cf10c7731d65d7425505e2acb776cf89f2576653b9c643349d
MD5 ec9627a708c492aea66689834f77c646
BLAKE2b-256 d457ce0dad4064fb459ccb461c1c0c18ad252ab6110ce3ffdd7997415ecc3254

See more details on using hashes here.

Supported by

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