Beispiel #1
0
 def test_repetition(self):
     """ Test repetition parser class. """
     word = parser.CharacterSeries(string.letters)
     whitespace = parser.CharacterSeries(string.whitespace)
     p = parser.Repetition(parser.Alternative((word, whitespace)))
     input_output = (
         ("abc", ["abc"]),
         ("abc abc", ["abc", " ", "abc"]),
         ("abc abc\t\t\n   cba", ["abc", " ", "abc", "\t\t\n   ", "cba"]),
     )
     self._test_single(p, input_output)
Beispiel #2
0
 def initialize(self):
     self._element_identifier = _ElementRef()
     self._action_identifier = _ActionRef()
     alternatives = parser_.Alternative((
         _Literal(),
         _Optional(),
         _Group(),
         self._element_identifier,
     ))
     elements = [
         parser_.Whitespace(optional=True),
         alternatives,
         parser_.Optional(
             parser_.Sequence((
                 parser_.Whitespace(optional=True),
                 self._action_identifier,
             ))),
         parser_.Whitespace(optional=True),
     ]
     parser_.Sequence.__init__(self, elements)
Beispiel #3
0
    def test_repetition(self):
        """ Test repetition parser class. """
        word = parser.Letters()
        whitespace = parser.Whitespace()
        p = parser.Repetition(parser.Alternative((word, whitespace)))

        # Test with ascii letters
        input_output = (
            ("abc", ["abc"]),
            ("abc abc", ["abc", " ", "abc"]),
            ("abc abc\t\t\n   cba", ["abc", " ", "abc", "\t\t\n   ", "cba"]),
        )
        self._test_single(p, input_output)

        # Test with non-ascii letters
        input_output = (
            (u"êùö", [u"êùö"]),
            (u"êùö êùö", [u"êùö", u" ", u"êùö"]),
            (u"êùö êùö\t\t\n   öùê",
             [u"êùö", " ", u"êùö", u"\t\t\n   ", u"öùê"]),
        )
        self._test_single(p, input_output)