Skip to main content

The parsing module implements an LR(1) parser generator, as well as the runtime support for using a generated parser, via the Lr and Glr parser drivers. There is no special parser generator input file format, but the parser generator still needs to know what classes/methods correspond to various aspects of the parser. This information is specified via docstrings, which the parser generator introspects in order to generate a parser. Only one parser specification can be embedded in each module, but it is possible to share modules between parser specifications so that, for example, the same token definitions can be used by multiple parser specifications.

The parsing tables are LR(1), but they are generated using a fast algorithm that avoids creating duplicate states that result when using the generic LR(1) algorithm. Creation time and table size are on par with the LALR(1) algorithm. However, LALR(1) can create reduce/reduce conflicts that don’t exist in a true LR(1) parser. For more information on the algorithm, see:

A Practical General Method for Constructing LR(k) Parsers
David Pager
Acta Informatica 7, 249-268 (1977)

Parsing table generation requires non-trivial amounts of time for large grammars, however it is still quite fast. Internal pickling support makes it possible to cache the most recent version of the parsing table on disk, and use the table if the current parser specification is still compatible with the one that was used to generate the pickled parsing table. Since the compatibility checking is quite fast, even for large grammars, this removes the need to use the standard code generation method that is used by most parser generators.

Parser specifications are encapsulated by the Spec class. Parser instances use Spec instances, but are themselves based on separate classes. This allows multiple parser instances to exist simultaneously, without requiring multiple copies of the parsing tables. There are two separate parser driver classes:

Lr:

Standard Characteristic Finite State Machine (CFSM) driver, based on unambiguous LR(1) parsing tables. This driver is faster than the Glr driver, but it cannot deal with all parsing tables that the Glr driver can.

Glr:

Generalized LR driver, capable of tracking multiple parse trees simultaneously, if the %split precedence is used to mark ambiguous actions. This driver is closely based on Elkhound’s design, which is described in a technical report:

Elkhound: A Fast, Practical GLR Parser Generator
Scott McPeak
Report No. UCB/CSD-2-1214 (December 2002)
http://www.cs.berkeley.edu/~smcpeak/elkhound/

Parser generator directives are embedded in docstrings, and must begin with a ‘%’ character, followed immediately by one of several keywords:

Precedence:

%fail %nonassoc %left %right %split

Token:

%token

Non-terminal:

%start %nonterm

Production:

%reduce

All of these directives are associated with classes except for %reduce. %reduce is associated with methods within non-terminal classes. The Parsing module provides base classes from which precedences, tokens, and non-terminals must be derived. This is not as restrictive as it sounds, since there is nothing preventing, for example, a master Token class that subclasses Parsing.Token, which all of the actual token types then subclass. Also, nothing prevents using multiple inheritance.

Folowing are the base classes to be subclassed by parser specifications:

  • Precedence

  • Token

  • Nonterm

The Parsing module implements the following exception classes:

  • SpecError - when there is a problem with the grammar specification

  • ParsingException - any problem that occurs during parsing

  • UnexpectedToken - when the input sequence contains a token that is not allowed by the grammar (including end-of-input)

In order to maintain compatibility with legacy code, the Parsing module defines the following aliases. New code should use the exceptions above that do not shadow Python’s builtin exceptions.

  • Exception - superclass for all exceptions that can be raised

  • SyntaxError - alias for UnexpectedToken

Additionally, trying to set private attributes may raise:
  • AttributeError

Author: Jason Evans jasone@canonware.com

Github repo: http://github.com/MagicStack/parsing

Download files

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

Source Distribution

parsing-2.0.3.tar.gz (36.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

parsing-2.0.3-cp311-cp311-win_amd64.whl (220.5 kB view details)

Uploaded CPython 3.11Windows x86-64

parsing-2.0.3-cp311-cp311-musllinux_1_1_x86_64.whl (478.9 kB view details)

Uploaded CPython 3.11musllinux: musl 1.1+ x86-64

parsing-2.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (491.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

parsing-2.0.3-cp311-cp311-macosx_10_9_x86_64.whl (290.9 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

parsing-2.0.3-cp310-cp310-win_amd64.whl (220.6 kB view details)

Uploaded CPython 3.10Windows x86-64

parsing-2.0.3-cp310-cp310-musllinux_1_1_x86_64.whl (478.5 kB view details)

Uploaded CPython 3.10musllinux: musl 1.1+ x86-64

parsing-2.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (493.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

parsing-2.0.3-cp310-cp310-macosx_10_9_x86_64.whl (293.8 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

parsing-2.0.3-cp39-cp39-win_amd64.whl (220.2 kB view details)

Uploaded CPython 3.9Windows x86-64

parsing-2.0.3-cp39-cp39-musllinux_1_1_x86_64.whl (470.3 kB view details)

Uploaded CPython 3.9musllinux: musl 1.1+ x86-64

parsing-2.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (484.8 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

parsing-2.0.3-cp39-cp39-macosx_10_9_x86_64.whl (293.6 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

parsing-2.0.3-cp38-cp38-win_amd64.whl (220.3 kB view details)

Uploaded CPython 3.8Windows x86-64

parsing-2.0.3-cp38-cp38-musllinux_1_1_x86_64.whl (466.8 kB view details)

Uploaded CPython 3.8musllinux: musl 1.1+ x86-64

parsing-2.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (472.6 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

parsing-2.0.3-cp38-cp38-macosx_10_9_x86_64.whl (288.1 kB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

parsing-2.0.3-cp37-cp37m-win_amd64.whl (209.9 kB view details)

Uploaded CPython 3.7mWindows x86-64

parsing-2.0.3-cp37-cp37m-musllinux_1_1_x86_64.whl (365.2 kB view details)

Uploaded CPython 3.7mmusllinux: musl 1.1+ x86-64

parsing-2.0.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (369.4 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

parsing-2.0.3-cp37-cp37m-macosx_10_9_x86_64.whl (280.8 kB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

File details

Details for the file parsing-2.0.3.tar.gz.

File metadata

  • Download URL: parsing-2.0.3.tar.gz
  • Upload date:
  • Size: 36.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for parsing-2.0.3.tar.gz
Algorithm Hash digest
SHA256 10141232307c40478a3ae3052737df0156420e5dde48aab775dfeb9141465cda
MD5 db58e29557141fe0b9b592928992fd14
BLAKE2b-256 0c5a4c33bbf61e8d228ea61c10e382a2ae00ba8c9844a0bf2004cbb6d90137e5

See more details on using hashes here.

File details

Details for the file parsing-2.0.3-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: parsing-2.0.3-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 220.5 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for parsing-2.0.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b47de0a63ea5ca5474da3860db3eb2710e6ecccfba140d0667edf1fa5ecaa17d
MD5 636e44d50a299f96b1a642e7b8ca868e
BLAKE2b-256 46c1982cbb328dfeded25f724cc0fb612842c65a6cb83327abfb08f9c42c6abd

See more details on using hashes here.

File details

Details for the file parsing-2.0.3-cp311-cp311-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for parsing-2.0.3-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 a114e23a2ec87d494bdb16f5268841dd5688088d51487bd07132120086356b69
MD5 e75e4d536ebbb3b1e7f3ab72da7ae89b
BLAKE2b-256 768a8c715d29d12e0d7011163c93b3e9d7377fcc8aa6161aca5a358a43f8ed25

See more details on using hashes here.

File details

Details for the file parsing-2.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for parsing-2.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bf13dbee31f1433be26943a73e06480d0ca245866ff838a214ad5e96cba94d7d
MD5 e2de5e5c6964cc135de06665c08b57ad
BLAKE2b-256 dc155364ffe1c19a0cb2c3a0c8a0115dfebe7aca1f081063ffc88dc4a93685e6

See more details on using hashes here.

File details

Details for the file parsing-2.0.3-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for parsing-2.0.3-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 46c67c0bc068b9b1d0d933586714ca516959514ae49603a829a02527fb78e4f6
MD5 41a51f8640294fc74bb07b3f28375413
BLAKE2b-256 b7fe961f9b05850a419ccdd479550742a199c64c8a642a051844042f67105630

See more details on using hashes here.

File details

Details for the file parsing-2.0.3-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: parsing-2.0.3-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 220.6 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for parsing-2.0.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 380a048303642784f23f7ac9a6e1f2688d2d6c9ed91dee0d00999a0207184b43
MD5 9aec3f018d7e39de38bc55c468dbd93c
BLAKE2b-256 f1729114aaf605745059bfc72ea92605d508d4cdcf90d2b88fe0ec7915c17ebc

See more details on using hashes here.

File details

Details for the file parsing-2.0.3-cp310-cp310-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for parsing-2.0.3-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 48595cbf6347c6ffaaaa6ca80eaa9060aba30523dcd618b3958f3c88bc79621d
MD5 dfe82f38107bf2e10cda9fcd723f9a0a
BLAKE2b-256 4edee3685b7ba6b538ac44952ac2fb2a8eb80a056a96266f0bcdd63ec9e079af

See more details on using hashes here.

File details

Details for the file parsing-2.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for parsing-2.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9592a25ea19312419094b84ef2a35398f90d021ff730d668b66f4549a25d91ca
MD5 4a9e1b0cf9d09221ff4b8369de311879
BLAKE2b-256 9f8859565d33866e9f7b7a78214fe255b386489977fa8ed37e5f7cfa0147c31b

See more details on using hashes here.

File details

Details for the file parsing-2.0.3-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for parsing-2.0.3-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 eec62d64bd44836b1532feef2c409be0cc194c131ef64d207815482ba6f49dc5
MD5 bbca199aef23692e45d98ca03fdede0c
BLAKE2b-256 b448f8f1bb2d15265b62013d512ea4db42cc2c1ca35e8d92da11952cd73f6861

See more details on using hashes here.

File details

Details for the file parsing-2.0.3-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: parsing-2.0.3-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 220.2 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for parsing-2.0.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 84b78382d706bc358d5b14dd18be49a44d57c862aa08c11a7b37e9bb96f19e0f
MD5 5a2b115fbb701c4b23c35d7236f2d10f
BLAKE2b-256 d52986de55fb1d0c1f57f513da5bda835788aa44e43cdb840ed639577efd5bf5

See more details on using hashes here.

File details

Details for the file parsing-2.0.3-cp39-cp39-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for parsing-2.0.3-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 6622db6b8b807e4eee49f18229c43c82ed582ab6e8b306c8e5b57a0f0e6f9512
MD5 42759024af747fadefc73fcf0b04ad39
BLAKE2b-256 cd2914ab6d368f7a74794cdbd45a6c5bb583f67875457d8f1a4ca5936946f532

See more details on using hashes here.

File details

Details for the file parsing-2.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for parsing-2.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 58b207f0e080980ae9f4a6f060eb61a9bbd9ceb8ea4a2733734bf179e0eeea3e
MD5 00b1c4b2328e4a0d1982e1fc85d4c406
BLAKE2b-256 f6544f6155a6fcef1704a055a7a77a9090ad9ba6e02f5d01d914533ff4116148

See more details on using hashes here.

File details

Details for the file parsing-2.0.3-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for parsing-2.0.3-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 235dee140c811d04f0caa620d666ba1a8ffc4280557eaee489e54a603d82e25d
MD5 38587ca0082ff63b1953237d43794b88
BLAKE2b-256 5b6df89e1e6512014260b26278deff53ff78c3829118758b2152cde726e3b171

See more details on using hashes here.

File details

Details for the file parsing-2.0.3-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: parsing-2.0.3-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 220.3 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for parsing-2.0.3-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 72386cad70651f0f638ac78f2f6bcb26f86e7e984e5b2e5bc771cf37b9c6426c
MD5 9994ef85a0c0197333d7fe5821681a1f
BLAKE2b-256 2903d6bbbad1badb8637952cd209b59b9ba9a7a132e7d0e2f06aa902460ebe80

See more details on using hashes here.

File details

Details for the file parsing-2.0.3-cp38-cp38-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for parsing-2.0.3-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 97941b949d2501ded9014f8a21bcf6376c20bfcc0daec9aa4c0f3ff30c8869ee
MD5 a0012774ecf8984f353f50cfa00829f0
BLAKE2b-256 e45c59c3bb88775c5c70324c040bed8832307116b535ab34a63c5a756669fa75

See more details on using hashes here.

File details

Details for the file parsing-2.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for parsing-2.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5cc1021f772a61f9e7c58fca801b928393f1ef4d8060cfd905427b11d5aa310e
MD5 d9925413e051a3dc39cd31b9a0fd07df
BLAKE2b-256 5859cc082b0533a68061b5f981b32b36c11d2f07ea005af77b231da953f320d1

See more details on using hashes here.

File details

Details for the file parsing-2.0.3-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for parsing-2.0.3-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 67542821ca11beaa39ba0632cecdc14c575c03abc804bcfd384a118a19e05d19
MD5 4165fd75b32d3c447ed8933255b5d6e7
BLAKE2b-256 8f2bc358a3b46001d24065c844253cf49654209b69de289d65c88eb7e6842e94

See more details on using hashes here.

File details

Details for the file parsing-2.0.3-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: parsing-2.0.3-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 209.9 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for parsing-2.0.3-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 27288fcfbbdce5d90d74f80350c9615c9c9d1168124444aba500cc70f164e32f
MD5 f27766857baaa7713f1c40abdd7d7487
BLAKE2b-256 3c136d86a115ad2bd5fe7a7ccfb8849701fd93e94df920a75c805972f75ea1bc

See more details on using hashes here.

File details

Details for the file parsing-2.0.3-cp37-cp37m-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for parsing-2.0.3-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 617521d5bd6ec31809bd00d084502d22324331b2b1c91bf9436ae0cafa556420
MD5 5dd6de27c553c05fed9556ce82e0d338
BLAKE2b-256 22037f513220135bd92e15c426db524eda2c059c539227cfe92868fd015d03cc

See more details on using hashes here.

File details

Details for the file parsing-2.0.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for parsing-2.0.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 35dc4eedd944a4bfe173e47cfd3d369cd028dc578fa5eec83e7ceea39fc171ea
MD5 5f22f2f565ecea207e5b8df2e2493df3
BLAKE2b-256 c052aaab10595a40765e68d1275e23f1d6edecbd13e55d0b21cf7b9ba0088e2f

See more details on using hashes here.

File details

Details for the file parsing-2.0.3-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for parsing-2.0.3-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f2116807642993025f254b3bfd194e3c01376fadeda61b2e1c02adb8584d9751
MD5 1a27a495249f12af14422954ecd77f75
BLAKE2b-256 4116db56e8bb24a4ef47dbb1358a113afa54dc3e9f2aae9cabb2b49b6dd56028

See more details on using hashes here.

Release history Release notifications | RSS feed

2.0.4

21 files

This release

2.0.3 This release

21 files

2.0.2

21 files

2.0.1

21 files

2.0.0

12 files

1.6.1

2 files

1.6.0

2 files

1.5.0

1 file

1.4.1

1 file

1.4

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page