Skip to content

Commit bcd7dee

Browse files
authored
bpo-40939: Remove PEG parser easter egg (__new_parser__) (#20802)
It no longer serves a purpose (there's only one parser) and having "new" in any name will eventually look odd. Also, it impinges on a potential sub-namespace, `__new_...__`.
1 parent 10e6506 commit bcd7dee

File tree

4 files changed

+10
-47
lines changed

4 files changed

+10
-47
lines changed

Grammar/python.gram

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,6 @@ atom[expr_ty]:
477477
| 'True' { _Py_Constant(Py_True, NULL, EXTRA) }
478478
| 'False' { _Py_Constant(Py_False, NULL, EXTRA) }
479479
| 'None' { _Py_Constant(Py_None, NULL, EXTRA) }
480-
| '__new_parser__' { RAISE_SYNTAX_ERROR("You found it!") }
481480
| &STRING strings
482481
| NUMBER
483482
| &'(' (tuple | group | genexp)

Lib/keyword.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
'False',
2020
'None',
2121
'True',
22-
'__new_parser__',
2322
'and',
2423
'as',
2524
'assert',

Lib/pydoc.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1817,7 +1817,6 @@ class Helper:
18171817
'False': '',
18181818
'None': '',
18191819
'True': '',
1820-
'__new_parser__': '',
18211820
'and': 'BOOLEAN',
18221821
'as': 'with',
18231822
'assert': ('assert', ''),

Parser/pegen/parse.c

Lines changed: 10 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ extern int Py_DebugFlag;
77
#else
88
#define D(x)
99
#endif
10-
static const int n_keyword_lists = 15;
10+
static const int n_keyword_lists = 9;
1111
static KeywordToken *reserved_keywords[] = {
1212
NULL,
1313
NULL,
1414
(KeywordToken[]) {
1515
{"if", 510},
1616
{"in", 518},
1717
{"is", 526},
18-
{"as", 531},
19-
{"or", 532},
18+
{"as", 530},
19+
{"or", 531},
2020
{NULL, -1},
2121
},
2222
(KeywordToken[]) {
@@ -25,7 +25,7 @@ static KeywordToken *reserved_keywords[] = {
2525
{"for", 517},
2626
{"def", 522},
2727
{"not", 525},
28-
{"and", 533},
28+
{"and", 532},
2929
{NULL, -1},
3030
},
3131
(KeywordToken[]) {
@@ -65,15 +65,6 @@ static KeywordToken *reserved_keywords[] = {
6565
{"nonlocal", 509},
6666
{NULL, -1},
6767
},
68-
NULL,
69-
NULL,
70-
NULL,
71-
NULL,
72-
NULL,
73-
(KeywordToken[]) {
74-
{"__new_parser__", 530},
75-
{NULL, -1},
76-
},
7768
};
7869
#define file_type 1000
7970
#define interactive_type 1001
@@ -10567,7 +10558,6 @@ slice_rule(Parser *p)
1056710558
// | 'True'
1056810559
// | 'False'
1056910560
// | 'None'
10570-
// | '__new_parser__'
1057110561
// | &STRING strings
1057210562
// | NUMBER
1057310563
// | &'(' (tuple | group | genexp)
@@ -10711,30 +10701,6 @@ atom_rule(Parser *p)
1071110701
D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ',
1071210702
p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'None'"));
1071310703
}
10714-
{ // '__new_parser__'
10715-
if (p->error_indicator) {
10716-
D(p->level--);
10717-
return NULL;
10718-
}
10719-
D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'__new_parser__'"));
10720-
Token * _keyword;
10721-
if (
10722-
(_keyword = _PyPegen_expect_token(p, 530)) // token='__new_parser__'
10723-
)
10724-
{
10725-
D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'__new_parser__'"));
10726-
_res = RAISE_SYNTAX_ERROR ( "You found it!" );
10727-
if (_res == NULL && PyErr_Occurred()) {
10728-
p->error_indicator = 1;
10729-
D(p->level--);
10730-
return NULL;
10731-
}
10732-
goto done;
10733-
}
10734-
p->mark = _mark;
10735-
D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ',
10736-
p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'__new_parser__'"));
10737-
}
1073810704
{ // &STRING strings
1073910705
if (p->error_indicator) {
1074010706
D(p->level--);
@@ -17313,7 +17279,7 @@ _tmp_34_rule(Parser *p)
1731317279
Token * _keyword;
1731417280
expr_ty z;
1731517281
if (
17316-
(_keyword = _PyPegen_expect_token(p, 531)) // token='as'
17282+
(_keyword = _PyPegen_expect_token(p, 530)) // token='as'
1731717283
&&
1731817284
(z = _PyPegen_name_token(p)) // NAME
1731917285
)
@@ -17471,7 +17437,7 @@ _tmp_37_rule(Parser *p)
1747117437
Token * _keyword;
1747217438
expr_ty z;
1747317439
if (
17474-
(_keyword = _PyPegen_expect_token(p, 531)) // token='as'
17440+
(_keyword = _PyPegen_expect_token(p, 530)) // token='as'
1747517441
&&
1747617442
(z = _PyPegen_name_token(p)) // NAME
1747717443
)
@@ -17971,7 +17937,7 @@ _tmp_46_rule(Parser *p)
1797117937
Token * _keyword;
1797217938
expr_ty t;
1797317939
if (
17974-
(_keyword = _PyPegen_expect_token(p, 531)) // token='as'
17940+
(_keyword = _PyPegen_expect_token(p, 530)) // token='as'
1797517941
&&
1797617942
(t = target_rule(p)) // target
1797717943
)
@@ -18086,7 +18052,7 @@ _tmp_48_rule(Parser *p)
1808618052
Token * _keyword;
1808718053
expr_ty z;
1808818054
if (
18089-
(_keyword = _PyPegen_expect_token(p, 531)) // token='as'
18055+
(_keyword = _PyPegen_expect_token(p, 530)) // token='as'
1809018056
&&
1809118057
(z = _PyPegen_name_token(p)) // NAME
1809218058
)
@@ -23892,7 +23858,7 @@ _tmp_144_rule(Parser *p)
2389223858
Token * _keyword;
2389323859
expr_ty c;
2389423860
if (
23895-
(_keyword = _PyPegen_expect_token(p, 532)) // token='or'
23861+
(_keyword = _PyPegen_expect_token(p, 531)) // token='or'
2389623862
&&
2389723863
(c = conjunction_rule(p)) // conjunction
2389823864
)
@@ -23936,7 +23902,7 @@ _tmp_145_rule(Parser *p)
2393623902
Token * _keyword;
2393723903
expr_ty c;
2393823904
if (
23939-
(_keyword = _PyPegen_expect_token(p, 533)) // token='and'
23905+
(_keyword = _PyPegen_expect_token(p, 532)) // token='and'
2394023906
&&
2394123907
(c = inversion_rule(p)) // inversion
2394223908
)

0 commit comments

Comments
 (0)