@bhsd/lezer-json 2.2.1 → 2.3.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/README.md +18 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +21 -17
- package/dist/parser.js +11 -11
- package/package.json +17 -13
package/README.md
CHANGED
|
@@ -19,6 +19,9 @@ npm install @bhsd/lezer-json
|
|
|
19
19
|
|
|
20
20
|
## Language Support
|
|
21
21
|
|
|
22
|
+
You can directly import the language support that provides both the [language](#language)
|
|
23
|
+
and the basic [completion source](#completion-source) for JSON or JSONC.
|
|
24
|
+
|
|
22
25
|
```ts
|
|
23
26
|
import {json} from '@bhsd/lezer-json';
|
|
24
27
|
import type {LanguageSupport} from '@codemirror/language';
|
|
@@ -36,10 +39,23 @@ for JSON or JSONC alone.
|
|
|
36
39
|
import {jsonLanguage, jsoncLanguage} from '@bhsd/lezer-json';
|
|
37
40
|
```
|
|
38
41
|
|
|
42
|
+
## Completion Source
|
|
43
|
+
|
|
44
|
+
If you are importing the [language](#language) alone, you can choose to import
|
|
45
|
+
the completion source which provides basic completion for both JSON and JSONC.
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import {jsonCompletionSource, jsonLanguage, jsoncLanguage} from '@bhsd/lezer-json';
|
|
49
|
+
import type {Extension} from '@codemirror/state';
|
|
50
|
+
|
|
51
|
+
const jsonCompletion: Extension = jsonLanguage.data.of({autocomplete: jsonCompletionSource}),
|
|
52
|
+
jsoncCompletion: Extension = jsoncLanguage.data.of({autocomplete: jsonCompletionSource});
|
|
53
|
+
```
|
|
54
|
+
|
|
39
55
|
## Lint Source
|
|
40
56
|
|
|
41
|
-
This package also provides
|
|
42
|
-
|
|
57
|
+
This package also provides lint sources for JSON or JSONC syntax checking. This
|
|
58
|
+
is not included in the language support by default.
|
|
43
59
|
|
|
44
60
|
```ts
|
|
45
61
|
import {linter} from '@codemirror/lint';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { LRLanguage, LanguageSupport } from '@codemirror/language';
|
|
2
2
|
import type { LintSource } from '@codemirror/lint';
|
|
3
|
+
import type { CompletionSource } from '@codemirror/autocomplete';
|
|
3
4
|
/** LR language for JSON. */
|
|
4
5
|
export declare const jsonLanguage: LRLanguage;
|
|
5
6
|
/** LR language for JSONC. */
|
|
6
7
|
export declare const jsoncLanguage: LRLanguage;
|
|
8
|
+
export declare const jsonCompletionSource: CompletionSource;
|
|
7
9
|
/**
|
|
8
10
|
* Get language support for JSON or JSONC.
|
|
9
11
|
* @param dialect The dialect to use, either omitted or `'jsonc'` for JSON with comments.
|
package/dist/index.js
CHANGED
|
@@ -10,23 +10,8 @@ const props = [
|
|
|
10
10
|
'Object Array': foldInside,
|
|
11
11
|
}),
|
|
12
12
|
], options = ['true', 'false', 'null'].map((label) => ({ label, type: 'keyword' })), languageData = {
|
|
13
|
-
closeBrackets: {
|
|
13
|
+
closeBrackets: { brackets: ['[', '{', '"'] },
|
|
14
14
|
indentOnInput: /^\s*[}\]]$/u,
|
|
15
|
-
autocomplete(context) {
|
|
16
|
-
const mt = context.matchBefore(/(?:^|[[,:])\s*[a-z]+$/u);
|
|
17
|
-
if (!mt) {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
const { state, pos } = context, { name: n, parent: p } = syntaxTree(state).resolveInner(pos, -1), { from, text } = mt;
|
|
21
|
-
return (p === null || p === void 0 ? void 0 : p.name) === 'Array' && !text.startsWith(':')
|
|
22
|
-
|| n !== 'PropertyName' && (p === null || p === void 0 ? void 0 : p.name) === 'Property' && !/^[[,]/u.test(text)
|
|
23
|
-
? {
|
|
24
|
-
from: from + text.search(/[a-z]/iu),
|
|
25
|
-
options,
|
|
26
|
-
validFor: /^[a-z]*$/iu,
|
|
27
|
-
}
|
|
28
|
-
: null;
|
|
29
|
-
},
|
|
30
15
|
};
|
|
31
16
|
/** LR language for JSON. */
|
|
32
17
|
export const jsonLanguage = /* #__PURE__ */ (() => LRLanguage.define({
|
|
@@ -46,11 +31,30 @@ export const jsoncLanguage = /* #__PURE__ */ (() => LRLanguage.define({
|
|
|
46
31
|
},
|
|
47
32
|
},
|
|
48
33
|
}))();
|
|
34
|
+
export const jsonCompletionSource = context => {
|
|
35
|
+
const mt = context.matchBefore(/(?:^|[[,:])\s*[a-z]+$/u);
|
|
36
|
+
if (!mt) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const { state, pos } = context, { name: n, parent: p } = syntaxTree(state).resolveInner(pos, -1), { from, text } = mt;
|
|
40
|
+
return n !== 'String' && ((p === null || p === void 0 ? void 0 : p.name) === 'Array' && !text.startsWith(':')
|
|
41
|
+
|| n !== 'PropertyName' && (p === null || p === void 0 ? void 0 : p.name) === 'Property' && !/^[[,]/u.test(text)
|
|
42
|
+
|| (p === null || p === void 0 ? void 0 : p.name) === 'JsonText' && /^[\sa-z]/u.test(text))
|
|
43
|
+
? {
|
|
44
|
+
from: from + text.search(/[a-z]/iu),
|
|
45
|
+
options,
|
|
46
|
+
validFor: /^[a-z]*$/iu,
|
|
47
|
+
}
|
|
48
|
+
: null;
|
|
49
|
+
};
|
|
49
50
|
/**
|
|
50
51
|
* Get language support for JSON or JSONC.
|
|
51
52
|
* @param dialect The dialect to use, either omitted or `'jsonc'` for JSON with comments.
|
|
52
53
|
*/
|
|
53
|
-
export const json = (dialect) =>
|
|
54
|
+
export const json = (dialect) => {
|
|
55
|
+
const lang = dialect === 'jsonc' ? jsoncLanguage : jsonLanguage;
|
|
56
|
+
return new LanguageSupport(lang, lang.data.of({ autocomplete: jsonCompletionSource }));
|
|
57
|
+
};
|
|
54
58
|
const getLintSource = (lint) => ({ state: { doc } }) => lint(doc.toString())
|
|
55
59
|
.map(({ message, from, to = from, severity }) => ({ message, severity, from, to }));
|
|
56
60
|
/** Lint source for JSON */
|
package/dist/parser.js
CHANGED
|
@@ -3,22 +3,22 @@ import {LRParser, LocalTokenGroup} from "@lezer/lr"
|
|
|
3
3
|
import {jsonHighlighting} from "./highlight.js"
|
|
4
4
|
export const parser = LRParser.deserialize({
|
|
5
5
|
version: 14,
|
|
6
|
-
states: "
|
|
7
|
-
stateData: "
|
|
8
|
-
goto: "#
|
|
9
|
-
nodeNames: "⚠ LineComment BlockComment JsonText True False Null Number String } { Object Property PropertyName : ,
|
|
10
|
-
maxTerm:
|
|
6
|
+
states: "%|O]QPOOPtOPOOOOQO'#Cd'#CdOyQPO'#CgO!RQPO'#CnOOQO'#Cx'#CxQOQPOOP!YOQO'#C^POOO)C>i)C>iOOQO'#Ci'#CiO!bQPO'#ChO!gQPO'#CzOOQO,59R,59RO!oQPO,59RO!tQPO'#C{OOQO,59Y,59YO!|QPO,59YPOOO'#Co'#CoP#ROQO,58xPOOO,58x,58xO]QPO,59SO#ZQPO,59fO#cQPO,59fOOQO1G.m1G.mO#kQPO,59gO#rQPO,59gOOQO1G.t1G.tPOOO-E6m-E6mPOOO1G.d1G.dOOQO1G.n1G.nOOQO,59[,59[O#zQPO1G/QOOQO-E6n-E6nOOQO,59],59]O$SQPO1G/ROOQO-E6o-E6oP|QPO'#CpP]QPO'#Cq",
|
|
7
|
+
stateData: "$^~OhOSPOSiPQ~OSTOTTOUTOVTOYROaSOmQO~OiVO~OX[OmXO~O`_O~P]OjaOkcO~O^dO~O_eOXnX~OXgO~O_hO`oX~O`jO~OjaOklO~OmXOXna~O_oOXna~O`oa~P]O_rO`oa~OmXOXni~O`oi~P]OPi~",
|
|
8
|
+
goto: "#SpPPqPPPPPtPPt|!UPPPPt![!b!hPPPPPP!nP!|#PRWP]TOSdhruQZRVneotXYReotQbVRkbQfZRpfQi^RsiQUOQ^SQmdVqhruR]RR`S",
|
|
9
|
+
nodeNames: "⚠ LineComment BlockComment JsonText True False Null Number String } { Object Property PropertyName : , ] [ Array",
|
|
10
|
+
maxTerm: 31,
|
|
11
11
|
nodeProps: [
|
|
12
12
|
["isolate", -2,8,13,""],
|
|
13
|
-
["openedBy", 9,"{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21
|
topRules: {"JsonText":[0,3]},
|
|
22
|
-
dialects: {jsonc:
|
|
22
|
+
dialects: {jsonc: 149},
|
|
23
23
|
tokenPrec: 0
|
|
24
24
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bhsd/lezer-json",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"description": "Lezer-based JSON/JSONC grammar",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codemirror",
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
"files": [
|
|
22
22
|
"dist/"
|
|
23
23
|
],
|
|
24
|
-
"browser": "dist/index.js",
|
|
25
24
|
"main": "./dist/index.js",
|
|
26
25
|
"types": "./dist/index.d.ts",
|
|
27
26
|
"type": "module",
|
|
@@ -31,14 +30,16 @@
|
|
|
31
30
|
"url": "git+https://github.com/bhsd-harry/lezer-json.git"
|
|
32
31
|
},
|
|
33
32
|
"scripts": {
|
|
34
|
-
"ls": "npm i --package-lock-only && npm ls --package-lock-only
|
|
33
|
+
"ls": "npm i --package-lock-only && npm ls --package-lock-only -a --omit=dev",
|
|
35
34
|
"prepublishOnly": "npm run build",
|
|
36
35
|
"build:parser": "lezer-generator src/json.grammar -o src/parser.js",
|
|
37
36
|
"build:core": "tsc && cp src/parser.js dist/ && eslint --no-config-lookup -c eslint.dist.js dist/*.js",
|
|
38
37
|
"build": "npm run build:parser && npm run build:core",
|
|
39
|
-
"lint:ts": "tsc --noEmit && eslint --cache .",
|
|
40
|
-
"lint:md": "
|
|
41
|
-
"lint": "npm run lint:ts && npm run lint:md"
|
|
38
|
+
"lint:ts": "tsc --noEmit && tsc -p test/tsconfig.json --noEmit && oxlint && eslint --cache .",
|
|
39
|
+
"lint:md": "myMarkdownlint",
|
|
40
|
+
"lint": "npm run lint:ts && npm run lint:md",
|
|
41
|
+
"migrate": "oxlint-migrate",
|
|
42
|
+
"test": "rm -rf test/dist/; tsc -p test/tsconfig.json && testUtil test/dist/*.test.js"
|
|
42
43
|
},
|
|
43
44
|
"peerDependencies": {
|
|
44
45
|
"@codemirror/language": "^6.0.0",
|
|
@@ -50,16 +51,19 @@
|
|
|
50
51
|
}
|
|
51
52
|
},
|
|
52
53
|
"dependencies": {
|
|
53
|
-
"@bhsd/common": "^4.1.
|
|
54
|
+
"@bhsd/common": "^4.1.1"
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
|
-
"@bhsd/code-standard": "^
|
|
57
|
-
"@
|
|
58
|
-
"@codemirror/
|
|
57
|
+
"@bhsd/code-standard": "^5.1.0",
|
|
58
|
+
"@bhsd/test-util": "^3.3.1",
|
|
59
|
+
"@codemirror/autocomplete": "^6.20.4",
|
|
60
|
+
"@codemirror/language": "^6.13.1",
|
|
59
61
|
"@codemirror/lint": "^6.9.7",
|
|
60
|
-
"@
|
|
61
|
-
"
|
|
62
|
-
"
|
|
62
|
+
"@codemirror/state": "^6.7.6",
|
|
63
|
+
"@lezer/generator": "^1.8.1",
|
|
64
|
+
"@oxlint/migrate": "^1.90.0",
|
|
65
|
+
"eslint": "^10.14.0",
|
|
66
|
+
"oxlint": "^1.90.0",
|
|
63
67
|
"typescript": "^6.0.3"
|
|
64
68
|
}
|
|
65
69
|
}
|