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

Extended GrammarFuzzer to handle EBNF grammars. #114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion docs/beta/code/GrammarFuzzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,11 @@ def tree_to_string(tree):

class GrammarFuzzer(Fuzzer):
def __init__(self, grammar, start_symbol=START_SYMBOL,
min_nonterminals=0, max_nonterminals=10, disp=False, log=False):
min_nonterminals=0, max_nonterminals=10, conv=False, disp=False, log=False):
"""Produce strings from `grammar`, starting with `start_symbol`.
If `min_nonterminals` or `max_nonterminals` is given, use them as limits
for the number of nonterminals produced.
If `conv` is set, convert EBNF to BNF. (Converting BNF will have no impact.)
If `disp` is set, display the intermediate derivation trees.
If `log` is set, show intermediate steps as text on standard output."""

Expand All @@ -412,6 +413,8 @@ def __init__(self, grammar, start_symbol=START_SYMBOL,
self.disp = disp
self.log = log
self.check_grammar() # Invokes is_valid_grammar()
self.conv_grammar() # Invokes convert_ebnf_grammar() if conv is set
self.check_grammar()

#### Excursion: `check_grammar()` implementation

Expand All @@ -428,6 +431,10 @@ def check_grammar(self):
start_symbol=self.start_symbol,
supported_opts=self.supported_opts())

def conv_grammar(self):
if self.conv:
self.grammar = convert_ebnf_grammar(self.grammar)

def supported_opts(self):
return set()

Expand Down
9 changes: 8 additions & 1 deletion docs/code/GrammarFuzzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,11 @@ def tree_to_string(tree):

class GrammarFuzzer(Fuzzer):
def __init__(self, grammar, start_symbol=START_SYMBOL,
min_nonterminals=0, max_nonterminals=10, disp=False, log=False):
min_nonterminals=0, max_nonterminals=10, conv=False, disp=False, log=False):
"""Produce strings from `grammar`, starting with `start_symbol`.
If `min_nonterminals` or `max_nonterminals` is given, use them as limits
for the number of nonterminals produced.
If `conv` is set, convert EBNF to BNF. (Converting BNF will have no impact.)
If `disp` is set, display the intermediate derivation trees.
If `log` is set, show intermediate steps as text on standard output."""

Expand All @@ -412,6 +413,8 @@ def __init__(self, grammar, start_symbol=START_SYMBOL,
self.disp = disp
self.log = log
self.check_grammar() # Invokes is_valid_grammar()
self.conv_grammar() # Invokes convert_ebnf_grammar() if conv is set
self.check_grammar()

#### Excursion: `check_grammar()` implementation

Expand All @@ -428,6 +431,10 @@ def check_grammar(self):
start_symbol=self.start_symbol,
supported_opts=self.supported_opts())

def conv_grammar(self):
if self.conv:
self.grammar = convert_ebnf_grammar(self.grammar)

def supported_opts(self):
return set()

Expand Down