cspell-grammar 8.7.0 → 8.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.js +5 -5
- package/dist/mappers/appendMappedText.js +4 -4
- package/dist/mappers/typescript.js +21 -14
- package/dist/parser/matchResult.js +1 -5
- package/dist/parser/scope.js +1 -1
- package/dist/parser/tokenizeLine.js +1 -1
- package/dist/parser/validateGrammar.js +2 -2
- package/dist/viewer/escapeMarkdown.js +5 -2
- package/dist/viewer/markdownHelper.js +1 -1
- package/dist/viewer/visualizeAsMD.js +1 -2
- package/package.json +6 -6
package/dist/app.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { promises as fs } from 'fs';
|
|
2
|
-
import * as path from 'path';
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
3
|
import { parser as parserTypeScript } from './parsers/typescript/index.js';
|
|
4
4
|
const parsers = {
|
|
5
5
|
'.ts': parserTypeScript,
|
|
@@ -15,7 +15,7 @@ export async function run(args) {
|
|
|
15
15
|
console.log('usage...');
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
-
const filename = args.slice(2).
|
|
18
|
+
const filename = args.slice(2).find((p) => !p.startsWith('-'));
|
|
19
19
|
if (!filename) {
|
|
20
20
|
console.log('filename missing');
|
|
21
21
|
return;
|
|
@@ -27,14 +27,14 @@ export async function run(args) {
|
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
29
|
console.log(`File: ${path.basename(filename)} Parser: ${parser.name}`);
|
|
30
|
-
const content = await fs.readFile(filename, '
|
|
30
|
+
const content = await fs.readFile(filename, 'utf8');
|
|
31
31
|
const result = parser.parse(content, filename);
|
|
32
32
|
for (const pt of result.parsedTexts) {
|
|
33
33
|
emit(pt);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
function emit(pt) {
|
|
37
|
-
const t = pt.text.
|
|
37
|
+
const t = pt.text.replaceAll('\t', '↦').replaceAll(/\r?\n/g, '↩︎').replaceAll('\r', '⇠');
|
|
38
38
|
console.log(`${pt.range[0]}-${pt.range[1]}\t${t}\t${pt.scope?.toString() || ''}`);
|
|
39
39
|
}
|
|
40
40
|
//# sourceMappingURL=app.js.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import assert from 'assert';
|
|
1
|
+
import assert from 'node:assert';
|
|
2
2
|
export function appendMappedText(a, b) {
|
|
3
3
|
if (!a.map && !b.map) {
|
|
4
4
|
return { text: a.text + b.text };
|
|
5
5
|
}
|
|
6
6
|
const aLen = a.text.length;
|
|
7
7
|
const bLen = b.text.length;
|
|
8
|
-
const aMap = [0, 0
|
|
9
|
-
const bMap = [0, 0
|
|
8
|
+
const aMap = [0, 0, ...(a.map || [0, 0, aLen, aLen])];
|
|
9
|
+
const bMap = [0, 0, ...(b.map || [0, 0, bLen, bLen])];
|
|
10
10
|
assert(aMap[aMap.length - 1] === aLen);
|
|
11
11
|
assert(bMap[bMap.length - 1] === bLen);
|
|
12
12
|
assert((aMap.length & 1) === 0);
|
|
@@ -19,7 +19,7 @@ export function appendMappedText(a, b) {
|
|
|
19
19
|
function joinMaps(aMap, bMap) {
|
|
20
20
|
const n = aMap.length - 1;
|
|
21
21
|
const offsets = [aMap[n - 1], aMap[n]];
|
|
22
|
-
const ab = aMap
|
|
22
|
+
const ab = [...aMap, ...bMap.map((v, i) => v + offsets[i & 1])];
|
|
23
23
|
// Normalize the map by removing duplicate entries
|
|
24
24
|
const r = [0, 0];
|
|
25
25
|
let last0 = 0, last1 = 0;
|
|
@@ -55,14 +55,14 @@ export function mapRawString(text) {
|
|
|
55
55
|
continue;
|
|
56
56
|
}
|
|
57
57
|
switch (tc) {
|
|
58
|
-
case 'u':
|
|
58
|
+
case 'u': {
|
|
59
59
|
{
|
|
60
60
|
let char;
|
|
61
61
|
let end;
|
|
62
62
|
if (text[i + 1] !== '{') {
|
|
63
63
|
const digits = text.slice(i + 1, i + 5);
|
|
64
|
-
parsed = isHex.test(digits) ? parseInt(digits, 16) : NaN;
|
|
65
|
-
char = isNaN(parsed) ? '' : String.
|
|
64
|
+
parsed = isHex.test(digits) ? Number.parseInt(digits, 16) : Number.NaN;
|
|
65
|
+
char = Number.isNaN(parsed) ? '' : String.fromCodePoint(parsed);
|
|
66
66
|
end = i + 4;
|
|
67
67
|
}
|
|
68
68
|
else {
|
|
@@ -74,8 +74,8 @@ export function mapRawString(text) {
|
|
|
74
74
|
}
|
|
75
75
|
else {
|
|
76
76
|
const digits = text.slice(i + 2, end);
|
|
77
|
-
parsed = isHex.test(digits) ? parseInt(digits, 16) : NaN;
|
|
78
|
-
char = isNaN(parsed) ? '' : String.fromCodePoint(parsed);
|
|
77
|
+
parsed = isHex.test(digits) ? Number.parseInt(digits, 16) : Number.NaN;
|
|
78
|
+
char = Number.isNaN(parsed) ? '' : String.fromCodePoint(parsed);
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
if (!char) {
|
|
@@ -89,38 +89,45 @@ export function mapRawString(text) {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
break;
|
|
92
|
-
|
|
92
|
+
}
|
|
93
|
+
case 'x': {
|
|
93
94
|
{
|
|
94
95
|
const digits = text.slice(i + 1, i + 3);
|
|
95
|
-
parsed = isHex.test(digits) ? parseInt(digits, 16) : NaN;
|
|
96
|
-
if (isNaN(parsed)) {
|
|
96
|
+
parsed = isHex.test(digits) ? Number.parseInt(digits, 16) : Number.NaN;
|
|
97
|
+
if (Number.isNaN(parsed)) {
|
|
97
98
|
// give up, it is not valid
|
|
98
99
|
t += tc;
|
|
99
100
|
j += 1;
|
|
100
101
|
}
|
|
101
102
|
else {
|
|
102
|
-
t += String.
|
|
103
|
+
t += String.fromCodePoint(parsed);
|
|
103
104
|
i += 2;
|
|
104
105
|
++j;
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
108
|
break;
|
|
108
|
-
|
|
109
|
+
}
|
|
110
|
+
case '0': {
|
|
109
111
|
// Deprecated in ES5
|
|
110
112
|
t += '0';
|
|
111
113
|
j += 1;
|
|
112
114
|
break;
|
|
113
|
-
|
|
115
|
+
}
|
|
116
|
+
case '\r': {
|
|
114
117
|
i += text[i + 1] === '\n' ? 1 : 0;
|
|
115
118
|
break;
|
|
116
|
-
|
|
119
|
+
}
|
|
120
|
+
case '\n': {
|
|
117
121
|
break;
|
|
118
|
-
|
|
122
|
+
}
|
|
123
|
+
case undefined: {
|
|
119
124
|
break;
|
|
120
|
-
|
|
125
|
+
}
|
|
126
|
+
default: {
|
|
121
127
|
t += tc;
|
|
122
128
|
++j;
|
|
123
129
|
break;
|
|
130
|
+
}
|
|
124
131
|
}
|
|
125
132
|
map.push(i + 1, j);
|
|
126
133
|
continue;
|
|
@@ -28,11 +28,7 @@ export function segmentMatch(mr) {
|
|
|
28
28
|
const s = value && textToSeg.get(value);
|
|
29
29
|
if (!s)
|
|
30
30
|
continue;
|
|
31
|
-
s.groupName = s.groupName
|
|
32
|
-
? Array.isArray(s.groupName)
|
|
33
|
-
? s.groupName.concat([name])
|
|
34
|
-
: [s.groupName, name]
|
|
35
|
-
: name;
|
|
31
|
+
s.groupName = s.groupName ? (Array.isArray(s.groupName) ? [...s.groupName, name] : [s.groupName, name]) : name;
|
|
36
32
|
}
|
|
37
33
|
return segments;
|
|
38
34
|
}
|
package/dist/parser/scope.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { strict as assert } from 'assert';
|
|
2
|
-
import { format } from 'util';
|
|
1
|
+
import { strict as assert } from 'node:assert';
|
|
2
|
+
import { format } from 'node:util';
|
|
3
3
|
import { isPatternBeginEnd, isPatternInclude, isPatternMatch, isPatternPatterns } from './grammarTypesHelpers.js';
|
|
4
4
|
export function validate(grammar) {
|
|
5
5
|
assert(grammar.scopeName);
|
|
@@ -21,7 +21,7 @@ function _escape(str, r) {
|
|
|
21
21
|
r.lastIndex = 0;
|
|
22
22
|
while (r.test(str)) {
|
|
23
23
|
const i = r.lastIndex - 1;
|
|
24
|
-
html += str.substring(lastIndex, i) + cvt[str.
|
|
24
|
+
html += str.substring(lastIndex, i) + (cvt[str.codePointAt(i) || 0] || '');
|
|
25
25
|
lastIndex = r.lastIndex;
|
|
26
26
|
}
|
|
27
27
|
return html + str.substring(lastIndex);
|
|
@@ -33,7 +33,10 @@ function compileEntities(entityMap) {
|
|
|
33
33
|
result[i] = `&#${i};`;
|
|
34
34
|
}
|
|
35
35
|
for (const [char, entity] of Object.entries(entityMap)) {
|
|
36
|
-
|
|
36
|
+
const index = char.codePointAt(0);
|
|
37
|
+
if (!index)
|
|
38
|
+
continue;
|
|
39
|
+
result[index] = entity;
|
|
37
40
|
}
|
|
38
41
|
return result;
|
|
39
42
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { escapeMarkdown } from './escapeMarkdown.js';
|
|
2
2
|
export function toInlineCode(text) {
|
|
3
|
-
return `<code>${escapeMarkdown(text.
|
|
3
|
+
return `<code>${escapeMarkdown(text.replaceAll('\r', '↤').replaceAll('\n', '↩'))}</code>`;
|
|
4
4
|
}
|
|
5
5
|
//# sourceMappingURL=markdownHelper.js.map
|
|
@@ -5,8 +5,7 @@ export function _tokenizedLineToMarkdown(line, indentation = '') {
|
|
|
5
5
|
|
|
6
6
|
| text | scope |
|
|
7
7
|
| --------- | -------------------------------------------------------- |`;
|
|
8
|
-
markdownLines.push(...header.split('\n'));
|
|
9
|
-
markdownLines.push(...line.tokens.map((t) => ` | ${toInlineCode(t.text)} | ${t.scope} |`));
|
|
8
|
+
markdownLines.push(...header.split('\n'), ...line.tokens.map((t) => ` | ${toInlineCode(t.text)} | ${t.scope} |`));
|
|
10
9
|
return markdownLines.map((line) => indentation + line).join('\n') + '\n\n';
|
|
11
10
|
}
|
|
12
11
|
export function tokenizedLineToMarkdown(line, indentation = '') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cspell-grammar",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.8.1",
|
|
4
4
|
"description": "Grammar parsing support for cspell",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cspell",
|
|
@@ -62,12 +62,12 @@
|
|
|
62
62
|
],
|
|
63
63
|
"scripts": {
|
|
64
64
|
"clean": "shx rm -rf dist temp coverage \"*.tsbuildInfo\"",
|
|
65
|
-
"build": "tsc -b .",
|
|
65
|
+
"build": "tsc -b . -f",
|
|
66
66
|
"clean-build": "pnpm run clean && pnpm run build",
|
|
67
67
|
"coverage": "vitest run --coverage",
|
|
68
68
|
"test:watch": "vitest",
|
|
69
69
|
"test": "vitest run",
|
|
70
|
-
"watch": "tsc -b . -w"
|
|
70
|
+
"watch": "tsc -b . -w -f"
|
|
71
71
|
},
|
|
72
72
|
"repository": {
|
|
73
73
|
"type": "git",
|
|
@@ -84,8 +84,8 @@
|
|
|
84
84
|
"jest": "^29.7.0"
|
|
85
85
|
},
|
|
86
86
|
"dependencies": {
|
|
87
|
-
"@cspell/cspell-pipe": "8.
|
|
88
|
-
"@cspell/cspell-types": "8.
|
|
87
|
+
"@cspell/cspell-pipe": "8.8.1",
|
|
88
|
+
"@cspell/cspell-types": "8.8.1"
|
|
89
89
|
},
|
|
90
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "6381846ffce8b9a349bfda03262297aa8e301ef5"
|
|
91
91
|
}
|