Пример #1
0
 def test_or(self):
     self._compare('a|b', N.Or(N.Char('a'), N.Char('b')))
     self._compare('ab|c',
                   N.Or(N.Concat(N.Char('a'), N.Char('b')), N.Char('c')))
     self._compare('a|bc',
                   N.Or(N.Char('a'), N.Concat(N.Char('b'), N.Char('c'))))
     self._compare('a|b|c', N.Or(N.Or(N.Char('a'), N.Char('b')),
                                 N.Char('c')))
     self._compare('|', N.Or(N.Empty(), N.Empty()))
Пример #2
0
 def parse_concat(self):
     lineno = self.stream.current.lineno
     args = [self.parse_mul()]
     while self.stream.current.type == 'tilde':
         next(self.stream)
         args.append(self.parse_mul())
     if len(args) == 1:
         return args[0]
     return nodes.Concat(args, lineno=lineno)
Пример #3
0
 def test_concat(self):
     self._compare(
         'abc', N.Concat(N.Concat(N.Char('a'), N.Char('b')), N.Char('c')))
     self._compare(
         'abcde',
         N.Concat(
             N.Concat(
                 N.Concat(N.Concat(N.Char('a'), N.Char('b')), N.Char('c')),
                 N.Char('d')), N.Char('e')))
Пример #4
0
 def test_parentheses(self):
     self._compare('()', N.Empty())
     self._compare('(ab)+', N.OneOrMore(N.Concat(N.Char('a'), N.Char('b'))))
     self._compare('a(b)+', N.Concat(N.Char('a'), N.OneOrMore(N.Char('b'))))
     parse.from_string('a(bcd*|efgh?(jk)+)*')
Пример #5
0
 def test_unary(self):
     self._compare('a?', N.ZeroOrOne(N.Char('a')))
     self._compare('ab+', N.Concat(N.Char('a'), N.OneOrMore(N.Char('b'))))
     self._compare('a+b', N.Concat(N.OneOrMore(N.Char('a')), N.Char('b')))