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

grammarinator-generate fails for the PostgreSQL grammar #41

Closed
mrigger opened this issue Feb 8, 2022 · 3 comments
Closed

grammarinator-generate fails for the PostgreSQL grammar #41

mrigger opened this issue Feb 8, 2022 · 3 comments

Comments

@mrigger
Copy link

mrigger commented Feb 8, 2022

While, as described in #40, grammarinator-process failed for the SQLite and MySQL grammars, it processed the grammars of PostgreSQL without any issues.

However, executing grammarinator-generate PostgreSQLGenerator.PostgreSQLGenerator -r root -d 5 -o test%d.sql -n 100 --sys-path . in the directory of PostgreSQLGenerator.py resulted in errors.

First, I found that grammarinator included a multi-line comment starting with /* from the grammar, which is not valid in Python and caused it to fail with an error:

  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "./PostgreSQLGenerator.py", line 22
    /* This field stores the tags which are used to detect the end of a dollar-quoted string literal.
    ^ 

After fixing this in the generated code, a follow-up failure with an invalid indent appeared:

  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "./PostgreSQLGenerator.py", line 15292
    ParseRoutineBody(_localctx);
    ^

By reducing the indent, the failure disappeared, but the next failure appeared which I did not investigate:

  File "./PostgreSQLGenerator.py", line 11, in <module>
    from PostgreSQLParserBase import PostgreSQLParserBase
ModuleNotFoundError: No module named 'PostgreSQLParserBase'
@renatahodovan
Copy link
Owner

Hi @mrigger !

While Grammarinator and ANTLR share many design patterns, like the possibility of inlined code and the definition of superclasses, they cannot share the same inlined code or the same superclass. It's true simply because their purposes are different: recognition vs. generation. Furthermore, while ANTLR supports inlined code in multiple languages, Grammarinator only supports Python right now.

Regarding the failures in this report, the first two errors are caused by inlined Java parser code in the grammars. On one hand, their purpose is to improve parsing, hence they are useless in our generation scenario. On the other hand, they are written in Java which is not supported by Grammarinator. To avoid these kind of issues, please use the --no-actions CLI option with grammarinator-process. (If you need, you can use inline code ofc, but only in Python.)

The third error is due to the "missing" PostgreSQLParserBase superclass, which is required by the generated ANTLR parser, but not needed by the generated fuzzer (recognition vs. generation again). To overcome this issue, you should comment out the superClass = ... options from the raw grammars. (If you need your own superclass, then you can use this syntax to define it ofc, but you must ensure to place the superclass file on PYTHONPATH.)

I hope it helps! Please let me know if you have any further questions.

Cheers,
Reni

@renatahodovan
Copy link
Owner

@mrigger I think we can consider this issue as "fixed". Please feel free to reopen if it still stands.

@mrigger
Copy link
Author

mrigger commented Apr 20, 2022

Thanks a lot for the detailed explanation!

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