Skip to content

Commit

Permalink
#34: Renamed depend argument and added new dependencies argument
Browse files Browse the repository at this point in the history
  • Loading branch information
ferraith committed Jul 28, 2018
1 parent 213dc97 commit 3d5460a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
18 changes: 11 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ See ``python setup.py antlr --help`` for available command line options:
...
Options for 'AntlrCommand' command:
--grammars (-g) specify grammars to generate parsers for
--output (-o) specify output directories where output is generated
--output (-o) specify directories where output is generated
--dependencies (-d) generate parser for every grammar a passed grammar depends on
--atn generate rule augmented transition network diagrams
--encoding specify grammar file encoding e.g. euc-jp
--message-format specify output style for messages in antlr, gnu, vs2005
Expand All @@ -124,7 +125,7 @@ See ``python setup.py antlr --help`` for available command line options:
--no-listener don't generate parse tree listener
--visitor generate parse tree visitor
--no-visitor don't generate parse tree visitor (default)
--depend generate file dependencies
--file-dependencies generate list of file dependencies instead of parsers
--grammar-options set/override a grammar-level option
--w-error treat warnings as error
--x-dbg-st launch StringTemplate visualizer on generated code
Expand All @@ -142,9 +143,12 @@ Apart from passing options on the command line it's also possible to add a dedic
[antlr]
# Specify grammars to generate parsers for; default: None
#grammars = <root-level grammar> [<root-level-grammar> ...]
# Specify output directories where all output is generated; default: ./
output = default=gen
#grammars = <grammar> [<grammar> ...]
# Specify directories where output is generated; default: ./
#output = [default=<output path>]
# [<grammar>=<output path> ...]
# Generate parser for every grammar a passed grammar depends on (yes|no); default: no
#dependencies = no
# Generate DOT graph files that represent the internal ATN data structures (yes|no); default: no
#atn = no
# Specify grammar file encoding; default: utf-8
Expand All @@ -157,8 +161,8 @@ Apart from passing options on the command line it's also possible to add a dedic
#listener = yes
# Generate parse tree visitor (yes|no); default: no
visitor = yes
# Generate file dependencies (yes|no); default: no
#depend = no
# Generate list of file dependencies instead of parsers (yes|no); default: no
#file-dependencies = no
# Set/override grammar-level options (<option>=<value> [<option>=value ...]); default: language=Python3
grammar-options = superClass=Abc
tokenVocab=SomeLexer
Expand Down
12 changes: 7 additions & 5 deletions example/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[antlr]
# Specify grammars to generate parsers for; default: None
#grammars = <root-level grammar> [<root-level-grammar> ...]
# Specify output directories where output is generated; default: ./
#grammars = <grammar> [<grammar> ...]
# Specify directories where output is generated; default: ./
#output = [default=<output path>]
# [<root-level grammar>=<output path> ...]
# [<grammar>=<output path> ...]
# Generate parser for every grammar a passed grammar depends on (yes|no); default: no
#dependencies = no
# Generate DOT graph files that represent the internal ATN data structures (yes|no); default: no
#atn = no
# Specify grammar file encoding; default: utf-8
Expand All @@ -16,8 +18,8 @@
#listener = yes
# Generate parse tree visitor (yes|no); default: no
#visitor = no
# Generate file dependencies (yes|no); default: no
#depend = no
# Generate list of file dependencies instead of parsers (yes|no); default: no
#file-dependencies = no
# Set/override grammar-level options (<option>=<value> [<option>=value ...]); default: language=Python3
# Documentation of all grammar-level options
# See https://github.com/antlr/antlr4/blob/master/doc/options.md
Expand Down
16 changes: 9 additions & 7 deletions setuptools_antlr/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ class AntlrCommand(setuptools.Command):

user_options = [
('grammars=', 'g', 'specify grammars to generate parsers for'),
('output=', 'o', 'specify output directories where output is generated'),
('output=', 'o', 'specify directories where output is generated'),
('dependencies=', 'd', 'generate parser for every grammar a passed grammar depends on'),
('atn', None, 'generate rule augmented transition network diagrams'),
('encoding=', None, 'specify grammar file encoding e.g. euc-jp'),
('message-format=', None, 'specify output style for messages in antlr, gnu, vs2005'),
Expand All @@ -119,7 +120,7 @@ class AntlrCommand(setuptools.Command):
('no-listener', None, 'don\'t generate parse tree listener'),
('visitor', None, 'generate parse tree visitor'),
('no-visitor', None, 'don\'t generate parse tree visitor (default)'),
('depend', None, 'generate file dependencies'),
('file-dependencies', None, 'generate list of file dependencies instead of parsers'),
('grammar-options=', None, "set/override a grammar-level options"),
('w-error', None, 'treat warnings as error'),
('x-dbg-st', None, 'launch StringTemplate visualizer on generated code'),
Expand All @@ -130,8 +131,8 @@ class AntlrCommand(setuptools.Command):
]

boolean_options = ['atn', 'long-messages', 'listener', 'no-listener', 'visitor', 'no-visitor',
'depend', 'w-error', 'x-dbg-st', 'x-dbg-st-wait', 'x-exact-output-dir',
'x-force-atn', 'x-log']
'file-dependencies', 'w-error', 'x-dbg-st', 'x-dbg-st-wait',
'x-exact-output-dir', 'x-force-atn', 'x-log']

negative_opt = {'no-listener': 'listener', 'no-visitor': 'visitor'}

Expand All @@ -142,13 +143,14 @@ def initialize_options(self):
"""
self.grammars = None
self.output = {}
self.dependencies = 0
self.atn = 0
self.encoding = None
self.message_format = None
self.long_messages = 0
self.listener = 1
self.visitor = 0
self.depend = 0
self.file_dependencies = 0
self.grammar_options = {}
self.w_error = 0
self.x_dbg_st = 0
Expand Down Expand Up @@ -337,7 +339,7 @@ def run(self):
run_args.append('-long-messages')
run_args.append('-listener' if self.listener else '-no-listener')
run_args.append('-visitor' if self.visitor else '-no-visitor')
if self.depend:
if self.file_dependencies:
run_args.append('-depend')
run_args.extend(['-D{}={}'.format(option, value) for option, value in
self.grammar_options.items()])
Expand Down Expand Up @@ -384,7 +386,7 @@ def run(self):
grammar_file = grammar.path.name
run_args.append(str(grammar_file))

if self.depend:
if self.file_dependencies:
dependency_file = pathlib.Path(package_dir, 'dependencies.txt')
distutils.log.info('generating {} file dependencies -> {}'.format(grammar_file,
dependency_file))
Expand Down
10 changes: 5 additions & 5 deletions test/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def test_finalize_options_default(self, command):
assert command.long_messages == 0
assert command.listener == 1
assert command.visitor == 0
assert command.depend == 0
assert command.file_dependencies == 0
assert command.grammar_options['language'] == 'Python3'
assert command.w_error == 0
assert command.x_dbg_st == 0
Expand Down Expand Up @@ -553,10 +553,10 @@ def test_run_grammar_options_not_specified(self, mock_run, configured_command):

@pytest.mark.usefixtures('configured_command')
@unittest.mock.patch('subprocess.run')
def test_run_depend_enabled(self, mock_run, configured_command):
def test_run_file_dependencies_enabled(self, mock_run, configured_command):
mock_run.return_value = unittest.mock.Mock(returncode=0, stdout='FooParser.py : Foo.g4')

configured_command.depend = 1
configured_command.file_dependencies = 1
configured_command.run()

args, _ = mock_run.call_args
Expand All @@ -565,9 +565,9 @@ def test_run_depend_enabled(self, mock_run, configured_command):

@pytest.mark.usefixtures('configured_command')
@unittest.mock.patch('subprocess.run')
def test_run_depend_disabled(self, mock_run, configured_command):
def test_run_file_dependencies_disabled(self, mock_run, configured_command):
mock_run.return_value = unittest.mock.Mock(returncode=0)
configured_command.depend = 0
configured_command.file_dependencies = 0
configured_command.run()

args, _ = mock_run.call_args
Expand Down

0 comments on commit 3d5460a

Please sign in to comment.