Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to merge PR #1151 #1205

Merged
merged 4 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/ISSUE_TEMPLATE/other.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ labels: ''
assignees: ''

---


10 changes: 9 additions & 1 deletion .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
name: Python type check
on: [push, pull_request]
jobs:
build:
type:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Lint with mypy
run: pipx run tox -e type

pre-commit:
name: Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/action@v2.0.3
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ tags
/dist
/build
docs/_build
docs/examples
docs/examples
32 changes: 32 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# To use:
#
# pre-commit run -a
#
# Or:
#
# pre-commit install # (runs every time you commit in git)
#
# To update this file:
#
# pre-commit autoupdate
#
# See https://github.com/pre-commit/pre-commit

repos:
# Standard hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.2.0"
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
exclude: '(^tests/.*\.lark|\.svg)$'
- id: mixed-line-ending
- id: requirements-txt-fixer
- id: trailing-whitespace
exclude: '(^tests/.*\.lark|\.svg)$'
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ v1.0

- `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)`
- `v_args(meta=True)` now gives meta as the first argument. i.e. `(meta, children)`
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ 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.

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Lark is great at handling ambiguity. Here is the result of parsing the phrase "f
- 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 [![codecov](https://codecov.io/gh/lark-parser/lark/branch/master/graph/badge.svg?token=lPxgVhCVPK)](https://codecov.io/gh/lark-parser/lark)
- Extensive test suite [![codecov](https://codecov.io/gh/lark-parser/lark/branch/master/graph/badge.svg?token=lPxgVhCVPK)](https://codecov.io/gh/lark-parser/lark)
- Type annotations (MyPy support)
- And much more!

Expand Down Expand Up @@ -193,4 +193,3 @@ Questions about code are best asked on [gitter](https://gitter.im/lark-parser/Lo
For anything else, I can be reached by email at erezshin at gmail com.

-- [Erez](https://github.com/erezsh)

2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ help:
# 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)
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
2 changes: 1 addition & 1 deletion docs/_static/sppf/sppf.html
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,4 @@ <h2 id="transformation-to-an-abstract-syntax-tree">Transformation to an abstract
</div>

</footer>
</body>
</body>
4 changes: 2 additions & 2 deletions docs/classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ InteractiveParser
ast_utils
---------

For an example of using ``ast_utils``, see `/examples/advanced/create_ast.py`_
For an example of using ``ast_utils``, see `/examples/advanced/create_ast.py`_

.. autoclass:: lark.ast_utils.Ast

.. autoclass:: lark.ast_utils.AsList

.. autofunction:: lark.ast_utils.create_transformer

.. _/examples/advanced/create_ast.py: examples/advanced/create_ast.html
.. _/examples/advanced/create_ast.py: examples/advanced/create_ast.html
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,4 @@
sphinx_gallery_conf = {
'examples_dirs': ['../examples'],
'gallery_dirs': ['examples'],
}
}
1 change: 0 additions & 1 deletion docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@
- Visualize your parse trees as dot or png files ([see_example](https://github.com/lark-parser/lark/blob/master/examples/fruitflies.py))
- Automatic reconstruction of input from parse-tree (see examples)
- Use Lark grammars in Julia and Javascript.

2 changes: 1 addition & 1 deletion docs/how_to_develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ pytest tests
Another way to run the tests is using setup.py:

```bash
python setup.py test
python setup.py test
```
1 change: 0 additions & 1 deletion docs/ide/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,3 @@ def start():
html5.Body().appendChild(
App()
)

2 changes: 1 addition & 1 deletion docs/ide/app/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,4 @@
"favoriteFruit": "strawberry"
}
]""")
}
}
2 changes: 1 addition & 1 deletion docs/ide/app/files.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"ext.py",
"ignite.py",
"utils.py"
]
]
2 changes: 0 additions & 2 deletions docs/ide/app/html5.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@

from .core import *
from . import ext, utils, ignite


1 change: 0 additions & 1 deletion docs/philosophy.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,3 @@ In short, "Premature optimization is the root of all evil."
- Automatically resolve terminal collisions whenever possible

- Automatically keep track of line & column numbers

2 changes: 1 addition & 1 deletion docs/recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,4 @@ try:
print( t.transform(tree))
except VisitError as e:
raise e.orig_exc
```
```
4 changes: 2 additions & 2 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# https://docs.readthedocs.io/en/stable/guides/specifying-dependencies.html#specifying-a-requirements-file
pillow
recommonmark
sphinx-gallery
sphinx_markdown_tables
recommonmark
sphinx_rtd_theme
pillow
1 change: 0 additions & 1 deletion docs/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,3 @@ python -m lark.tools.nearley nearley/examples/calculator/arithmetic.ne main near
- Lark currently cannot export grammars to Nearley

These might get added in the future, if enough users ask for them.

2 changes: 1 addition & 1 deletion docs/visitors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,4 @@ Discard
VisitError
----------

.. autoclass:: lark.exceptions.VisitError
.. autoclass:: lark.exceptions.VisitError
1 change: 0 additions & 1 deletion examples/advanced/error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@ def main():
print(res) # prints [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0]

main()

2 changes: 0 additions & 2 deletions examples/advanced/error_reporting_earley.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,3 @@ def test():

if __name__ == '__main__':
test()


2 changes: 0 additions & 2 deletions examples/advanced/error_reporting_lalr.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,3 @@ def test():

if __name__ == '__main__':
test()


8 changes: 4 additions & 4 deletions examples/advanced/py3to2.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ def parse_code(s):

#
# 2. Define translations using templates (each template code is parsed to a template tree)
#
#

pytemplate = TemplateConf(parse=parse_template)

translations_3to2 = {
'yield from $a':
'yield from $a':
'for _tmp in $a: yield _tmp',

'raise $e from $x':
Expand All @@ -63,7 +63,7 @@ def parse_code(s):

#
# 3. Translate and reconstruct Python 3 code into valid Python 2 code
#
#

python_reconstruct = PythonReconstructor(parser)

Expand Down Expand Up @@ -91,4 +91,4 @@ def test():
print(translate_py3to2(_TEST_CODE))

if __name__ == '__main__':
test()
test()
1 change: 0 additions & 1 deletion examples/advanced/python2.lark
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,3 @@ IMAG_NUMBER: (_INT | FLOAT) ("j"|"J")
%ignore /\\[\t \f]*\r?\n/ // LINE_CONT
%ignore COMMENT
%declare _INDENT _DEDENT

2 changes: 1 addition & 1 deletion examples/advanced/python_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ def test_earley_equals_lalr():
if __name__ == '__main__':
test_python_lib()
# test_earley_equals_lalr()
# python_parser3.parse(_read(sys.argv[1]) + '\n')
# python_parser3.parse(_read(sys.argv[1]) + '\n')
2 changes: 1 addition & 1 deletion examples/advanced/reconstruct_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ def test():


if __name__ == '__main__':
test()
test()
2 changes: 1 addition & 1 deletion examples/advanced/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
parser = Lark(grammar)

print(parser.parse('[1, "a", 2]'))
print(parser.parse('{"a": 2, "b": 6}'))
print(parser.parse('{"a": 2, "b": 6}'))
2 changes: 1 addition & 1 deletion examples/composition/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ file format that allows both CSV and JSON to co-exist.
We show how, by using namespaces, Lark grammars and their transformers can be fully reused -
they don't need to care if their grammar is used directly, or being imported, or who is doing the importing.

See [``main.py``](main.py) for more details.
See [``main.py``](main.py) for more details.
2 changes: 1 addition & 1 deletion examples/composition/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ def main():


if __name__ == "__main__":
main()
main()
1 change: 0 additions & 1 deletion examples/composition/storage.lark
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ start: (csv__start | json__start _NL?)+
%import .json.start -> json__start

%import .csv._NL -> _NL

2 changes: 1 addition & 1 deletion examples/grammars/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

This directory is a collection of lark grammars, taken from real world projects.

- [Verilog](verilog.lark) - Taken from https://github.com/circuitgraph/circuitgraph/blob/master/circuitgraph/parsing/verilog.lark
- [Verilog](verilog.lark) - Taken from https://github.com/circuitgraph/circuitgraph/blob/master/circuitgraph/parsing/verilog.lark
6 changes: 3 additions & 3 deletions examples/grammars/verilog.lark
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

// 1. Source Text
start: description*

?description: module

module: "module" name_of_module list_of_ports? ";" module_item* "endmodule"

?name_of_module: IDENTIFIER

list_of_ports: "(" port ("," port)* ")"

?port: IDENTIFIER

?module_item: input_declaration
| output_declaration
| net_declaration
Expand Down
1 change: 0 additions & 1 deletion examples/indented_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,3 @@ def test():

if __name__ == '__main__':
test()

1 change: 0 additions & 1 deletion examples/standalone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ Then run using:
```bash
python json_parser_main.py <path-to.json>
```

1 change: 0 additions & 1 deletion examples/standalone/json_parser_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@ def string(self, s):
if __name__ == '__main__':
with open(sys.argv[1]) as f:
print(parser.parse(f.read()))

2 changes: 1 addition & 1 deletion examples/tests/no_newline_at_end.lark
Original file line number Diff line number Diff line change
@@ -1 +1 @@
start: "a"
start: "a"
2 changes: 1 addition & 1 deletion lark/__pyinstaller/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
import os

def get_hook_dirs():
return [os.path.dirname(__file__)]
return [os.path.dirname(__file__)]
2 changes: 1 addition & 1 deletion lark/ast_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def create_transformer(ast_module: types.ModuleType,
Parameters:
ast_module: A Python module containing all the subclasses of ``ast_utils.Ast``
transformer (Optional[Transformer]): An initial transformer. Its attributes may be overwritten.
decorator_factory (Callable): An optional callable accepting two booleans, inline, and meta,
decorator_factory (Callable): An optional callable accepting two booleans, inline, and meta,
and returning a decorator for the methods of ``transformer``. (default: ``v_args``).
"""
t = transformer or Transformer()
Expand Down
2 changes: 1 addition & 1 deletion lark/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def __str__(self):


class UnexpectedCharacters(LexError, UnexpectedInput):
"""An exception that is raised by the lexer, when it cannot match the next
"""An exception that is raised by the lexer, when it cannot match the next
string of characters to any of its terminals.
"""

Expand Down
Loading