pax_global_header 0000666 0000000 0000000 00000000064 14200554527 0014516 g ustar 00root root 0000000 0000000 52 comment=01e16c55c75be6ba8199f0873adee7f1a3146678
lark-1.1.1/ 0000775 0000000 0000000 00000000000 14200554527 0012447 5 ustar 00root root 0000000 0000000 lark-1.1.1/.github/ 0000775 0000000 0000000 00000000000 14200554527 0014007 5 ustar 00root root 0000000 0000000 lark-1.1.1/.github/FUNDING.yml 0000664 0000000 0000000 00000001205 14200554527 0015622 0 ustar 00root root 0000000 0000000 # These are supported funding model platforms
github: lark-parser
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
lark-1.1.1/.github/ISSUE_TEMPLATE/ 0000775 0000000 0000000 00000000000 14200554527 0016172 5 ustar 00root root 0000000 0000000 lark-1.1.1/.github/ISSUE_TEMPLATE/bug_report.md 0000664 0000000 0000000 00000000554 14200554527 0020670 0 ustar 00root root 0000000 0000000 ---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is, and what you expected to happen.
**To Reproduce**
Provide a short script that reproduces the erroneous behavior.
If that is impossible, provide clear steps to reproduce the behavior.
lark-1.1.1/.github/ISSUE_TEMPLATE/feature_request.md 0000664 0000000 0000000 00000000714 14200554527 0021721 0 ustar 00root root 0000000 0000000 ---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''
---
**Suggestion**
Provide a clear and concise description of what the problem is, and what you would like to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.
lark-1.1.1/.github/ISSUE_TEMPLATE/other.md 0000664 0000000 0000000 00000000163 14200554527 0017635 0 ustar 00root root 0000000 0000000 ---
name: Other
about: For any discussion that doesn't fit the templates
title: ''
labels: ''
assignees: ''
---
lark-1.1.1/.github/ISSUE_TEMPLATE/question.md 0000664 0000000 0000000 00000000547 14200554527 0020371 0 ustar 00root root 0000000 0000000 ---
name: Question
about: Ask a question about Lark or request help
title: ''
labels: question
assignees: ''
---
**What is your question?**
Try to be accurate and concise.
**If you're having trouble with your code or grammar**
Provide a small script that encapsulates your issue.
Explain what you're trying to do, and what is obstructing your progress.
lark-1.1.1/.github/workflows/ 0000775 0000000 0000000 00000000000 14200554527 0016044 5 ustar 00root root 0000000 0000000 lark-1.1.1/.github/workflows/codecov.yml 0000664 0000000 0000000 00000002324 14200554527 0020212 0 ustar 00root root 0000000 0000000 name: Compute coverage and push to Codecov
on: [push]
jobs:
run:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
env:
OS: ${{ matrix.os }}
PYTHON: '3.7'
steps:
- uses: actions/checkout@master
- name: Download submodules
run: |
git submodule update --init --recursive
git submodule sync -q
git submodule update --init
- name: Setup Python
uses: actions/setup-python@master
with:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r test-requirements.txt
- name: Generate coverage report
run: |
pip install pytest
pip install pytest-cov
pytest --cov=./ --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
flags: unittests
env_vars: OS,PYTHON
name: codecov-umbrella
fail_ci_if_error: true
path_to_write_report: ./coverage/codecov_report.txt
verbose: true
lark-1.1.1/.github/workflows/mypy.yml 0000664 0000000 0000000 00000001007 14200554527 0017563 0 ustar 00root root 0000000 0000000 name: Python type check
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Download submodules
run: git submodule update --init --recursive
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install mypy
- name: Lint with mypy
run: mypy -p lark || true
lark-1.1.1/.github/workflows/tests.yml 0000664 0000000 0000000 00000001374 14200554527 0017736 0 ustar 00root root 0000000 0000000 name: Tests
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, 3.10.0-rc - 3.10, pypy3]
steps:
- uses: actions/checkout@v2
- name: Download submodules
run: |
git submodule update --init --recursive
git submodule sync -q
git submodule update --init
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r test-requirements.txt
- name: Run tests
run: |
python -m tests lark-1.1.1/.gitignore 0000664 0000000 0000000 00000000204 14200554527 0014433 0 ustar 00root root 0000000 0000000 *.pyc
*.pyo
/.tox
/lark_parser.egg-info/**
tags
.vscode
.idea
.ropeproject
.cache
.mypy_cache
/dist
/build
docs/_build
docs/examples lark-1.1.1/.gitmodules 0000664 0000000 0000000 00000000172 14200554527 0014624 0 ustar 00root root 0000000 0000000 [submodule "tests/test_nearley/nearley"]
path = tests/test_nearley/nearley
url = https://github.com/Hardmath123/nearley
lark-1.1.1/CHANGELOG.md 0000664 0000000 0000000 00000000752 14200554527 0014264 0 ustar 00root root 0000000 0000000 v1.0
- `maybe_placeholders` is now True by default
- Renamed TraditionalLexer to BasicLexer, and 'standard' lexer option to 'basic'
- Default priority is now 0, for both terminals and rules (used to be 1 for terminals)
- Discard mechanism is now done by returning Discard, instead of raising it as an exception.
- `use_accepts` in `UnexpectedInput.match_examples()` is now True by default
- `v_args(meta=True)` now gives meta as the first argument. i.e. `(meta, children)` lark-1.1.1/LICENSE 0000664 0000000 0000000 00000002040 14200554527 0013450 0 ustar 00root root 0000000 0000000 Copyright © 2017 Erez Shinan
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
lark-1.1.1/MANIFEST.in 0000664 0000000 0000000 00000000255 14200554527 0014207 0 ustar 00root root 0000000 0000000 include README.md LICENSE docs/* examples/*.py examples/*.png examples/*.lark tests/*.py tests/*.lark tests/grammars/* tests/test_nearley/*.py tests/test_nearley/grammars/*
lark-1.1.1/README.md 0000664 0000000 0000000 00000022255 14200554527 0013734 0 ustar 00root root 0000000 0000000 # Lark - a parsing toolkit for Python
Lark is a 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.
**Who is it for?**
- **Beginners**: Lark is very friendly for experimentation. It can parse any grammar you throw at it, no matter how complicated or ambiguous, and do so efficiently. It also constructs an annotated parse-tree for you, using only the grammar and an input, and it gives you convienient and flexible tools to process that parse-tree.
- **Experts**: Lark implements both Earley(SPPF) and LALR(1), and several different lexers, so you can trade-off power and speed, according to your requirements. It also provides a variety of sophisticated features and utilities.
**What can it do?**
- Parse all context-free grammars, and handle any ambiguity gracefully
- Build an annotated parse-tree automagically, no construction code required.
- Provide first-rate performance in terms of both Big-O complexity and measured run-time (considering that this is Python ;)
- Run on every Python interpreter (it's pure-python)
- Generate a stand-alone parser (for LALR(1) grammars)
And many more features. Read ahead and find out!
Most importantly, Lark will save you time and prevent you from getting parsing headaches.
### Quick links
- [Documentation @readthedocs](https://lark-parser.readthedocs.io/)
- [Cheatsheet (PDF)](/docs/_static/lark_cheatsheet.pdf)
- [Online IDE](https://lark-parser.org/ide)
- [Tutorial](/docs/json_tutorial.md) for writing a JSON parser.
- Blog post: [How to write a DSL with Lark](http://blog.erezsh.com/how-to-write-a-dsl-in-python-with-lark/)
- [Gitter chat](https://gitter.im/lark-parser/Lobby)
### Install Lark
$ pip install lark --upgrade
Lark has no dependencies.
[](https://github.com/lark-parser/lark/actions/workflows/tests.yml)
### Syntax Highlighting
Lark provides syntax highlighting for its grammar files (\*.lark):
- [Sublime Text & TextMate](https://github.com/lark-parser/lark_syntax)
- [vscode](https://github.com/lark-parser/vscode-lark)
- [Intellij & PyCharm](https://github.com/lark-parser/intellij-syntax-highlighting)
- [Vim](https://github.com/lark-parser/vim-lark-syntax)
- [Atom](https://github.com/Alhadis/language-grammars)
### Clones
These are implementations of Lark in other languages. They accept Lark grammars, and provide similar utilities.
- [Lerche (Julia)](https://github.com/jamesrhester/Lerche.jl) - an unofficial clone, written entirely in Julia.
- [Lark.js (Javascript)](https://github.com/lark-parser/lark.js) - a port of the stand-alone LALR(1) parser generator to Javascsript.
### Hello World
Here is a little program to parse "Hello, World!" (Or any other similar phrase):
```python
from lark import Lark
l = Lark('''start: WORD "," WORD "!"
%import common.WORD // imports from terminal library
%ignore " " // Disregard spaces in text
''')
print( l.parse("Hello, World!") )
```
And the output is:
```python
Tree(start, [Token(WORD, 'Hello'), Token(WORD, 'World')])
```
Notice punctuation doesn't appear in the resulting tree. It's automatically filtered away by Lark.
### Fruit flies like bananas
Lark is great at handling ambiguity. Here is the result of parsing the phrase "fruit flies like bananas":

[Read the code here](https://github.com/lark-parser/lark/tree/master/examples/fruitflies.py), and see [more examples here](https://lark-parser.readthedocs.io/en/latest/examples/index.html).
## List of main features
- Builds a parse-tree (AST) automagically, based on the structure of the grammar
- **Earley** parser
- Can parse all context-free grammars
- Full support for ambiguous grammars
- **LALR(1)** parser
- Fast and light, competitive with PLY
- Can generate a stand-alone parser ([read more](docs/tools.md#stand-alone-parser))
- **EBNF** grammar
- **Unicode** fully supported
- Automatic line & column tracking
- Interactive parser for advanced parsing flows and debugging
- Grammar composition - Import terminals and rules from other grammars
- Standard library of terminals (strings, numbers, names, etc.)
- Import grammars from Nearley.js ([read more](/docs/tools.md#importing-grammars-from-nearleyjs))
- Extensive test suite [](https://codecov.io/gh/lark-parser/lark)
- Type annotations (MyPy support)
- And much more!
See the full list of [features here](https://lark-parser.readthedocs.io/en/latest/features.html)
### Comparison to other libraries
#### Performance comparison
Lark is the fastest and lightest (lower is better)


Check out the [JSON tutorial](/docs/json_tutorial.md#conclusion) for more details on how the comparison was made.
*Note: I really wanted to add PLY to the benchmark, but I couldn't find a working JSON parser anywhere written in PLY. If anyone can point me to one that actually works, I would be happy to add it!*
*Note 2: The parsimonious code has been optimized for this specific test, unlike the other benchmarks (Lark included). Its "real-world" performance may not be as good.*
#### Feature comparison
| Library | Algorithm | Grammar | Builds tree? | Supports ambiguity? | Can handle every CFG? | Line/Column tracking | Generates Stand-alone
|:--------|:----------|:----|:--------|:------------|:------------|:----------|:----------
| **Lark** | Earley/LALR(1) | EBNF | Yes! | Yes! | Yes! | Yes! | Yes! (LALR only) |
| [PLY](http://www.dabeaz.com/ply/) | LALR(1) | BNF | No | No | No | No | No |
| [PyParsing](https://github.com/pyparsing/pyparsing) | PEG | Combinators | No | No | No\* | No | No |
| [Parsley](https://pypi.python.org/pypi/Parsley) | PEG | EBNF | No | No | No\* | No | No |
| [Parsimonious](https://github.com/erikrose/parsimonious) | PEG | EBNF | Yes | No | No\* | No | No |
| [ANTLR](https://github.com/antlr/antlr4) | LL(*) | EBNF | Yes | No | Yes? | Yes | No |
(\* *PEGs cannot handle non-deterministic grammars. Also, according to Wikipedia, it remains unanswered whether PEGs can really parse all deterministic CFGs*)
### Projects using Lark
- [Poetry](https://github.com/python-poetry/poetry-core) - A utility for dependency management and packaging
- [tartiflette](https://github.com/dailymotion/tartiflette) - a GraphQL server by Dailymotion
- [PyQuil](https://github.com/rigetti/pyquil) - Python library for quantum programming using Quil
- [Preql](https://github.com/erezsh/preql) - An interpreted relational query language that compiles to SQL
- [Hypothesis](https://github.com/HypothesisWorks/hypothesis) - Library for property-based testing
- [mappyfile](https://github.com/geographika/mappyfile) - a MapFile parser for working with MapServer configuration
- [synapse](https://github.com/vertexproject/synapse) - an intelligence analysis platform
- [Datacube-core](https://github.com/opendatacube/datacube-core) - Open Data Cube analyses continental scale Earth Observation data through time
- [SPFlow](https://github.com/SPFlow/SPFlow) - Library for Sum-Product Networks
- [Torchani](https://github.com/aiqm/torchani) - Accurate Neural Network Potential on PyTorch
- [Command-Block-Assembly](https://github.com/simon816/Command-Block-Assembly) - An assembly language, and C compiler, for Minecraft commands
- [EQL](https://github.com/endgameinc/eql) - Event Query Language
- [Fabric-SDK-Py](https://github.com/hyperledger/fabric-sdk-py) - Hyperledger fabric SDK with Python 3.x
- [required](https://github.com/shezadkhan137/required) - multi-field validation using docstrings
- [miniwdl](https://github.com/chanzuckerberg/miniwdl) - A static analysis toolkit for the Workflow Description Language
- [pytreeview](https://gitlab.com/parmenti/pytreeview) - a lightweight tree-based grammar explorer
- [harmalysis](https://github.com/napulen/harmalysis) - A language for harmonic analysis and music theory
- [gersemi](https://github.com/BlankSpruce/gersemi) - A CMake code formatter
- [MistQL](https://github.com/evinism/mistql) - A query language for JSON-like structures
Using Lark? Send me a message and I'll add your project!
## License
Lark uses the [MIT license](LICENSE).
(The standalone tool is under MPL2)
## Contributors
Lark is currently accepting pull-requests. See [How to develop Lark](/docs/how_to_develop.md)
Big thanks to everyone who contributed so far:
## Sponsor
If you like Lark, and want to see us grow, please consider [sponsoring us!](https://github.com/sponsors/lark-parser)
## Contact the author
Questions about code are best asked on [gitter](https://gitter.im/lark-parser/Lobby) or in the issues.
For anything else, I can be reached by email at erezshin at gmail com.
-- [Erez](https://github.com/erezsh)
lark-1.1.1/docs/ 0000775 0000000 0000000 00000000000 14200554527 0013377 5 ustar 00root root 0000000 0000000 lark-1.1.1/docs/Makefile 0000664 0000000 0000000 00000001131 14200554527 0015033 0 ustar 00root root 0000000 0000000 # Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXPROJ = Lark
SOURCEDIR = .
BUILDDIR = _build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) lark-1.1.1/docs/_static/ 0000775 0000000 0000000 00000000000 14200554527 0015025 5 ustar 00root root 0000000 0000000 lark-1.1.1/docs/_static/comparison_memory.png 0000664 0000000 0000000 00000064730 14200554527 0021307 0 ustar 00root root 0000000 0000000 PNG
IHDR R@ sBIT|d IDATxy|Y䄬 @l*`EB+jbmjZj{\ϲA@Ed%, a !!d!9Hr1CI@X˗33=3!""""b """"H1M!RDDDDLS"EDDD4H1M!RDDDDLS"EDDD4H1M!RDDDDLS"EDDD4H1M!RDDDDLS"EDDD4H1M!RDDDDLwDDDZS__kÇ}Z_UU3<5͚5_v^o}nY_Wznݺ]ņ
ٽ{7|>իGcǨn%߿ķu+:thV(D4m[F!rΝ~RĬl,X@MMB
ꫯ9s&h^Z:uLhh(tԉn|C!Rwgvۛ}vh\)yp H}}=RWWǛo?LNڹ/227ӹsgV/rP9ʼn'"55oСCԪn3dnݘ;wѳV]]fŊOמmW=V۹E"r*HoDFFRQQ%#c{cv|> ;vx^6nȖ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