Ejemplo n.º 1
0
class OrderedList(modgrammar.Grammar):
    """Defines the grammar for an unordered list."""
    grammar = (EmptyLine,
               modgrammar.LIST_OF(OrderedListItem,
                                  sep=modgrammar.EOL,
                                  collapse=True), modgrammar.EOL)

    def grammar_elem_init(self, sessiondata):
        """Saves the text for later use."""
        self.tag = "ordered_list"
Ejemplo n.º 2
0
class Sequence(modgrammar.Grammar):
    grammar_whitespace_mode = 'explicit'
    grammar = (SequenceRuleExpansion,
               modgrammar.WHITESPACE,
               modgrammar.LIST_OF(SequenceRuleExpansion, sep=modgrammar.WHITESPACE, min=1))

    def grammar_elem_init(self, session_data):
        self.model = model.Sequence()
        self.model.add_element(self[0].model)

        for i in range(0, len(self[2].elements), 2):
            self.model.add_element(self[2][i].model)
Ejemplo n.º 3
0
class SlotIndices(mg.Grammar):
    grammar = mg.LIST_OF(mg.OR(SlotIndex, SlotIndexRange),
                         sep=SEQUENCE_ITEM_SEPARATOR,
                         min=1)

    def value(self):
        return frozenset(self.yield_value())

    def yield_value(self):
        yield from itertools.chain.from_iterable(
            s.yield_value() for s in self[0]
            if s.string != SEQUENCE_ITEM_SEPARATOR)
Ejemplo n.º 4
0
class UnaryOperator(modgrammar.Grammar):
    grammar_whitespace_mode = 'explicit'
    grammar = (modgrammar.OPTIONAL(modgrammar.WHITESPACE),
               modgrammar.L('*') |
               modgrammar.L('+') |
               modgrammar.LIST_OF(Tag, sep=" ", min=1))

    def grammar_elem_init(self, session_data):
        self.is_kleene_star = False
        self.is_plus = False
        self.tags = []

        if self[1].string == '*':
            self.is_kleene_star = True
        elif self[1].string == '+':
            self.is_plus = True
        else:
            for i in range(0, len(self[1].elements), 2):
                self.tags.append(self[1][i].model)
Ejemplo n.º 5
0
class Package(modgrammar.Grammar):
    grammar_whitespace_mode = 'explicit'
    grammar = (modgrammar.LIST_OF(JavaIdentifier, sep=".", min=1))

    def grammar_elem_init(self, session_data):
        self.value = self[0].string
Ejemplo n.º 6
0
class LanguageList(mg.Grammar):
    '''Parse a language list comment.'''
    grammar = (mg.LIST_OF(Words, sep='and'))
Ejemplo n.º 7
0
class PublisherList(mg.Grammar):
    '''Parse a publishers list comment.'''
    grammar = (mg.LIST_OF(Publisher, sep='and'))
Ejemplo n.º 8
0
class NameList(mg.Grammar):
    '''Parse a namelist in a comment.'''
    grammar = (mg.LIST_OF(Name, sep='and'))