@@ -36,7 +36,7 @@ print( l.parse("Hello, World!") ) | |||||
And the output is: | And the output is: | ||||
```python | ```python | ||||
Tree(start, [Token(WORD, Hello), Token(WORD, World)]) | |||||
Tree(start, [Token(WORD, 'Hello'), Token(WORD, 'World')]) | |||||
``` | ``` | ||||
Notice punctuation doesn't appear in the resulting tree. It's automatically filtered away by Lark. | Notice punctuation doesn't appear in the resulting tree. It's automatically filtered away by Lark. | ||||
@@ -44,8 +44,15 @@ Notice punctuation doesn't appear in the resulting tree. It's automatically filt | |||||
## Learn more about using Lark | ## Learn more about using Lark | ||||
- Read the [tutorial](/docs/json_tutorial.md), which shows how to write a JSON parser in Lark. | - Read the [tutorial](/docs/json_tutorial.md), which shows how to write a JSON parser in Lark. | ||||
- Browse the [examples](/examples), which include a calculator, and a Python-code parser. | |||||
- Read the [reference](/docs/reference.md) | - Read the [reference](/docs/reference.md) | ||||
- Browse the [examples](/examples), which include a calculator, and a Python-code parser. | |||||
- Check out the [tests](/tests/test_parser.py) for more examples. | |||||
## Install Lark | |||||
$ pip install lark-parser | |||||
Lark has no dependencies. | |||||
## List of Features | ## List of Features | ||||
@@ -74,7 +81,7 @@ This is a feature comparison. For benchmarks vs pyparsing, check out the [JSON t | |||||
| [PLY](http://www.dabeaz.com/ply/) | LALR(1) | 4.6K | Yacc-like BNF | No | | | [PLY](http://www.dabeaz.com/ply/) | LALR(1) | 4.6K | Yacc-like BNF | No | | ||||
| [PyParsing](http://pyparsing.wikispaces.com/) | PEG | 5.7K | Parser combinators | No | | | [PyParsing](http://pyparsing.wikispaces.com/) | PEG | 5.7K | Parser combinators | No | | ||||
| [Parsley](https://pypi.python.org/pypi/Parsley) | PEG | 3.3K | EBNF-like | No | | | [Parsley](https://pypi.python.org/pypi/Parsley) | PEG | 3.3K | EBNF-like | No | | ||||
| [funcparselib](https://github.com/vlasovskikh/funcparserlib) | Recursive-Descent | 0.5K | Parser combinators | No | | |||||
| [funcparserlib](https://github.com/vlasovskikh/funcparserlib) | Recursive-Descent | 0.5K | Parser combinators | No | | |||||
(*LOC measures lines of code of the parsing algorithm(s), without accompanying files*) | (*LOC measures lines of code of the parsing algorithm(s), without accompanying files*) | ||||
@@ -408,8 +408,9 @@ I measured memory consumption using a little script called [memusg](https://gist | |||||
| Lark - LALR(1) | 7s | 1.3s | 0.6M | 0.3M | | | Lark - LALR(1) | 7s | 1.3s | 0.6M | 0.3M | | ||||
| Lark - LALR(1) tree-less | 4.2s | 1.1s | 0.4M | 0.3M | | | Lark - LALR(1) tree-less | 4.2s | 1.1s | 0.4M | 0.3M | | ||||
| PyParsing ([Parser](http://pyparsing.wikispaces.com/file/view/jsonParser.py)) | 32s | 4.1s | 0.4M | 0.2M | | | PyParsing ([Parser](http://pyparsing.wikispaces.com/file/view/jsonParser.py)) | 32s | 4.1s | 0.4M | 0.2M | | ||||
| funcparselibr ([Parser](https://github.com/vlasovskikh/funcparserlib/blob/master/funcparserlib/tests/json.py)) | 11s | 1.9s | 0.5M | 0.3M | | |||||
I added PyParsing for comparison. It fairs pretty well in its memory usage, but it can't compete with the run-time speed of LALR(1). | |||||
I added PyParsing and funcparselib for comparison. They fair pretty well in their memory usage (they don't build a tree), but they can't compete with the run-time speed of LALR(1). | |||||
These benchmarks are for Lark's alpha version. I already have several optimizations planned that will significantly improve run-time speed. | These benchmarks are for Lark's alpha version. I already have several optimizations planned that will significantly improve run-time speed. | ||||
@@ -4,6 +4,8 @@ | |||||
Lark is a general-purpose parsing library. It's written in Python, and supports two parsing algorithms: Earley (default) and LALR(1). | Lark is a general-purpose parsing library. It's written in Python, and supports two parsing algorithms: Earley (default) and LALR(1). | ||||
Lark is a re-write of my previous parsing library, [PlyPlus](https://github.com/erezsh/plyplus). | |||||
## Grammar | ## Grammar | ||||
Lark accepts its grammars in [EBNF](https://www.wikiwand.com/en/Extended_Backus%E2%80%93Naur_form) form. | Lark accepts its grammars in [EBNF](https://www.wikiwand.com/en/Extended_Backus%E2%80%93Naur_form) form. | ||||
@@ -23,7 +23,7 @@ class Token(Str): | |||||
return inst | return inst | ||||
def __repr__(self): | def __repr__(self): | ||||
return 'Token(%s, %s)' % (self.type, self.value) | |||||
return 'Token(%s, %r)' % (self.type, self.value) | |||||
class Regex: | class Regex: | ||||
def __init__(self, pattern, flags=()): | def __init__(self, pattern, flags=()): | ||||
@@ -0,0 +1,5 @@ | |||||
[global] | |||||
zip_safe= | |||||
[metadata] | |||||
description-file = README.md |