diff options
author | ptmcg <ptmcg@austin.rr.com> | 2021-08-19 16:53:27 -0500 |
---|---|---|
committer | ptmcg <ptmcg@austin.rr.com> | 2021-08-19 16:53:27 -0500 |
commit | a3846e7a973308dae9c39c584525b82cf8d73549 (patch) | |
tree | b2ac1d6eb7e2dfeefd687e52fd5f005872fc8c73 /tests | |
parent | da022671996878a9665fc9362d5f3ab2f3aa9f11 (diff) | |
download | pyparsing-git-a3846e7a973308dae9c39c584525b82cf8d73549.tar.gz |
Add identchars and identbodychars symbols to make it easier to construct identifiers
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_unit.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/test_unit.py b/tests/test_unit.py index 07b1ae4..1d3227f 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -7484,6 +7484,53 @@ class Test02_WithoutPackrat(ppt.TestParseResultsAsserts, TestCase): ) print() + def testWordWithIdentChars(self): + ppu = pp.pyparsing_unicode + + latin_identifier = pp.Word(pp.identchars, pp.identbodychars)("latin*") + japanese_identifier = pp.Word( + ppu.Japanese.identchars, ppu.Japanese.identbodychars + )("japanese*") + cjk_identifier = pp.Word(ppu.CJK.identchars, ppu.CJK.identbodychars)("cjk") + greek_identifier = pp.Word(ppu.Greek.identchars, ppu.Greek.identbodychars)( + "greek" + ) + cyrillic_identifier = pp.Word( + ppu.Cyrillic.identchars, ppu.Cyrillic.identbodychars + )("cyrillic*") + thai_identifier = pp.Word(ppu.Thai.identchars, ppu.Thai.identbodychars)("thai") + idents = ( + latin_identifier + | japanese_identifier + | cjk_identifier # must follow japanese_identifier, since CJK is superset + | thai_identifier + | greek_identifier + | cyrillic_identifier + ) + + result = idents[...].parseString( + "abc_100 кириллицаx_10 日本語f_300 ไทยg_600 def_200 漢字y_300 한국어_中文c_400 Ελληνικάb_500" + ) + self.assertParseResultsEquals( + result, + [ + "abc_100", + "кириллицаx_10", + "日本語f_300", + "ไทยg_600", + "def_200", + "漢字y_300", + "한국어_中文c_400", + "Ελληνικάb_500", + ], + {'cjk': '한국어_中文c_400', + 'cyrillic': ['кириллицаx_10'], + 'greek': 'Ελληνικάb_500', + 'japanese': ['日本語f_300', '漢字y_300'], + 'latin': ['abc_100', 'def_200'], + 'thai': 'ไทยg_600'}, + ) + def testChainedTernaryOperator(self): TERNARY_INFIX = pp.infixNotation( ppc.integer, [(("?", ":"), 3, pp.opAssoc.LEFT)] |