Skip to content

Commit

Permalink
style: run pre-commit
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed May 25, 2022
1 parent 61ea19b commit 5236ff9
Show file tree
Hide file tree
Showing 56 changed files with 73 additions and 99 deletions.
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: ''

---


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
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
```
```
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
6 changes: 3 additions & 3 deletions lark/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def get_context(self, text: str, span: int=40) -> str:
after = text[pos:end].split(b'\n', 1)[0]
return (before + after + b'\n' + b' ' * len(before.expandtabs()) + b'^\n').decode("ascii", "backslashreplace")

def match_examples(self, parse_fn: 'Callable[[str], Tree]',
def match_examples(self, parse_fn: 'Callable[[str], Tree]',
examples: Union[Mapping[T, Iterable[str]], Iterable[Tuple[T, Iterable[str]]]],
token_type_match_fallback: bool=False,
use_accepts: bool=True
Expand Down 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 Expand Up @@ -229,7 +229,7 @@ class UnexpectedToken(ParseError, UnexpectedInput):

def __init__(self, token, expected, considered_rules=None, state=None, interactive_parser=None, terminals_by_name=None, token_history=None):
super(UnexpectedToken, self).__init__()

# TODO considered_rules and expected can be figured out using state
self.line = getattr(token, 'line', '?')
self.column = getattr(token, 'column', '?')
Expand Down
14 changes: 7 additions & 7 deletions lark/grammars/python.lark
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ lambda_kwparams: "**" name ","?
?stmt: simple_stmt | compound_stmt
?simple_stmt: small_stmt (";" small_stmt)* [";"] _NEWLINE
?small_stmt: (expr_stmt | assign_stmt | del_stmt | pass_stmt | flow_stmt | import_stmt | global_stmt | nonlocal_stmt | assert_stmt)
expr_stmt: testlist_star_expr
expr_stmt: testlist_star_expr
assign_stmt: annassign | augassign | assign

annassign: testlist_star_expr ":" test ["=" test]
assign: testlist_star_expr ("=" (yield_expr|testlist_star_expr))+
augassign: testlist_star_expr augassign_op (yield_expr|testlist)
!augassign_op: "+=" | "-=" | "*=" | "@=" | "/=" | "%=" | "&=" | "|=" | "^=" | "<<=" | ">>=" | "**=" | "//="
?testlist_star_expr: test_or_star_expr
?testlist_star_expr: test_or_star_expr
| test_or_star_expr ("," test_or_star_expr)+ ","? -> tuple
| test_or_star_expr "," -> tuple

Expand Down Expand Up @@ -95,13 +95,13 @@ for_stmt: "for" exprlist "in" testlist ":" suite ["else" ":" suite]
try_stmt: "try" ":" suite except_clauses ["else" ":" suite] [finally]
| "try" ":" suite finally -> try_finally
finally: "finally" ":" suite
except_clauses: except_clause+
except_clauses: except_clause+
except_clause: "except" [test ["as" name]] ":" suite
// NB compile.c makes sure that the default except clause is last


with_stmt: "with" with_items ":" suite
with_items: with_item ("," with_item)*
with_items: with_item ("," with_item)*
with_item: test ["as" name]

match_stmt: "match" test ":" _NEWLINE _INDENT case+ _DEDENT
Expand Down Expand Up @@ -204,7 +204,7 @@ AWAIT: "await"
| "{" _set_exprlist "}" -> set
| "{" comprehension{test} "}" -> set_comprehension
| name -> var
| number
| number
| string_concat
| "(" test ")"
| "..." -> ellipsis
Expand All @@ -217,7 +217,7 @@ AWAIT: "await"

_testlist_comp: test | _tuple_inner
_tuple_inner: test_or_star_expr (("," test_or_star_expr)+ [","] | ",")


?test_or_star_expr: test
| star_expr
Expand Down Expand Up @@ -253,7 +253,7 @@ kwargs: "**" test ("," argvalue)*


comprehension{comp_result}: comp_result comp_fors [comp_if]
comp_fors: comp_for+
comp_fors: comp_for+
comp_for: [ASYNC] "for" exprlist "in" or_test
ASYNC: "async"
?comp_if: "if" test_nocond
Expand Down
Loading

0 comments on commit 5236ff9

Please sign in to comment.