Skip to main content

LR(1) parser generator for Python

Project description

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

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

parsing-2.0.1.tar.gz (35.9 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.1-cp311-cp311-win_amd64.whl (200.8 kB view details)

Uploaded CPython 3.11Windows x86-64

parsing-2.0.1-cp311-cp311-musllinux_1_1_x86_64.whl (422.6 kB view details)

Uploaded CPython 3.11musllinux: musl 1.1+ x86-64

parsing-2.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (430.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

parsing-2.0.1-cp311-cp311-macosx_10_9_x86_64.whl (253.2 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

parsing-2.0.1-cp310-cp310-win_amd64.whl (201.1 kB view details)

Uploaded CPython 3.10Windows x86-64

parsing-2.0.1-cp310-cp310-musllinux_1_1_x86_64.whl (424.8 kB view details)

Uploaded CPython 3.10musllinux: musl 1.1+ x86-64

parsing-2.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (433.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

parsing-2.0.1-cp310-cp310-macosx_10_9_x86_64.whl (256.5 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

parsing-2.0.1-cp39-cp39-win_amd64.whl (201.0 kB view details)

Uploaded CPython 3.9Windows x86-64

parsing-2.0.1-cp39-cp39-musllinux_1_1_x86_64.whl (423.4 kB view details)

Uploaded CPython 3.9musllinux: musl 1.1+ x86-64

parsing-2.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (431.8 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

parsing-2.0.1-cp39-cp39-macosx_10_9_x86_64.whl (256.5 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

parsing-2.0.1-cp38-cp38-win_amd64.whl (201.0 kB view details)

Uploaded CPython 3.8Windows x86-64

parsing-2.0.1-cp38-cp38-musllinux_1_1_x86_64.whl (421.9 kB view details)

Uploaded CPython 3.8musllinux: musl 1.1+ x86-64

parsing-2.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (425.1 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

parsing-2.0.1-cp38-cp38-macosx_10_9_x86_64.whl (253.0 kB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

parsing-2.0.1-cp37-cp37m-win_amd64.whl (191.5 kB view details)

Uploaded CPython 3.7mWindows x86-64

parsing-2.0.1-cp37-cp37m-musllinux_1_1_x86_64.whl (325.1 kB view details)

Uploaded CPython 3.7mmusllinux: musl 1.1+ x86-64

parsing-2.0.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (328.7 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

parsing-2.0.1-cp37-cp37m-macosx_10_9_x86_64.whl (246.1 kB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: parsing-2.0.1.tar.gz
  • Upload date:
  • Size: 35.9 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.1.tar.gz
Algorithm Hash digest
SHA256 5d5497e9e1f3561d5930c2c2b4759692b32792d8132b48eca2e63235a0d2c8a0
MD5 2ef937eb9688efe7a0cf387a8e439ac9
BLAKE2b-256 507459a8375162cf14443f02edcc819a05742a04cac5e38c5218789c8e7e8a5e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: parsing-2.0.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 200.8 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.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 a929061dcdfc53340b3065d518f1306da9dee133e27521703f00a40b9071e32c
MD5 d836d32e5e59092228c4b1952ede5076
BLAKE2b-256 e6c8e85041721a94a43c378e16bec002c4f37dddf09fcce6cd31a0e23616cf7c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for parsing-2.0.1-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 0b800a3f42c5f409de27dce90bfe22280393180d75ac77539a4489c60e511083
MD5 52c607a25545a0ead586a71ed96cab2f
BLAKE2b-256 cb93003d06d9de497aa8c934f5deff89c3deaf2b405c0055bf22f776dfdcdc06

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for parsing-2.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 eb1e7edf8a655b555e116d2043e6c0733857b396b75f1deb394d2eda51cbedb9
MD5 2e900aad6f30e9e4712a73beee1daa3d
BLAKE2b-256 e73f28230c346d9c1f6f385c67ed07150ed30513603d82504ad6a68ae7e9e812

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for parsing-2.0.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 fd25062be1662136f572042a5280f2f58c1f73671e22c0682c56292c7c35352f
MD5 9780aa5ec71f45b5418a24679ed25a7e
BLAKE2b-256 e8fbfed86be3b4f1866170dc5cd5a919aad30c0ee674007f80ac6c5a9ba9c448

See more details on using hashes here.

File details

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

File metadata

  • Download URL: parsing-2.0.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 201.1 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.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 bcd9ccd8f22f7555a189f991aea46a47684bd84ca2972499efb6730241b1483b
MD5 c6325713471cd93a0d78b56498759329
BLAKE2b-256 753a92591ad340e5e5c23c2abe8b0c9e279beaeade0eee1ec6e0759e44d90c8c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for parsing-2.0.1-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 bbd828e373a6bab668ad479065606bdb09a4932bf4ad1cec0826ff75ee8eecbc
MD5 1437d9a82a7b3ed3523dfe596e5afb19
BLAKE2b-256 dbba880d023a8e428e768ef78e0fff3720217d2e87ab90076cdb6299d1df965a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for parsing-2.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 20811ed9ec0ac6ec6bdc2ee33397965eea2d9c3a3e2d91f905783a83ebd6bdd0
MD5 a87f2ba332189e985d4b0016fc81d567
BLAKE2b-256 79655bd8f6da0475fef2c7dddbd612f8a85f65bd33ce9c2950238e9c792cf405

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for parsing-2.0.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0d345c60efc531b15fb668e28544aa96e8af2848a85a72c57376908af7ca49c6
MD5 a6f2b713a1461aca85807d1d5c7b64d5
BLAKE2b-256 5ac667c32178f65fd284529397838a7d88bc8281c53f8b67d9997af140d63c42

See more details on using hashes here.

File details

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

File metadata

  • Download URL: parsing-2.0.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 201.0 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.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 62623a5500c3cc255c26319806b2cc6386f6625e505f86b26793855456d67e96
MD5 d69054b7fa58e0092a10041b6e61b6eb
BLAKE2b-256 27bbe21975e6bfd153f10edbb9b787cc4a487a56865af740756c4c80b5db4249

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for parsing-2.0.1-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 585eec834c7734f6fd92e1a5a0db2a16d9f885af2749f3f5927511afbc8652c1
MD5 f8b0a3674b0a10bd387f37da2b33a9f9
BLAKE2b-256 20934e919fa525eeaa52514ac31c1bf3e34a41181864c52cd6a28be4996f92d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for parsing-2.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a26c1c39279922faabcdf53f5ce34d53b65a0368cb99dd8a360c7e7c7d175b39
MD5 a4c82034489b7b79c10707aa81d839e3
BLAKE2b-256 25325f2ff0a1145c6107972744ed769807243c78de6fdffe274ae66ee58a51d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for parsing-2.0.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 3733f1c8d9db0de91f4543f4a5c01f27435823232ce11a7575f6e0689303d3d9
MD5 0d10a9713f6d64aede320deb2b07825a
BLAKE2b-256 474b399fb3ae1dab39828a048c3c30501b08ef53a8bbf3a21be9a2662efc0c82

See more details on using hashes here.

File details

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

File metadata

  • Download URL: parsing-2.0.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 201.0 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.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 a1c498ce6cb782616548948d3b0b09eb88302a0e3d503e900389622a05eb888f
MD5 8d54e538c5bbfb31dd008cc0c59d6ce3
BLAKE2b-256 19646ef7bd8eb89e1e6364665167ca22cde9c6c99ee3baa60cc5d21033dea5a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for parsing-2.0.1-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 3882e7fe3392c30deda2aaf09e2b5467f46e99b888137bf77316b1578bbbf689
MD5 4351e634c1fd8f9b8c5d39c540161e95
BLAKE2b-256 51e45db5579ee923af5db99a59ec5eacdc84f52e67e959b0784b171cf652d302

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for parsing-2.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e582b4faa49959072fcbc70c0d49f5071b99b1c95b68a28d3721f7543f514a2f
MD5 a6d7624f80a8e5b032c3bb28617f9534
BLAKE2b-256 e14060d667296b394df47664df6214e9491263097c55b41c7665561cae18f0a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for parsing-2.0.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1634a5624816e7388753745d8c715029c40e79361c954eb49216982ba10a2246
MD5 383127826937fd387d434811db60e8db
BLAKE2b-256 3e4051606e5789a3553bf22d85c73680a0de7d7e6961e13373c02388771c38b5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: parsing-2.0.1-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 191.5 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.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 32e3276809acf017c708ed8ef36804c894f22ef5a3db310d79f4a3b2ed349648
MD5 5bb009aeb669dac467977413adfd0c62
BLAKE2b-256 a0b27b5fedbefa00719bdccab908543605fedb1387c45dd6b9961ae9b7d4351a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for parsing-2.0.1-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 c0afa5c5cf8ec16d7d3feaed6c2a4aca68e404065ceb7931ee16d4ea54d193dc
MD5 27fa3ecd707a94fabde8ce1137266e88
BLAKE2b-256 0f617ac4b25acbfe70cbfddba7ccc7f8a43d7c079343d6d4d2949bb16d619752

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for parsing-2.0.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 34fcf56c2ee37273b8367c178c99eaec75ea1126ec1f77da5b4b18a8c24b3758
MD5 0ea9d129409993c8bf6e87b252c7ee5c
BLAKE2b-256 f51e1231e3cfe83cfce57a034d48cd15629f9bc97907d92edb60709dabe82e25

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for parsing-2.0.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ed511a394e2b3b0310b2340161236d49ff4a02fce3d64e208a6d908a46c03957
MD5 69a9ad4a4e47a82bdf11c5f638ccb3df
BLAKE2b-256 6190897faa990a2ee51433a120f3a32df4308f71202f91252cf899f240078929

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