diff options
author | Guido van Rossum <guido@python.org> | 2020-05-26 17:58:44 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-26 17:58:44 (GMT) |
commit | b45af1a5691e83b86321fc52d173f66cf891ce5f (patch) | |
tree | ff39a728c49995811eeca554bc7b2ce89be2644e /Lib | |
parent | 578c3955e0222ec7b3146197467fbb0fcfae12fe (diff) | |
download | cpython-b45af1a5691e83b86321fc52d173f66cf891ce5f.zip cpython-b45af1a5691e83b86321fc52d173f66cf891ce5f.tar.gz cpython-b45af1a5691e83b86321fc52d173f66cf891ce5f.tar.bz2 |
Add soft keywords (GH-20370)
These are like keywords but they only work in context; they are not reserved except when there is an exact match.
This would enable things like match statements without reserving `match` (which would be bad for the `re.match()` function and probably lots of other places).
Automerge-Triggered-By: @gvanrossum
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_peg_generator/test_c_parser.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Lib/test/test_peg_generator/test_c_parser.py b/Lib/test/test_peg_generator/test_c_parser.py index f66b92d..72383d5 100644 --- a/Lib/test/test_peg_generator/test_c_parser.py +++ b/Lib/test/test_peg_generator/test_c_parser.py @@ -402,3 +402,33 @@ class TestCParser(TempdirManager, unittest.TestCase): parse.parse_string("a", mode=0) """ self.run_test(grammar_source, test_source) + + def test_no_soft_keywords(self) -> None: + grammar_source = """ + start: expr+ NEWLINE? ENDMARKER + expr: 'foo' + """ + grammar = parse_string(grammar_source, GrammarParser) + parser_source = generate_c_parser_source(grammar) + assert "expect_soft_keyword" not in parser_source + + def test_soft_keywords(self) -> None: + grammar_source = """ + start: expr+ NEWLINE? ENDMARKER + expr: "foo" + """ + grammar = parse_string(grammar_source, GrammarParser) + parser_source = generate_c_parser_source(grammar) + assert "expect_soft_keyword" in parser_source + + def test_soft_keywords_parse(self) -> None: + grammar_source = """ + start: "if" expr '+' expr NEWLINE + expr: NAME + """ + test_source = """ + valid_cases = ["if if + if"] + invalid_cases = ["if if"] + self.check_input_strings_for_grammar(valid_cases, invalid_cases) + """ + self.run_test(grammar_source, test_source) |