def load_bug(bug_fn, grammar_meta): with open(bug_fn) as f: bug_src = f.read() start = grammar_meta['[start]'] grammar = grammar_meta['[grammar]'] parser = Parser(grammar, start_symbol=start, canonical=True) # log=True) forest = parser.parse(bug_src.strip()) tree = list(forest)[0] return grammar_meta, coalesce(tree)
class EvalMysteryRunner(MysteryRunner): def __init__(self): self.parser = EarleyParser(EXPR_GRAMMAR) def run(self, inp): try: tree, *_ = self.parser.parse(inp) except SyntaxError as exc: return (inp, Runner.UNRESOLVED) return super().run(inp)
if __name__ == "__main__": print('\n### Counting Expansions') if __package__ is None or __package__ == "": from Parser import Parser, EarleyParser, PEGParser else: from .Parser import Parser, EarleyParser, PEGParser IP_ADDRESS_TOKENS = {"<octet>"} # EarleyParser needs explicit tokens if __name__ == "__main__": parser = EarleyParser(IP_ADDRESS_GRAMMAR) if __name__ == "__main__": tree = parser.parse("127.0.0.1")[0] display_tree(tree) class ExpansionCountMiner(object): def __init__(self, parser, log=False): assert isinstance(parser, Parser) self.grammar = extend_grammar(parser.grammar()) self.parser = parser self.log = log self.reset() if __package__ is None or __package__ == "": from GrammarCoverageFuzzer import expansion_key # minor dependency else:
assert is_valid_grammar(XML_GRAMMAR) if __package__ is None or __package__ == "": from Parser import EarleyParser else: from .Parser import EarleyParser if __package__ is None or __package__ == "": from GrammarFuzzer import display_tree else: from .GrammarFuzzer import display_tree if __name__ == "__main__": parser = EarleyParser(XML_GRAMMAR, tokens=XML_TOKENS) for tree in parser.parse("<html>Text</html>"): display_tree(tree) # ### Building the Fragment Pool if __name__ == "__main__": print('\n### Building the Fragment Pool') class FragmentMutator(Mutator): def __init__(self, parser): """Initialize empty fragment pool and add parser""" self.parser = parser self.fragments = {k: [] for k in self.parser.cgrammar} super().__init__()
if __name__ == "__main__": print('\n### Counting Expansions') if __package__ is None or __package__ == "": from Parser import Parser, EarleyParser, PEGParser else: from .Parser import Parser, EarleyParser, PEGParser IP_ADDRESS_TOKENS = {"<octet>"} # EarleyParser needs explicit tokens if __name__ == "__main__": parser = EarleyParser(IP_ADDRESS_GRAMMAR) if __name__ == "__main__": tree, *_ = parser.parse("127.0.0.1") display_tree(tree) class ExpansionCountMiner(object): def __init__(self, parser, log=False): assert isinstance(parser, Parser) self.grammar = extend_grammar(parser.grammar()) self.parser = parser self.log = log self.reset() if __package__ is None or __package__ == "": from GrammarCoverageFuzzer import expansion_key # minor dependency else:
if __package__ is None or __package__ == "": from GrammarFuzzer import display_tree else: from .GrammarFuzzer import display_tree if __package__ is None or __package__ == "": from Parser import EarleyParser else: from .Parser import EarleyParser if __name__ == "__main__": parser = EarleyParser(IP_ADDRESS_GRAMMAR) if __name__ == "__main__": tree = parser.parse("127.0.0.1")[0] display_tree(tree) if __name__ == "__main__": IP_ADDRESS_GRAMMAR["<octet>"] = list(sorted(decrange(0, 256), reverse=True)) if __package__ is None or __package__ == "": from Parser import PEGParser else: from .Parser import PEGParser if __name__ == "__main__": parser = PEGParser(IP_ADDRESS_GRAMMAR) tree = parser.parse("127.0.0.1")[0] display_tree(tree)