Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
57f78dd
Run CI in pegen branch as well (#3)
pablogsal Feb 26, 2020
5c0c31f
Merge steps 1-3 and 6 into 'pegen' branch (#8)
gvanrossum Mar 20, 2020
eab06f3
Fall back to a set for done in collect_todo (#9)
lysnikolaou Mar 20, 2020
91427a4
Add Github Actions for pegen tests in Tools/peg_generator (#12)
lysnikolaou Mar 23, 2020
cccfd3d
Allow expressions in yield_expression rule and rename it to annotated…
lysnikolaou Mar 23, 2020
51611b4
Copy .clang-format from pegen project, to guide 'make format-c'
gvanrossum Mar 23, 2020
0c7a382
Expose a C API and a Python-level module for pegen (#11)
lysnikolaou Mar 23, 2020
0cffa81
Run clang-format over peg_parser/pegen.c
gvanrossum Mar 23, 2020
e960c15
Run clang-format over Parser/pegen/pegen.c
gvanrossum Mar 23, 2020
89c2385
Run clang-format over Modules/peg_parser.c
gvanrossum Mar 23, 2020
1d2b107
Ifdef-out token_name() to silence compiler output noise warning
gvanrossum Mar 23, 2020
12f6175
Merge branch 'master' into pegen
gvanrossum Mar 23, 2020
59abf20
Make Ubuntu tests pass; disable Win and Mac tests (#19)
lysnikolaou Mar 23, 2020
14ae717
Rewrite run_parser* functions to always return a mod_ty (#17)
lysnikolaou Mar 24, 2020
bfa7445
Rewrite exported function (#21)
lysnikolaou Mar 24, 2020
4c4917b
Merge remote-tracking branch 'upstream/master' into pegen
lysnikolaou Mar 24, 2020
479bd95
Remove all unnecessary code from Tools/peg_generator; only keep the g…
lysnikolaou Mar 27, 2020
4410737
Support for PEP 614 (#24)
pablogsal Mar 27, 2020
b984cad
Re-enable MacOS test on Github Actions (#26)
lysnikolaou Mar 27, 2020
919a669
Add memoization control (#28)
gvanrossum Mar 27, 2020
55101cb
Fold long lines in metagrammar
gvanrossum Mar 30, 2020
ca3eeca
Update Parser/pegen/parse.c after addition of memoization flag (#28)
lysnikolaou Apr 1, 2020
33b77af
Add a command-line flag and an environment variable to enable pegen (…
lysnikolaou Apr 3, 2020
3aa1dd4
Add missing possible start rules in python.gram (#32)
lysnikolaou Apr 3, 2020
b8ce9a1
Merge remote-tracking branch 'upstream/master' into pegen
pablogsal Apr 3, 2020
f3d8888
Update grammar to account for _Py_keyword changes (#40)
pablogsal Apr 3, 2020
242114a
Merge remote-tracking branch 'upstream/master' into pegen
pablogsal Apr 3, 2020
35bedc2
Add new C API functions PyPegen_*FromFileObject and use them in inter…
lysnikolaou Apr 4, 2020
74736fe
Memoize some rules to avoid exponential time in deep nesting (#39)
pablogsal Apr 4, 2020
4bc4e7c
Run tests with pegen enabled on CI (#41)
lysnikolaou Apr 5, 2020
6ba7869
Improve SyntaxError message when an ERRORTOKEN is returned by the tok…
lysnikolaou Apr 6, 2020
ee7b2cf
Use FILE pointer instead of filename string to pass file to parser (#52)
lysnikolaou Apr 6, 2020
c12c227
Add start_mark variable in loop rules (#51)
lysnikolaou Apr 6, 2020
18743bc
Simplify grammar rules around ASYNC (#53)
gvanrossum Apr 7, 2020
3359dab
Throw SyntaxError when parsing a STRING throws an exception (#54)
lysnikolaou Apr 7, 2020
071df9c
Add use_peg field to sys.flags (#55)
lysnikolaou Apr 7, 2020
b1f0bd8
Improve error reporting and disallow f(**kwargs, *args) (#46)
pablogsal Apr 7, 2020
0627990
Propagate errors from the tokenizer (#57)
pablogsal Apr 8, 2020
f233194
Output more descriptive error messages for named expressions (#56)
lysnikolaou Apr 8, 2020
1dcdc4b
Output more descriptive error messages for invalid assignments (#59)
lysnikolaou Apr 9, 2020
8da51f1
Avoid memory leak in Parser_New (#62)
lysnikolaou Apr 9, 2020
494114e
Fix SEGFAULT in test_fstring (#61)
lysnikolaou Apr 9, 2020
99a8e2f
Provide location info on SyntaxError due to EOLS or EOFS errors (#60)
lysnikolaou Apr 9, 2020
502dfb7
Merge remote-tracking branch 'upstream/master' into pegen
lysnikolaou Apr 10, 2020
e43370e
Ignore encoding cookie when that's necessary (#68)
lysnikolaou Apr 12, 2020
a7f962d
Silence compiler warnings about unused variables on Linux (#70)
lysnikolaou Apr 12, 2020
9c36a0f
Merge remote-tracking branch 'upstream/master' into pegen
lysnikolaou Apr 12, 2020
9952d03
Refactor illegal syntax rules to avoid invalid error messages (#72)
lysnikolaou Apr 13, 2020
b684233
Create a new rule for STRING+ and memoize it (#67)
lysnikolaou Apr 14, 2020
45d6bf7
Fix type of strings rule (#73)
lysnikolaou Apr 14, 2020
a54e89e
Skip one test_traceback test, where pegen is better (#74)
lysnikolaou Apr 15, 2020
d386c70
Skip non-critical test_string_literals test that fails (#75)
lysnikolaou Apr 15, 2020
1169db2
Add script that reproduces all the PEP benchmarks (#71)
lysnikolaou Apr 15, 2020
e764fb2
Merge remote-tracking branch 'upstream/master' into pegen
lysnikolaou Apr 15, 2020
dad5249
Fix calls to _PyInterpreterState_GET after merge
lysnikolaou Apr 15, 2020
6f6354f
Generate specialized error message for invalid string prefixes (#77)
lysnikolaou Apr 15, 2020
b623006
Compress data/xxl.py and decompress on demand (#79)
pablogsal Apr 17, 2020
1a03e3e
Use the new parser by default (#81)
pablogsal Apr 17, 2020
3af6081
Rename pegen functions to start with the _PyPegen_ prefix (#80)
lysnikolaou Apr 17, 2020
e3c95c9
Compile pegen in windows (#82)
pablogsal Apr 17, 2020
d7e4b5c
Remove whitespace to make patchcheck happy (#87)
pablogsal Apr 17, 2020
ffee25f
Rename the peg_parser module to _peg_parser (#86)
pablogsal Apr 17, 2020
b625797
Fix travis errors (#88)
pablogsal Apr 17, 2020
85f7400
Remove the -p command line option and add a new -X oldparser option i…
lysnikolaou Apr 18, 2020
a4c58b5
Disallow trailing comma in from-imports (#97)
lysnikolaou Apr 20, 2020
04062ed
Add blurb
gvanrossum Apr 20, 2020
f1afe08
Use pegen in the symtable and fix symtable test errors (#102)
pablogsal Apr 20, 2020
b8899ec
Merge branch 'master' into pegen
gvanrossum Apr 20, 2020
975baa4
Only optimize __debug__ when ctx==Load (#106)
gvanrossum Apr 21, 2020
298650c
Reproduce current parser's error messages for indentation errors (#107)
lysnikolaou Apr 21, 2020
de6edfb
Add more tokenize errors (#105)
pablogsal Apr 21, 2020
ef0f6fa
Normalize unicode identifiers (#108)
pablogsal Apr 21, 2020
a9d309c
Raise IndentationError on indentation-related errors (#111)
lysnikolaou Apr 21, 2020
871cecb
Copy most fixes from #96 except for the part that uses pegen for comp…
gvanrossum Apr 21, 2020
ecef99b
Temporarily suppress two failures in test_eof.py (one even with old p…
gvanrossum Apr 21, 2020
443afb1
Use col_offset when raising an E_DEDENT error (#116)
lysnikolaou Apr 21, 2020
87460d2
Use pegen in compile and other functions in pythonrun.c (#96)
lysnikolaou Apr 22, 2020
14ab84b
Don't use longjmp and check for the error indicator on every rule (#119)
pablogsal Apr 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Reproduce current parser's error messages for indentation errors (#107)
  • Loading branch information
lysnikolaou authored Apr 21, 2020
commit 298650cd00bcc28ae79eac25b0b3cf4a220d635c
7 changes: 6 additions & 1 deletion Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ class_def_raw[stmt_ty]:
(b) ? ((expr_ty) b)->v.Call.keywords : NULL,
c, NULL, EXTRA) }

block[asdl_seq*] (memo): NEWLINE INDENT a=statements DEDENT { a } | simple_stmt
block[asdl_seq*] (memo):
| NEWLINE INDENT a=statements DEDENT { a }
| simple_stmt
| invalid_block

expressions_list[asdl_seq*]: a=','.star_expression+ [','] { a }
star_expressions[expr_ty]:
Expand Down Expand Up @@ -532,3 +535,5 @@ invalid_assignment:
_PyPegen_raise_syntax_error(p, "illegal target for annotation") }
| a=expression ('=' | augassign) (yield_expr | star_expressions) {
_PyPegen_raise_syntax_error(p, "cannot assign to %s", _PyPegen_get_expr_name(a)) }
invalid_block:
| NEWLINE !INDENT { _PyPegen_raise_syntax_error(p, "expected an indented block") }
2 changes: 2 additions & 0 deletions Lib/test/test_peg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,8 @@ def f():
("[a, b]: int", "only single target (not list) can be annotated"),
("a(): int", "illegal target for annotation"),
("1 += 1", "cannot assign to literal"),
("pass\n pass", "unexpected indent"),
("def f():\npass", "expected an indented block"),
]

GOOD_BUT_FAIL_TEST_CASES = [
Expand Down
304 changes: 172 additions & 132 deletions Parser/pegen/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,137 +199,138 @@ static KeywordToken *reserved_keywords[] = {
#define incorrect_arguments_type 1137
#define invalid_named_expression_type 1138
#define invalid_assignment_type 1139
#define _loop0_1_type 1140
#define _loop1_2_type 1141
#define _loop0_4_type 1142
#define _gather_3_type 1143
#define _tmp_5_type 1144
#define _tmp_6_type 1145
#define _tmp_7_type 1146
#define _tmp_8_type 1147
#define _tmp_9_type 1148
#define _tmp_10_type 1149
#define _tmp_11_type 1150
#define _tmp_12_type 1151
#define _loop1_13_type 1152
#define _tmp_14_type 1153
#define _tmp_15_type 1154
#define _loop0_17_type 1155
#define _gather_16_type 1156
#define _loop0_19_type 1157
#define _gather_18_type 1158
#define _tmp_20_type 1159
#define _loop0_21_type 1160
#define _loop1_22_type 1161
#define _loop0_24_type 1162
#define _gather_23_type 1163
#define _tmp_25_type 1164
#define _loop0_27_type 1165
#define _gather_26_type 1166
#define _tmp_28_type 1167
#define _loop0_30_type 1168
#define _gather_29_type 1169
#define _loop0_32_type 1170
#define _gather_31_type 1171
#define _tmp_33_type 1172
#define _loop1_34_type 1173
#define _tmp_35_type 1174
#define _tmp_36_type 1175
#define _tmp_37_type 1176
#define _tmp_38_type 1177
#define _tmp_39_type 1178
#define _tmp_40_type 1179
#define _tmp_41_type 1180
#define _tmp_42_type 1181
#define _tmp_43_type 1182
#define _tmp_44_type 1183
#define _tmp_45_type 1184
#define _tmp_46_type 1185
#define _loop0_47_type 1186
#define _tmp_48_type 1187
#define _loop1_49_type 1188
#define _tmp_50_type 1189
#define _tmp_51_type 1190
#define _loop0_53_type 1191
#define _gather_52_type 1192
#define _loop0_55_type 1193
#define _gather_54_type 1194
#define _tmp_56_type 1195
#define _loop1_57_type 1196
#define _tmp_58_type 1197
#define _loop0_60_type 1198
#define _gather_59_type 1199
#define _loop1_61_type 1200
#define _loop0_63_type 1201
#define _gather_62_type 1202
#define _loop1_64_type 1203
#define _tmp_65_type 1204
#define _tmp_66_type 1205
#define _tmp_67_type 1206
#define _tmp_68_type 1207
#define _tmp_69_type 1208
#define _tmp_70_type 1209
#define _tmp_71_type 1210
#define _tmp_72_type 1211
#define _tmp_73_type 1212
#define _loop0_74_type 1213
#define _tmp_75_type 1214
#define _loop1_76_type 1215
#define _tmp_77_type 1216
#define _tmp_78_type 1217
#define _loop0_80_type 1218
#define _gather_79_type 1219
#define _loop0_82_type 1220
#define _gather_81_type 1221
#define _loop1_83_type 1222
#define _loop1_84_type 1223
#define _loop1_85_type 1224
#define _loop0_87_type 1225
#define _gather_86_type 1226
#define _tmp_88_type 1227
#define _tmp_89_type 1228
#define _tmp_90_type 1229
#define _tmp_91_type 1230
#define _loop1_92_type 1231
#define _tmp_93_type 1232
#define _tmp_94_type 1233
#define _loop0_96_type 1234
#define _gather_95_type 1235
#define _loop1_97_type 1236
#define _tmp_98_type 1237
#define _tmp_99_type 1238
#define _loop0_101_type 1239
#define _gather_100_type 1240
#define _loop0_103_type 1241
#define _gather_102_type 1242
#define _loop0_105_type 1243
#define _gather_104_type 1244
#define _loop0_107_type 1245
#define _gather_106_type 1246
#define _loop0_108_type 1247
#define _loop0_110_type 1248
#define _gather_109_type 1249
#define _loop0_112_type 1250
#define _gather_111_type 1251
#define _loop0_114_type 1252
#define _gather_113_type 1253
#define _tmp_115_type 1254
#define _tmp_116_type 1255
#define _tmp_117_type 1256
#define _tmp_118_type 1257
#define _tmp_119_type 1258
#define _tmp_120_type 1259
#define _tmp_121_type 1260
#define _tmp_122_type 1261
#define _tmp_123_type 1262
#define _tmp_124_type 1263
#define _tmp_125_type 1264
#define _tmp_126_type 1265
#define _tmp_127_type 1266
#define _tmp_128_type 1267
#define _tmp_129_type 1268
#define _loop0_130_type 1269
#define _tmp_131_type 1270
#define invalid_block_type 1140
#define _loop0_1_type 1141
#define _loop1_2_type 1142
#define _loop0_4_type 1143
#define _gather_3_type 1144
#define _tmp_5_type 1145
#define _tmp_6_type 1146
#define _tmp_7_type 1147
#define _tmp_8_type 1148
#define _tmp_9_type 1149
#define _tmp_10_type 1150
#define _tmp_11_type 1151
#define _tmp_12_type 1152
#define _loop1_13_type 1153
#define _tmp_14_type 1154
#define _tmp_15_type 1155
#define _loop0_17_type 1156
#define _gather_16_type 1157
#define _loop0_19_type 1158
#define _gather_18_type 1159
#define _tmp_20_type 1160
#define _loop0_21_type 1161
#define _loop1_22_type 1162
#define _loop0_24_type 1163
#define _gather_23_type 1164
#define _tmp_25_type 1165
#define _loop0_27_type 1166
#define _gather_26_type 1167
#define _tmp_28_type 1168
#define _loop0_30_type 1169
#define _gather_29_type 1170
#define _loop0_32_type 1171
#define _gather_31_type 1172
#define _tmp_33_type 1173
#define _loop1_34_type 1174
#define _tmp_35_type 1175
#define _tmp_36_type 1176
#define _tmp_37_type 1177
#define _tmp_38_type 1178
#define _tmp_39_type 1179
#define _tmp_40_type 1180
#define _tmp_41_type 1181
#define _tmp_42_type 1182
#define _tmp_43_type 1183
#define _tmp_44_type 1184
#define _tmp_45_type 1185
#define _tmp_46_type 1186
#define _loop0_47_type 1187
#define _tmp_48_type 1188
#define _loop1_49_type 1189
#define _tmp_50_type 1190
#define _tmp_51_type 1191
#define _loop0_53_type 1192
#define _gather_52_type 1193
#define _loop0_55_type 1194
#define _gather_54_type 1195
#define _tmp_56_type 1196
#define _loop1_57_type 1197
#define _tmp_58_type 1198
#define _loop0_60_type 1199
#define _gather_59_type 1200
#define _loop1_61_type 1201
#define _loop0_63_type 1202
#define _gather_62_type 1203
#define _loop1_64_type 1204
#define _tmp_65_type 1205
#define _tmp_66_type 1206
#define _tmp_67_type 1207
#define _tmp_68_type 1208
#define _tmp_69_type 1209
#define _tmp_70_type 1210
#define _tmp_71_type 1211
#define _tmp_72_type 1212
#define _tmp_73_type 1213
#define _loop0_74_type 1214
#define _tmp_75_type 1215
#define _loop1_76_type 1216
#define _tmp_77_type 1217
#define _tmp_78_type 1218
#define _loop0_80_type 1219
#define _gather_79_type 1220
#define _loop0_82_type 1221
#define _gather_81_type 1222
#define _loop1_83_type 1223
#define _loop1_84_type 1224
#define _loop1_85_type 1225
#define _loop0_87_type 1226
#define _gather_86_type 1227
#define _tmp_88_type 1228
#define _tmp_89_type 1229
#define _tmp_90_type 1230
#define _tmp_91_type 1231
#define _loop1_92_type 1232
#define _tmp_93_type 1233
#define _tmp_94_type 1234
#define _loop0_96_type 1235
#define _gather_95_type 1236
#define _loop1_97_type 1237
#define _tmp_98_type 1238
#define _tmp_99_type 1239
#define _loop0_101_type 1240
#define _gather_100_type 1241
#define _loop0_103_type 1242
#define _gather_102_type 1243
#define _loop0_105_type 1244
#define _gather_104_type 1245
#define _loop0_107_type 1246
#define _gather_106_type 1247
#define _loop0_108_type 1248
#define _loop0_110_type 1249
#define _gather_109_type 1250
#define _loop0_112_type 1251
#define _gather_111_type 1252
#define _loop0_114_type 1253
#define _gather_113_type 1254
#define _tmp_115_type 1255
#define _tmp_116_type 1256
#define _tmp_117_type 1257
#define _tmp_118_type 1258
#define _tmp_119_type 1259
#define _tmp_120_type 1260
#define _tmp_121_type 1261
#define _tmp_122_type 1262
#define _tmp_123_type 1263
#define _tmp_124_type 1264
#define _tmp_125_type 1265
#define _tmp_126_type 1266
#define _tmp_127_type 1267
#define _tmp_128_type 1268
#define _tmp_129_type 1269
#define _loop0_130_type 1270
#define _tmp_131_type 1271

static mod_ty file_rule(Parser *p);
static mod_ty interactive_rule(Parser *p);
Expand Down Expand Up @@ -471,6 +472,7 @@ static expr_ty t_atom_rule(Parser *p);
static void *incorrect_arguments_rule(Parser *p);
static void *invalid_named_expression_rule(Parser *p);
static void *invalid_assignment_rule(Parser *p);
static void *invalid_block_rule(Parser *p);
static asdl_seq *_loop0_1_rule(Parser *p);
static asdl_seq *_loop1_2_rule(Parser *p);
static asdl_seq *_loop0_4_rule(Parser *p);
Expand Down Expand Up @@ -3651,7 +3653,7 @@ class_def_raw_rule(Parser *p)
return res;
}

// block: NEWLINE INDENT statements DEDENT | simple_stmt
// block: NEWLINE INDENT statements DEDENT | simple_stmt | invalid_block
static asdl_seq*
block_rule(Parser *p)
{
Expand Down Expand Up @@ -3693,6 +3695,17 @@ block_rule(Parser *p)
}
p->mark = mark;
}
{ // invalid_block
void *invalid_block_var;
if (
(invalid_block_var = invalid_block_rule(p))
)
{
res = invalid_block_var;
goto done;
}
p->mark = mark;
}
res = NULL;
done:
_PyPegen_insert_memo(p, mark, block_type, res);
Expand Down Expand Up @@ -9043,6 +9056,33 @@ invalid_assignment_rule(Parser *p)
return res;
}

// invalid_block: NEWLINE !INDENT
static void *
invalid_block_rule(Parser *p)
{
void * res = NULL;
int mark = p->mark;
{ // NEWLINE !INDENT
void *newline_var;
if (
(newline_var = _PyPegen_newline_token(p))
&&
_PyPegen_lookahead(0, _PyPegen_indent_token, p)
)
{
res = _PyPegen_raise_syntax_error ( p , "expected an indented block" );
if (res == NULL && PyErr_Occurred()) {
longjmp(p->error_env, 1);
}
goto done;
}
p->mark = mark;
}
res = NULL;
done:
return res;
}

// _loop0_1: NEWLINE
static asdl_seq *
_loop0_1_rule(Parser *p)
Expand Down
10 changes: 9 additions & 1 deletion Parser/pegen/pegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,15 @@ _PyPegen_run_parser(Parser *p)
_PyPegen_raise_syntax_error(p, "error at start before reading any input");
}
else {
_PyPegen_raise_syntax_error(p, "invalid syntax");
if (p->tokens[p->fill-1]->type == INDENT) {
_PyPegen_raise_syntax_error(p, "unexpected indent");
}
else if (p->tokens[p->fill-1]->type == DEDENT) {
_PyPegen_raise_syntax_error(p, "unexpected unindent");
}
else {
_PyPegen_raise_syntax_error(p, "invalid syntax");
}
}
return NULL;
}
Expand Down