Skip to main content

LR(1) parser generator for Python

Project description

Wisent - LR(1) Parser Generator for Python

Wisent is an LR(1) parser generator for Python 3 that converts context-free grammars into Python code. It provides a simple way to build robust parsers for custom languages and data formats, making it ideal for compiler construction, configuration file parsing, and domain-specific language development.

Installation

The easiest way to install Wisent is using pip, which will handle all dependencies automatically. For most users, a simple pip install wisent-parser is sufficient. If you need the latest development version or want to contribute to the project, you can install from source using git.

# Install from PyPI (recommended)
pip install wisent-parser

# Install from source for development
git clone https://github.com/seehuhn/wisent.git
cd wisent
pip install -e .

For users without administrator privileges, add the --user flag to install only for your account. Python 3.6 or later is required.

Quick Start

After installation, you can immediately start generating parsers from grammar files. Wisent uses a simple grammar syntax with .wi file extensions. Here's how to get started:

# Check that Wisent is working
wisent --version

# Generate a parser from a grammar file
wisent your_grammar.wi -o parser.py

# Try the included calculator example
wisent examples/calculator/calculator.wi

The examples directory contains several ready-to-use grammars including a calculator, CSS parser, and email address parser that demonstrate different parsing techniques and language features.

Testing Your Installation

To verify that everything is working correctly, run the included test suite. These tests validate both the parser generation process and the grammar tokenizer functionality:

python3 tests/test_parser_generation.py
python3 tests/test_scanner.py

Both tests should complete with success messages, indicating that your installation is ready for use.

Grammar File Format

Wisent grammars use a straightforward syntax similar to BNF notation. Rules are defined with colons and alternatives separated by vertical bars. The grammar format supports modern features like UTF-8 encoding, hyphenated symbol names, grouping with parentheses, and optional expressions with the ? operator.

rule_name: symbol1 symbol2 | alternative ;
optional_expr: required_part optional_part? ;
grouped: symbol1 ( group_a | group_b ) symbol2 ;

See the examples directory and online documentation for complete grammar examples and advanced features.

Documentation and Support

Complete documentation including a tutorial and reference manual is available online at http://seehuhn.de/media/manuals/wisent/. For bug reports or questions, contact voss@seehuhn.de and include the output of wisent --version.

License

Wisent is free software distributed under the GNU General Public License. It comes with absolutely no warranty to the extent permitted by law. See the COPYING file for complete license terms.


Copyright (C) 2008, 2009 Jochen Voss

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

wisent_parser-1.0.2.tar.gz (32.6 kB view details)

Uploaded Source

Built Distribution

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

wisent_parser-1.0.2-py3-none-any.whl (38.8 kB view details)

Uploaded Python 3

File details

Details for the file wisent_parser-1.0.2.tar.gz.

File metadata

  • Download URL: wisent_parser-1.0.2.tar.gz
  • Upload date:
  • Size: 32.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for wisent_parser-1.0.2.tar.gz
Algorithm Hash digest
SHA256 5709d8e830fdd708ab6381ed26bebb4bfb4082e154419edd7b45989c59442e2c
MD5 b35f5a457fb1acf065a29ec11f4432c3
BLAKE2b-256 3bc49c4ca3e85c09b1ba5aef7a871162206bf64a60f8dc024b0b0557e1a62e79

See more details on using hashes here.

File details

Details for the file wisent_parser-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: wisent_parser-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 38.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for wisent_parser-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fcffd3a3a870703ea0399f40d413ab9190983c2d983dfb57c264aec10099f515
MD5 ac2abd0cf4148884e98f90030232cc88
BLAKE2b-256 a2c7d163573faffc60e4a7f28ea54f7ea4e0a7916e99ae6e90a6c13d1a3c8f38

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