Skip to content

Commit b2ecc87

Browse files
committed
Add TreeSitter support for firstLine regex
1 parent a14c85e commit b2ecc87

File tree

2 files changed

+48
-23
lines changed

2 files changed

+48
-23
lines changed

src/DiagnosticCollection.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,7 @@ function diagnosticsOnigurumaRegexErrors(diagnostics: vscode.Diagnostic[], trees
261261
for (const regexNode of regexNodes.values()) {
262262
const text = regexNode.text;
263263
const key = regexNode.previousNamedSibling;
264-
if (!key) { // `previousNamedSibling` is broken on 0width nodes
265-
vscode.window.showInformationMessage("0width broken!!");
264+
if (!key) {
266265
continue;
267266
}
268267

src/tree-sitter/tree-sitter-json/grammar.js

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,53 @@ module.exports = grammar({
1515
],
1616

1717
rules: {
18-
json: $ => repeat(
19-
choice(
20-
$._whitespace,
21-
object($,
22-
choice(
23-
$.version,
24-
$.schema,
25-
$.scopeName,
26-
$.name_display,
27-
$.information_for_contributors,
28-
$.fileTypes,
29-
$.firstLineMatch,
30-
$.foldingStartMarker,
31-
$.foldingStopMarker,
32-
$.injectionSelector,
33-
$.injections,
34-
$.patterns,
35-
$.repository,
36-
$.uuid,
37-
$._comments,
38-
$.item,
18+
json: $ => seq(
19+
optional(
20+
seq(
21+
fieldAlias($,
22+
'regex',
23+
token.immediate(
24+
seq(
25+
repeat(' '),
26+
choice(
27+
/[^\x00-\x1F\\"{\[]+/,
28+
/\\[^\x00-\x1F]/,
29+
),
30+
repeat(
31+
choice(
32+
/[^\x00-\x1F\\"]+/,
33+
/\\[^\x00-\x1F]/,
34+
),
35+
),
36+
37+
),
38+
),
39+
),
40+
/\r?\n|\x00/, // '\0' is treated as EOF
41+
),
42+
),
43+
repeat(
44+
choice(
45+
$._whitespace,
46+
object($,
47+
choice(
48+
$.version,
49+
$.schema,
50+
$.scopeName,
51+
$.name_display,
52+
$.information_for_contributors,
53+
$.fileTypes,
54+
$.firstLineMatch,
55+
$.foldingStartMarker,
56+
$.foldingStopMarker,
57+
$.injectionSelector,
58+
$.injections,
59+
$.patterns,
60+
$.repository,
61+
$.uuid,
62+
$._comments,
63+
$.item,
64+
),
3965
),
4066
),
4167
),

0 commit comments

Comments
 (0)