Closed Thirumalai-Shaktivel closed 2 years ago
Here, match
and case
are soft keywords: https://docs.python.org/3/reference/compound_stmts.html#the-match-statement
The match and case keywords are proposed to be soft keywords, so that they are recognized as keywords at the beginning of a match statement or case block respectively, but are allowed to be used in other places as variable or argument names.
https://peps.python.org/pep-0622/#the-match-statement @certik how do we handle this?
So match
is a keyword that is not reserved. See https://docs.python.org/3/reference/lexical_analysis.html#soft-keywords, they call it a soft keyword. In our tokenizer.re, we have the following sets of reserved keywords:
"as"
"assert"
"async"
"await"
"break"
"class"
"continue"
"def"
"del"
"elif"
"else"
"except"
"finally"
"for"
"from"
"global"
"if"
"import"
"in"
"is"
"lambda"
"None"
"nonlocal"
"pass"
"raise"
"return"
"try"
"while"
"with"
"yield"
"yield from"
These cannot be used as variable names such as in with = 5
.
match
, case
are different (perhaps also _
as the docs say, not sure about how we handle that --- looks like _
can also be a variable name). We have to allow them as variable names.
We have several options how to tackle the match
and case
non-reserved keywords (each has pros/cons):
match
and case
are keywords, or just a name (such as a variable).match
as a keyword, and in Bison we add an id
rule that is a "TK_NAME | KW_MATCH | KW_CASE", this creates conflicts, but Bison GLR can take care of itWe should probably fix this one first, now when the new parser is merged.
Remaining issues:
match():
# Comment
case():
x = 0
match (): # Comment
case ():
pass
case ['remove',
*files]:
print('Removing files: {}'.format(files))
match = {2:
3}
match[2:
8]
Example:
Error: