コード例 #1
0
 def initialize(self):
     self._single = _Single()
     self._single.initialize()
     repetition = parser_.Repetition(self._single)
     elements = (
         repetition,
         parser_.Repetition(parser_.Sequence((
             parser_.String("|"),
             repetition,
         )),
                            min=0),
     )
     parser_.Sequence.__init__(self, elements)
コード例 #2
0
 def __init__(self):
     characters = string.letters + string.digits + "_-.'"
     word = parser_.CharacterSeries(characters)
     whitespace = parser_.Whitespace()
     elements = (
         word,
         parser_.Repetition(parser_.Sequence((whitespace, word)), min=0),
     )
     parser_.Sequence.__init__(self, elements)
コード例 #3
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)
コード例 #4
0
 def __init__(self):
     # Use a pattern to allow ascii and Unicode alphanumeric characters plus a
     # few special characters.
     pattern = re.compile(r"[\w_\-.',]", re.UNICODE)
     word = parser_.CharacterSeries(None, pattern=pattern)
     whitespace = parser_.Whitespace()
     elements = (
         word,
         parser_.Repetition(parser_.Sequence((whitespace, word)), min=0),
     )
     parser_.Sequence.__init__(self, elements)
コード例 #5
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)