Skip to content
This repository was archived by the owner on Oct 20, 2022. It is now read-only.

Commit fab6802

Browse files
add node for pattern cons lists (#11)
* add grammar change and test case for pat_cons_list * generate grammar * run 'make publish'
1 parent 9d5fd0c commit fab6802

File tree

7 files changed

+23847
-22812
lines changed

7 files changed

+23847
-22812
lines changed

docs/tree-sitter-erlang.wasm

68.7 KB
Binary file not shown.

grammar.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,20 @@ module.exports = grammar({
295295
pattern: ($) =>
296296
prec(PREC.PATTERN, choice($.term, $.variable, $.pat_list, $.pat_tuple)),
297297

298-
pat_list: ($) => prec(PREC.PATTERN, list($.pattern)),
298+
pat_list: ($) =>
299+
prec(PREC.PATTERN, choice(list($.pattern), $.pat_list_cons)),
300+
301+
pat_list_cons: ($) =>
302+
delim(
303+
BRACKET_LEFT,
304+
seq(
305+
field("init", sepBy(COMMA, $.pattern)),
306+
PIPE,
307+
field("tail", $.pattern)
308+
),
309+
BRACKET_RIGHT
310+
),
311+
299312
pat_tuple: ($) => prec(PREC.PATTERN, tuple($.pattern)),
300313
pat_map: ($) =>
301314
seq(HASH, BRACE_LEFT, opt(sepBy(COMMA, $.pat_map_entry)), BRACE_RIGHT),

src/grammar.json

Lines changed: 87 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@
295295
},
296296
"comment": {
297297
"type": "PATTERN",
298-
"value": "%.*\\n"
298+
"value": "%.*"
299299
},
300300
"type_declaration": {
301301
"type": "SEQ",
@@ -1221,16 +1221,75 @@
12211221
"type": "PREC",
12221222
"value": 3,
12231223
"content": {
1224-
"type": "SEQ",
1224+
"type": "CHOICE",
12251225
"members": [
12261226
{
1227-
"type": "STRING",
1228-
"value": "["
1229-
},
1230-
{
1231-
"type": "CHOICE",
1227+
"type": "SEQ",
12321228
"members": [
12331229
{
1230+
"type": "STRING",
1231+
"value": "["
1232+
},
1233+
{
1234+
"type": "CHOICE",
1235+
"members": [
1236+
{
1237+
"type": "SEQ",
1238+
"members": [
1239+
{
1240+
"type": "SYMBOL",
1241+
"name": "pattern"
1242+
},
1243+
{
1244+
"type": "REPEAT",
1245+
"content": {
1246+
"type": "SEQ",
1247+
"members": [
1248+
{
1249+
"type": "STRING",
1250+
"value": ","
1251+
},
1252+
{
1253+
"type": "SYMBOL",
1254+
"name": "pattern"
1255+
}
1256+
]
1257+
}
1258+
}
1259+
]
1260+
},
1261+
{
1262+
"type": "BLANK"
1263+
}
1264+
]
1265+
},
1266+
{
1267+
"type": "STRING",
1268+
"value": "]"
1269+
}
1270+
]
1271+
},
1272+
{
1273+
"type": "SYMBOL",
1274+
"name": "pat_list_cons"
1275+
}
1276+
]
1277+
}
1278+
},
1279+
"pat_list_cons": {
1280+
"type": "SEQ",
1281+
"members": [
1282+
{
1283+
"type": "STRING",
1284+
"value": "["
1285+
},
1286+
{
1287+
"type": "SEQ",
1288+
"members": [
1289+
{
1290+
"type": "FIELD",
1291+
"name": "init",
1292+
"content": {
12341293
"type": "SEQ",
12351294
"members": [
12361295
{
@@ -1254,18 +1313,27 @@
12541313
}
12551314
}
12561315
]
1257-
},
1258-
{
1259-
"type": "BLANK"
12601316
}
1261-
]
1262-
},
1263-
{
1264-
"type": "STRING",
1265-
"value": "]"
1266-
}
1267-
]
1268-
}
1317+
},
1318+
{
1319+
"type": "STRING",
1320+
"value": "|"
1321+
},
1322+
{
1323+
"type": "FIELD",
1324+
"name": "tail",
1325+
"content": {
1326+
"type": "SYMBOL",
1327+
"name": "pattern"
1328+
}
1329+
}
1330+
]
1331+
},
1332+
{
1333+
"type": "STRING",
1334+
"value": "]"
1335+
}
1336+
]
12691337
},
12701338
"pat_tuple": {
12711339
"type": "PREC",
@@ -3928,7 +3996,7 @@
39283996
"extras": [
39293997
{
39303998
"type": "PATTERN",
3931-
"value": "[\\x00-\\x20\\x80-\\xA0]"
3999+
"value": "[\\x01-\\x20\\x80-\\xA0]"
39324000
},
39334001
{
39344002
"type": "SYMBOL",

src/node-types.json

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4100,7 +4100,7 @@
41004100
"fields": {},
41014101
"children": {
41024102
"multiple": false,
4103-
"required": true,
4103+
"required": false,
41044104
"types": [
41054105
{
41064106
"type": "atom",
@@ -5275,13 +5275,47 @@
52755275
"multiple": true,
52765276
"required": false,
52775277
"types": [
5278+
{
5279+
"type": "pat_list_cons",
5280+
"named": true
5281+
},
52785282
{
52795283
"type": "pattern",
52805284
"named": true
52815285
}
52825286
]
52835287
}
52845288
},
5289+
{
5290+
"type": "pat_list_cons",
5291+
"named": true,
5292+
"fields": {
5293+
"init": {
5294+
"multiple": true,
5295+
"required": true,
5296+
"types": [
5297+
{
5298+
"type": ",",
5299+
"named": false
5300+
},
5301+
{
5302+
"type": "pattern",
5303+
"named": true
5304+
}
5305+
]
5306+
},
5307+
"tail": {
5308+
"multiple": false,
5309+
"required": true,
5310+
"types": [
5311+
{
5312+
"type": "pattern",
5313+
"named": true
5314+
}
5315+
]
5316+
}
5317+
}
5318+
},
52855319
{
52865320
"type": "pat_map_entry",
52875321
"named": true,

0 commit comments

Comments
 (0)