Exemple #1
0
 def grammar(self, ast, *args):
     directives = OrderedDict((d.name, d.value) for d in ast.directives)
     keywords = set(ast.keywords or [])
     return grammars.Grammar(self.grammar_name,
                             list(self.rules.values()),
                             directives=directives,
                             keywords=keywords)
    def grammar(self, ast, *args):
        directives = OrderedDict(
            (d.name, d.value) for d in flatten(ast.directives))
        keywords = set(flatten(ast.keywords) or [])

        if directives.get('whitespace') in ('None', 'False'):
            directives['whitespace'] = ''

        return grammars.Grammar(self.grammar_name,
                                list(self.rules.values()),
                                directives=directives,
                                keywords=keywords)
Exemple #3
0
def generate_tatsu_grammar(grammar: gll_grammar.Grammar, extra_rules=()) -> tatsu_grammars.Grammar:
    tatsu_rules = list(extra_rules)
    for (symbol, rule) in grammar.rules.items():
        tatsu_rule = tatsu_grammars.Rule(
            ast=None,
            name=symbol,
            exp=node_to_tatsu(rule),
            params=None,
            kwparams=None,
        )
        tatsu_rules.append(tatsu_rule)

    return tatsu_grammars.Grammar(name=grammar.name, rules=tatsu_rules)
Exemple #4
0
 def grammar(self, ast):
     return model.Grammar(
         self.name,
         [r for r in chain(ast.rules, self.synthetic_rules) if r is not None]
     )
Exemple #5
0
 def grammar(self, ast):
     return model.Grammar(self.name,
                          [r for r in ast.rules if r is not None])