Skip to content

Commit c0ba8d7

Browse files
committed
Add text block support (#105)
1 parent 881b84f commit c0ba8d7

File tree

6 files changed

+5593
-6260
lines changed

6 files changed

+5593
-6260
lines changed

grammar.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ module.exports = grammar({
8888
$.false,
8989
$.character_literal,
9090
$.string_literal,
91+
$.text_block,
9192
$.null_literal
9293
),
9394

@@ -155,6 +156,10 @@ module.exports = grammar({
155156
// seq('"', repeat(choice(/[^\\"\n]/, /\\(.|\n)/)), '"', '+', /\n/, '"', repeat(choice(/[^\\"\n]/, /\\(.|\n)/)))
156157
)),
157158

159+
text_block: $ => token(choice(
160+
seq('"""', /\s*\n/, optional(repeat(choice(/[^\\"]/, /\\(.)/))), '"""'),
161+
)),
162+
158163
null_literal: $ => 'null',
159164

160165
// Expressions

src/grammar.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
"type": "SYMBOL",
5353
"name": "string_literal"
5454
},
55+
{
56+
"type": "SYMBOL",
57+
"name": "text_block"
58+
},
5559
{
5660
"type": "SYMBOL",
5761
"name": "null_literal"
@@ -1097,6 +1101,55 @@
10971101
]
10981102
}
10991103
},
1104+
"text_block": {
1105+
"type": "TOKEN",
1106+
"content": {
1107+
"type": "CHOICE",
1108+
"members": [
1109+
{
1110+
"type": "SEQ",
1111+
"members": [
1112+
{
1113+
"type": "STRING",
1114+
"value": "\"\"\""
1115+
},
1116+
{
1117+
"type": "PATTERN",
1118+
"value": "\\s*\\n"
1119+
},
1120+
{
1121+
"type": "CHOICE",
1122+
"members": [
1123+
{
1124+
"type": "REPEAT",
1125+
"content": {
1126+
"type": "CHOICE",
1127+
"members": [
1128+
{
1129+
"type": "PATTERN",
1130+
"value": "[^\\\\\"]"
1131+
},
1132+
{
1133+
"type": "PATTERN",
1134+
"value": "\\\\(.)"
1135+
}
1136+
]
1137+
}
1138+
},
1139+
{
1140+
"type": "BLANK"
1141+
}
1142+
]
1143+
},
1144+
{
1145+
"type": "STRING",
1146+
"value": "\"\"\""
1147+
}
1148+
]
1149+
}
1150+
]
1151+
}
1152+
},
11001153
"null_literal": {
11011154
"type": "STRING",
11021155
"value": "null"

src/node-types.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
"type": "string_literal",
4444
"named": true
4545
},
46+
{
47+
"type": "text_block",
48+
"named": true
49+
},
4650
{
4751
"type": "true",
4852
"named": true
@@ -4088,6 +4092,10 @@
40884092
"type": "synchronized",
40894093
"named": false
40904094
},
4095+
{
4096+
"type": "text_block",
4097+
"named": true
4098+
},
40914099
{
40924100
"type": "this",
40934101
"named": true

0 commit comments

Comments
 (0)