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

Wrong indentation in generated Python code #50

Closed
ligurio opened this issue Jul 4, 2022 · 2 comments
Closed

Wrong indentation in generated Python code #50

ligurio opened this issue Jul 4, 2022 · 2 comments

Comments

@ligurio
Copy link

ligurio commented Jul 4, 2022

Steps to reproduce:

  • git clone https://github.com/renatahodovan/grammarinator, f85b80c
  • cd grammarinator && pip3 install .
  • mkdir lua-examples lua-fuzzer
  • curl -O https://raw.githubusercontent.com/antlr/grammars-v4/master/lua/Lua.g4
  • grammarinator-process Lua.g4 -o lua-fuzzer/ --pep8 -v
  • grammarinator-generate LuaGenerator.LuaGenerator -r chunk -d 20 -o lua-examples/test_%d.lua -n 100 -s grammarinator.runtime.simple_space_serializer --sys-path lua-fuzzer/

Syntax error in the generated file:

Traceback (most recent call last):
  File "/home/sergeyb/.local/bin/grammarinator-generate", line 8, in <module>
    sys.exit(execute())
  File "/home/sergeyb/.local/lib/python3.8/site-packages/grammarinator/generate.py", line 294, in execute
    with Generator(generator=args.generator, rule=args.rule, out_format=args.out,
  File "/home/sergeyb/.local/lib/python3.8/site-packages/grammarinator/generate.py", line 72, in __init__
    self.generator_cls = import_object(generator) if generator else None
  File "/home/sergeyb/.local/lib/python3.8/site-packages/inators/imp.py", line 24, in import_object
    return getattr(importlib.import_module('.'.join(steps[0:-1])), steps[-1])
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 844, in exec_module
  File "<frozen importlib._bootstrap_external>", line 981, in get_code
  File "<frozen importlib._bootstrap_external>", line 911, in source_to_code
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/sergeyb/sources/MRG/tarantool/grammarinator/lua-fuzzer/LuaGenerator.py", line 988
    elif choice == 1:
    ^
SyntaxError: invalid syntax

Seems indentation is wrong and patch below fixes a problem:

--- lua-fuzzer/LuaGenerator.py.orig     2022-07-04 15:52:37.284564569 +0300
+++ lua-fuzzer/LuaGenerator.py  2022-07-04 15:52:56.883836234 +0300
@@ -985,7 +985,8 @@
         choice = self._model.choice(current, 0, [0 if [
                                     0, 0, 0, 0][i] > self._max_depth else w for i, w in enumerate([1, 1, 1, 1])])
         if choice == 0:
-            elif choice == 1:
+            pass
+        elif choice == 1:
             UnlexerRule(src='[', parent=current)
             if self._max_depth >= 0:
                 for _ in self._model.quantify(current, 0, min=0, max=inf):
@ligurio ligurio changed the title Wrong formatting in generated Python code Wrong indentation in generated Python code Jul 4, 2022
@renatahodovan
Copy link
Owner

@ligurio Thanks for the report! It pointed out a real issue indeed which is hopefully fixed now. Please don't hesitate to reopen this ticket if the the issue still persist for you.

@ligurio
Copy link
Author

ligurio commented Jul 9, 2022

Fix confirmed on version 19.3.post98+gf38ffe5. Thanks a lot for a quick response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants