Skip to main content

Plugin which integrates Lark into the Poetry build system.

Project description

poetry-lark

Tests

Lark is an amazing parsing toolkit for Python, built with a focus on ergonomics, performance and modularity. Lark can parse all context-free languages. To put it simply, it means that it is capable of parsing almost any programming language out there, and to some degree most natural languages too.

Lark can generate a stand-alone LALR(1) parser from a grammar. This plugin integrates Lark into the Poetry build system and provides several commands for configuring standalone parsers using pyproject.toml and Poetry.

Install

$ poetry self add poetry-lark

The plugin depends only on Lark and Poetry, but you can use Lark's extra features:

  • interegular (if it is installed, Lark uses it to check for collisions, and warn about any conflicts that it can find)
  • regex (if you want to use the regex module instead of the re module).

Usage

$ poetry lark-add <module> <grammar-file>
$ poetry lark-remove <module>
$ poetry lark-build <module>

By default, the plugin is integrated into the Poetry build system and generates all parser modules specified in the pyproject.toml (if auto-build option is not configured as false for parser module).

In the simplest case, when adding a parser, you will get:

[[tool.lark.standalone]]
module = "parser"
source = "grammar.lark"

In a more complex case you can use all features of Lark standalone parser:

[[tool.lark.standalone]]
module = {expose = "parser", from = "src", auto-build = true}
source = "grammar.lark"
start = ["start"]
lexer = "contextual"
enable_compress = false
keep_all_tokens = false
propagate_positions = false
use_bytes = false
use_maybe_placeholders = true
use_regex = false
use_strict = false

These options are available on lark-add command:

Argument Description
--src use the 'src' layout for the project
-s <symbol>, --start <symbol> the grammar's start symbols, default start, can be multiple
-l <lexer>, --lexer <lexer> the lexer to use, basic or contextual, default contextual
-c, --enable-compress enable compression in the generated parser
-K, --keep-all-tokens prevent removal of 'punctuation' tokens in the parse tree
-P, --propagate-positions propagate positional attributes into metadata
--use-bytes use bytes as input type instead of str
--use-regex use the regex module instead of the re module
--use-strict use strict mode in parsing
--no-maybe-placeholders disable placeholders for empty optional tokens
--no-auto-build disable automatic build for the module

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

poetry_lark-1.1.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

poetry_lark-1.1.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file poetry_lark-1.1.0.tar.gz.

File metadata

  • Download URL: poetry_lark-1.1.0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.2 Linux/6.8.0-1021-azure

File hashes

Hashes for poetry_lark-1.1.0.tar.gz
Algorithm Hash digest
SHA256 412da403e8836312cb9c1eb3700be178512f4f9a0d097b352fcc3b64e59a9cf6
MD5 78d6cc02c7233f1861a210b74fb6f5dc
BLAKE2b-256 e7ad153254c77268c0ca829f09909c81e149ca0838e5701dc7e4e4054dbba0b1

See more details on using hashes here.

File details

Details for the file poetry_lark-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: poetry_lark-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.2 Linux/6.8.0-1021-azure

File hashes

Hashes for poetry_lark-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ec4b74c358368ca0dc800b82df049b5faff4d151558faf6377d087cc414ee79d
MD5 282ff3f6ec0b5cb66a0769d5a499dd39
BLAKE2b-256 ae648fd59218174db9a828811eec0c63ba16456c2dba8eac029954ee4bfcfabb

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