Skip to content

Commit 9dc9549

Browse files
committed
Python: fix soft-keywords priority
1 parent aa65f54 commit 9dc9549

4 files changed

Lines changed: 32035 additions & 30481 deletions

File tree

python/extractor/tsg-python/tsp/grammar.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const PREC = {
2+
statment_conflicting_softkeyword: -10,
23
// this resolves a conflict between the usage of ':' in a lambda vs in a
34
// typed parameter. In the case of a lambda, we don't allow typed parameters.
45
lambda: -2,
@@ -165,7 +166,7 @@ module.exports = grammar({
165166
repeat(seq(',', field('argument', $.expression))),
166167
optional(','))
167168
),
168-
prec(-10, seq(
169+
prec(PREC.statment_conflicting_softkeyword, seq(
169170
'print',
170171
commaSep1(field('argument', $.expression)),
171172
optional(',')
@@ -349,7 +350,7 @@ module.exports = grammar({
349350
))
350351
)),
351352

352-
match_statement: $ => seq(
353+
match_statement: $ => prec(PREC.statment_conflicting_softkeyword,seq(
353354
'match',
354355
field('subject',
355356
choice(
@@ -359,7 +360,7 @@ module.exports = grammar({
359360
),
360361
':',
361362
field('cases', $.cases)
362-
),
363+
)),
363364

364365
cases: $ => repeat1($.case_block),
365366

@@ -549,7 +550,7 @@ module.exports = grammar({
549550
commaSep1($.identifier)
550551
),
551552

552-
exec_statement: $ => seq(
553+
exec_statement: $ => prec(PREC.statment_conflicting_softkeyword,seq(
553554
'exec',
554555
field('code', $.string),
555556
optional(
@@ -558,15 +559,15 @@ module.exports = grammar({
558559
commaSep1($.expression)
559560
)
560561
)
561-
),
562+
)),
562563

563-
type_alias_statement: $ => seq(
564+
type_alias_statement: $ => prec(PREC.statment_conflicting_softkeyword,seq(
564565
'type',
565566
field('name', $.identifier),
566567
optional(field('type_parameters', $.type_parameters)),
567568
'=',
568569
field('value', $.expression)
569-
),
570+
)),
570571

571572
class_definition: $ => seq(
572573
'class',
@@ -1191,7 +1192,7 @@ module.exports = grammar({
11911192

11921193
identifier: $ => /[_\p{XID_Start}][_\p{XID_Continue}]*/,
11931194

1194-
keyword_identifier: $ => prec(-3, alias(
1195+
keyword_identifier: $ => prec(11, alias(
11951196
choice(
11961197
'print',
11971198
'exec',
@@ -1207,7 +1208,7 @@ module.exports = grammar({
12071208
false: $ => 'False',
12081209
none: $ => 'None',
12091210

1210-
await: $ => prec(PREC.unary, seq(
1211+
await: $ => prec(PREC.statment_conflicting_softkeyword, seq(
12111212
'await',
12121213
$.primary_expression
12131214
)),

python/extractor/tsg-python/tsp/src/grammar.json

Lines changed: 148 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,47 +1407,51 @@
14071407
}
14081408
},
14091409
"match_statement": {
1410-
"type": "SEQ",
1411-
"members": [
1412-
{
1413-
"type": "STRING",
1414-
"value": "match"
1415-
},
1416-
{
1417-
"type": "FIELD",
1418-
"name": "subject",
1419-
"content": {
1420-
"type": "CHOICE",
1421-
"members": [
1422-
{
1423-
"type": "SYMBOL",
1424-
"name": "expression"
1425-
},
1426-
{
1427-
"type": "ALIAS",
1428-
"content": {
1410+
"type": "PREC",
1411+
"value": -10,
1412+
"content": {
1413+
"type": "SEQ",
1414+
"members": [
1415+
{
1416+
"type": "STRING",
1417+
"value": "match"
1418+
},
1419+
{
1420+
"type": "FIELD",
1421+
"name": "subject",
1422+
"content": {
1423+
"type": "CHOICE",
1424+
"members": [
1425+
{
14291426
"type": "SYMBOL",
1430-
"name": "expression_list"
1427+
"name": "expression"
14311428
},
1432-
"named": true,
1433-
"value": "tuple"
1434-
}
1435-
]
1436-
}
1437-
},
1438-
{
1439-
"type": "STRING",
1440-
"value": ":"
1441-
},
1442-
{
1443-
"type": "FIELD",
1444-
"name": "cases",
1445-
"content": {
1446-
"type": "SYMBOL",
1447-
"name": "cases"
1429+
{
1430+
"type": "ALIAS",
1431+
"content": {
1432+
"type": "SYMBOL",
1433+
"name": "expression_list"
1434+
},
1435+
"named": true,
1436+
"value": "tuple"
1437+
}
1438+
]
1439+
}
1440+
},
1441+
{
1442+
"type": "STRING",
1443+
"value": ":"
1444+
},
1445+
{
1446+
"type": "FIELD",
1447+
"name": "cases",
1448+
"content": {
1449+
"type": "SYMBOL",
1450+
"name": "cases"
1451+
}
14481452
}
1449-
}
1450-
]
1453+
]
1454+
}
14511455
},
14521456
"cases": {
14531457
"type": "REPEAT1",
@@ -2725,108 +2729,116 @@
27252729
]
27262730
},
27272731
"exec_statement": {
2728-
"type": "SEQ",
2729-
"members": [
2730-
{
2731-
"type": "STRING",
2732-
"value": "exec"
2733-
},
2734-
{
2735-
"type": "FIELD",
2736-
"name": "code",
2737-
"content": {
2738-
"type": "SYMBOL",
2739-
"name": "string"
2740-
}
2741-
},
2742-
{
2743-
"type": "CHOICE",
2744-
"members": [
2745-
{
2746-
"type": "SEQ",
2747-
"members": [
2748-
{
2749-
"type": "STRING",
2750-
"value": "in"
2751-
},
2752-
{
2753-
"type": "SEQ",
2754-
"members": [
2755-
{
2756-
"type": "SYMBOL",
2757-
"name": "expression"
2758-
},
2759-
{
2760-
"type": "REPEAT",
2761-
"content": {
2762-
"type": "SEQ",
2763-
"members": [
2764-
{
2765-
"type": "STRING",
2766-
"value": ","
2767-
},
2768-
{
2769-
"type": "SYMBOL",
2770-
"name": "expression"
2771-
}
2772-
]
2773-
}
2774-
}
2775-
]
2776-
}
2777-
]
2778-
},
2779-
{
2780-
"type": "BLANK"
2732+
"type": "PREC",
2733+
"value": -10,
2734+
"content": {
2735+
"type": "SEQ",
2736+
"members": [
2737+
{
2738+
"type": "STRING",
2739+
"value": "exec"
2740+
},
2741+
{
2742+
"type": "FIELD",
2743+
"name": "code",
2744+
"content": {
2745+
"type": "SYMBOL",
2746+
"name": "string"
27812747
}
2782-
]
2783-
}
2784-
]
2748+
},
2749+
{
2750+
"type": "CHOICE",
2751+
"members": [
2752+
{
2753+
"type": "SEQ",
2754+
"members": [
2755+
{
2756+
"type": "STRING",
2757+
"value": "in"
2758+
},
2759+
{
2760+
"type": "SEQ",
2761+
"members": [
2762+
{
2763+
"type": "SYMBOL",
2764+
"name": "expression"
2765+
},
2766+
{
2767+
"type": "REPEAT",
2768+
"content": {
2769+
"type": "SEQ",
2770+
"members": [
2771+
{
2772+
"type": "STRING",
2773+
"value": ","
2774+
},
2775+
{
2776+
"type": "SYMBOL",
2777+
"name": "expression"
2778+
}
2779+
]
2780+
}
2781+
}
2782+
]
2783+
}
2784+
]
2785+
},
2786+
{
2787+
"type": "BLANK"
2788+
}
2789+
]
2790+
}
2791+
]
2792+
}
27852793
},
27862794
"type_alias_statement": {
2787-
"type": "SEQ",
2788-
"members": [
2789-
{
2790-
"type": "STRING",
2791-
"value": "type"
2792-
},
2793-
{
2794-
"type": "FIELD",
2795-
"name": "name",
2796-
"content": {
2797-
"type": "SYMBOL",
2798-
"name": "identifier"
2799-
}
2800-
},
2801-
{
2802-
"type": "CHOICE",
2803-
"members": [
2804-
{
2805-
"type": "FIELD",
2806-
"name": "type_parameters",
2807-
"content": {
2808-
"type": "SYMBOL",
2809-
"name": "type_parameters"
2795+
"type": "PREC",
2796+
"value": -10,
2797+
"content": {
2798+
"type": "SEQ",
2799+
"members": [
2800+
{
2801+
"type": "STRING",
2802+
"value": "type"
2803+
},
2804+
{
2805+
"type": "FIELD",
2806+
"name": "name",
2807+
"content": {
2808+
"type": "SYMBOL",
2809+
"name": "identifier"
2810+
}
2811+
},
2812+
{
2813+
"type": "CHOICE",
2814+
"members": [
2815+
{
2816+
"type": "FIELD",
2817+
"name": "type_parameters",
2818+
"content": {
2819+
"type": "SYMBOL",
2820+
"name": "type_parameters"
2821+
}
2822+
},
2823+
{
2824+
"type": "BLANK"
28102825
}
2811-
},
2812-
{
2813-
"type": "BLANK"
2826+
]
2827+
},
2828+
{
2829+
"type": "STRING",
2830+
"value": "="
2831+
},
2832+
{
2833+
"type": "FIELD",
2834+
"name": "value",
2835+
"content": {
2836+
"type": "SYMBOL",
2837+
"name": "expression"
28142838
}
2815-
]
2816-
},
2817-
{
2818-
"type": "STRING",
2819-
"value": "="
2820-
},
2821-
{
2822-
"type": "FIELD",
2823-
"name": "value",
2824-
"content": {
2825-
"type": "SYMBOL",
2826-
"name": "expression"
28272839
}
2828-
}
2829-
]
2840+
]
2841+
}
28302842
},
28312843
"class_definition": {
28322844
"type": "SEQ",
@@ -6551,7 +6563,7 @@
65516563
},
65526564
"keyword_identifier": {
65536565
"type": "PREC",
6554-
"value": -3,
6566+
"value": 11,
65556567
"content": {
65566568
"type": "ALIAS",
65576569
"content": {
@@ -6601,7 +6613,7 @@
66016613
},
66026614
"await": {
66036615
"type": "PREC",
6604-
"value": 19,
6616+
"value": -10,
66056617
"content": {
66066618
"type": "SEQ",
66076619
"members": [

0 commit comments

Comments
 (0)