Esempio n. 1
0
class Grammar(modgrammar.Grammar):
    grammar_whitespace_mode = 'optional'
    grammar = (Header, modgrammar.ZERO_OR_MORE(Rule), modgrammar.OPTIONAL(modgrammar.WHITESPACE), modgrammar.EOI)

    def grammar_elem_init(self, session_data):
        self.model = model.Grammar(name=self[0].name, language=self[0].locale, encoding=self[0].encoding)

        for i in range(len(self[1].elements)):
            rule = self[1][i].model
            self.model.add_rule(rule)
Esempio n. 2
0
class Header(modgrammar.Grammar):
    grammar_whitespace_mode = 'optional'
    grammar = (SelfIdentifyingHeader, NameDeclaration, modgrammar.ZERO_OR_MORE(ImportStatement))

    def grammar_elem_init(self, session_data):
        self.version = self[0].version
        self.encoding = self[0].encoding
        self.locale = self[0].locale
        self.name = self[1].name
        self.package = self[1].package
        self.imports = []

        for i in range(len(self[2].elements)):
            self.imports.append(self[2][i])
Esempio n. 3
0
class Tag(modgrammar.Grammar):
    grammar_whitespace_mode = 'explicit'
    grammar = (modgrammar.L('{'), modgrammar.ZERO_OR_MORE(modgrammar.ANY_EXCEPT('^}')), modgrammar.L('}'))

    def grammar_elem_init(self, session_data):
        self.model = model.Tag(name=self[1].string)