コード例 #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)
コード例 #2
0
    def test_character_series(self):
        """ Test CharacterSeries parser class. """

        self._test_multiple(parser.CharacterSeries(string.letters), [
            ("abc", ["abc"]),
        ],
                            must_finish=False)
コード例 #3
0
    def test_character_series(self):
        """ Test CharacterSeries parser classes. """

        # Test with ascii characters
        self._test_multiple(
            parser.CharacterSeries(string.ascii_letters),
            [
                ("abc", ["abc"]),
            ],
            must_finish=False)

        # Test the Letters and Alphanumerics classes with a few inputs and
        # outputs
        input_outputs = [
            # Unicode strings
            (u"abc", [u"abc"]),
            # Mix of non-ascii characters
            (u"éèàâêùôöëäïüû", [u"éèàâêùôöëäïüû"]),
            (u"touché", [u"touché"]),
        ]
        self._test_multiple(
            parser.Letters(),
            input_outputs + [(string.digits, [])],
            must_finish=False
        )
        self._test_multiple(
            parser.Alphanumerics(),
            input_outputs + [(string.digits, [string.digits])],
            must_finish=False
        )
コード例 #4
0
 def __init__(self):
     # Use a pattern to allow ascii and Unicode alphanumeric characters plus
     # underscores.
     pattern = re.compile(r"\w", re.UNICODE)
     name = parser_.CharacterSeries(None, pattern=pattern)
     elements = (parser_.String("{"), name, parser_.String("}"))
     parser_.Sequence.__init__(self, elements)
     self._identifiers = None
コード例 #5
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)
コード例 #6
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)
コード例 #7
0
    def test_character_series(self):
        """ Test CharacterSeries parser class. """

        # Test with ascii characters
        self._test_multiple(
            parser.CharacterSeries(string.letters),
            [
                ("abc", ["abc"]),
            ],
            must_finish=False)

        # Test with Unicode characters
        self._test_multiple(
            parser.Letters(),
            [
                (u"abc", [u"abc"]),
            ],
            must_finish=False
        )
コード例 #8
0
 def __init__(self):
     characters = string.letters + string.digits + "_"
     name = parser_.CharacterSeries(characters)
     elements = (parser_.String("{"), name, parser_.String("}"))
     parser_.Sequence.__init__(self, elements)
     self._identifiers = None