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

Can't get this to work #42

Closed
kaby76 opened this issue Feb 15, 2022 · 2 comments
Closed

Can't get this to work #42

kaby76 opened this issue Feb 15, 2022 · 2 comments

Comments

@kaby76
Copy link

kaby76 commented Feb 15, 2022

I'm trying to understand how to run Grammarinator with a minimal knowledge beyond Linux/Bash/Antlr4. Unfortunately, I can't get far past the first two lines (one to build it after cloning, the other grammarinator-process).

Following the instructions starting here and filling in the details as though it's written for GitHub Actions:

git clone https://github.com/renatahodovan/grammarinator.git
cd grammarinator

pip --version
# pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)

pip install .
mkdir x
cd x
cat << END > Expr.g4
grammar Expr;
file_ : expr EOF;
expr : expr ('*' | '/') expr | expr ('+' | '-') expr | '(' expr ')' | ('+' | '-')* atom ;
atom : INT;
INT : [0..9]+;
WS : [ \r\n\t] + -> channel(HIDDEN) ;
END

java --version
# openjdk 11.0.13 2021-10-19
# OpenJDK Runtime Environment (build 11.0.13+8-Ubuntu-0ubuntu1.20.04)
# OpenJDK 64-Bit Server VM (build 11.0.13+8-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)

java -jar /mnt/c/Users/Kenne/Downloads/antlr-4.9.3-complete.jar Expr.g4
# (Antlr4 works.)

grammarinator-process Expr.g4 -o .
# (grammarinator-process works.)

ls -l ExprGenerator.py
# -rwxrwxrwx 1 ken ken 3808 Feb 15 18:29 ExprGenerator.py*

grammarinator-generate
# grammarinator-generate: error: the following arguments are required: NAME

grammarinator-generate ExprGenerator
# Traceback (most recent call last):
#   File "/home/ken/.local/bin/grammarinator-generate", line 8, in <module>
#     sys.exit(execute())
#   File "/home/ken/.local/lib/python3.8/site-packages/grammarinator/generate.py", line 295, in execute
#     with Generator(generator=args.generator, rule=args.rule, out_format=args.out,
#   File "/home/ken/.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/ken/.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 1011, in _gcd_import
#   File "<frozen importlib._bootstrap>", line 950, in _sanity_check
# ValueError: Empty module name

grammarinator-generate ExprGenerator.ExprGenerator
# Traceback (most recent call last):
#   File "/home/ken/.local/bin/grammarinator-generate", line 8, in <module>
#     sys.exit(execute())
#   File "/home/ken/.local/lib/python3.8/site-packages/grammarinator/generate.py", line 295, in execute
#     with Generator(generator=args.generator, rule=args.rule, out_format=args.out,
#   File "/home/ken/.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/ken/.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 973, in _find_and_load_unlocked
# ModuleNotFoundError: No module named 'ExprGenerator'

I just want to see what grammarinator-generate outputs. The instructions are inadequate.

@akosthekiss
Copy link
Collaborator

Current directory isn't on the search path for modules (available inside the python interpreter as sys.path, see https://docs.python.org/3/library/sys.html). This can be added either via the PYTHONPATH environment variable or using the --sys-path command line option (see grammarinator-generate --help).

The following worked for me: grammarinator-generate ExprGenerator.ExprGenerator --max-depth 10 --sys-path . -n 10 (also note --max-depth aka -d, and -n).

The readme actually mentions all these command line options at

grammarinator/README.rst

Lines 172 to 175 in 583ebca

grammarinator-generate HTMLCustomGenerator.HTMLCustomGenerator -r htmlDocument -d 20 \
-o examples/tests/test_%d.html -n 100 \
-s HTMLGenerator.html_space_serializer \
--sys-path examples/fuzzer/

@kaby76
Copy link
Author

kaby76 commented Feb 16, 2022

@akosthekiss Thanks that works.

@kaby76 kaby76 closed this as completed Feb 16, 2022
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