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)
def test_character_series(self): """ Test CharacterSeries parser class. """ self._test_multiple(parser.CharacterSeries(string.letters), [ ("abc", ["abc"]), ], must_finish=False)
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 )
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
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)
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)
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 )
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