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"
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)
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)
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)
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
class LanguageList(mg.Grammar): '''Parse a language list comment.''' grammar = (mg.LIST_OF(Words, sep='and'))
class PublisherList(mg.Grammar): '''Parse a publishers list comment.''' grammar = (mg.LIST_OF(Publisher, sep='and'))
class NameList(mg.Grammar): '''Parse a namelist in a comment.''' grammar = (mg.LIST_OF(Name, sep='and'))