Skip to content

Commit a681b76

Browse files
committed
Don't early terminate a 'balance' block.
This can cause tokens inside the block to be incorrectly terminated early. For example, in `[@ '[@ "inner code" @]' @]**` the single quote starts a 'balance' type block, and the `@]` inside the string tries to terminate the outer `[@` block. This early termination code may need further consideration. It is not part of PGML and is there to ensure that blocks that are improperly terminated show up in the tree. The point is to catch starting to type a new block inside of another. For example, say you have already typed ``[` `]``, and then you start to type `[$` inside that. This code terminates the outer block so that syntax highlighting continues to work after the outer block.
1 parent 45ac50a commit a681b76

File tree

4 files changed

+58
-11
lines changed

4 files changed

+58
-11
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openwebwork/codemirror-lang-pg",
3-
"version": "0.0.1-beta.20",
3+
"version": "0.0.1-beta.21",
44
"description": "PG language support for CodeMirror",
55
"author": "The WeBWorK Project",
66
"license": "MIT",

src/pgml-parse.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export class PGMLParse {
149149
this.Terminate(token);
150150
else if (
151151
!block.containerEnd &&
152+
block.type !== 'balance' &&
152153
block.prev?.terminator &&
153154
RegExp(
154155
`^${

test/pgml-substitutions.txt

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,31 @@ BEGIN_PGML
66
[@ '<div>hello</div>' @]***
77
[@ %f = (q => 4); $f{q} @]
88
[@ q}asdf} @]
9+
[@ '[@ "inner code" @]' @]**
910
END_PGML
1011

1112
==>
1213

1314
{
1415
"name": "Program",
1516
"from": 0,
16-
"to": 165,
17+
"to": 194,
1718
"children": [
1819
{
1920
"name": "PGMLBlock",
2021
"from": 0,
21-
"to": 165,
22+
"to": 194,
2223
"children": [
2324
{ "name": "BeginPG", "from": 0, "to": 10 },
2425
{
25-
"name": "PGMLContent",
26+
"name": "PGMLContent",
2627
"from": 10,
27-
"to": 157,
28+
"to": 186,
2829
"children": [
2930
{
3031
"name": "Paragraph",
3132
"from": 10,
32-
"to": 157,
33+
"to": 186,
3334
"children": [
3435
{
3536
"name": "PerlCommand",
@@ -258,12 +259,36 @@ END_PGML
258259
},
259260
{ "name": "PerlCommandMark", "from": 154, "to": 156 }
260261
]
262+
},
263+
{
264+
"name": "PerlCommand",
265+
"from": 157,
266+
"to": 185,
267+
"children": [
268+
{ "name": "PerlCommandMark", "from": 157, "to": 159 },
269+
{
270+
"name": "Program",
271+
"from": 159,
272+
"to": 181,
273+
"children": [
274+
{
275+
"name": "ExpressionStatement",
276+
"from": 160,
277+
"to": 180,
278+
"children": [
279+
{ "name": "StringSingleQuoted", "from": 160, "to": 180 }
280+
]
281+
}
282+
]
283+
},
284+
{ "name": "PerlCommandMark", "from": 181, "to": 185 }
285+
]
261286
}
262287
]
263288
}
264289
]
265290
},
266-
{ "name": "EndPG", "from": 157, "to": 165 }
291+
{ "name": "EndPG", "from": 186, "to": 194 }
267292
]
268293
}
269294
]
@@ -273,14 +298,14 @@ END_PGML
273298

274299
from: '0'
275300
parseAll: 'true'
276-
to: '146'
301+
to: '175'
277302
type: 'root'
278303
stack: [
279304
[ # 0
280305
combine: { indent: 'indent', list: { indent: '1' }, par: 'true' }
281306
from: '0'
282307
indent: '0'
283-
to: '146'
308+
to: '175'
284309
type: 'indent'
285310
stack: [
286311
[ # 0
@@ -386,6 +411,27 @@ stack: [
386411
type: 'text'
387412
stack: ['\n']
388413
]
414+
[ # 10
415+
allowDblStar: 'true'
416+
allowStar: 'true'
417+
allowTriStar: 'true'
418+
from: '146'
419+
hasDblStar: 'true'
420+
parseQuoted: 'true'
421+
terminator: '@]'
422+
text: ' '[@ "inner code" @]' '
423+
textFrom: '148'
424+
to: '174'
425+
token: '[@'
426+
type: 'command'
427+
]
428+
[ # 11
429+
combine: { text: 'type' }
430+
from: '174'
431+
to: '175'
432+
type: 'text'
433+
stack: ['\n']
434+
]
389435
]
390436
]
391437
]

0 commit comments

Comments
 (0)