@codemirror/language 6.10.7 → 6.11.0
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/CHANGELOG.md +12 -0
- package/README.md +48 -0
- package/dist/index.cjs +5 -3
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## 6.11.0 (2025-03-13)
|
|
2
|
+
|
|
3
|
+
### New features
|
|
4
|
+
|
|
5
|
+
Stream parsers now support a `mergeTokens` option that can be used to turn off automatic merging of adjacent tokens.
|
|
6
|
+
|
|
7
|
+
## 6.10.8 (2024-12-23)
|
|
8
|
+
|
|
9
|
+
### Bug fixes
|
|
10
|
+
|
|
11
|
+
Fix a regression introduced 6.10.7 that caused indention to sometimes crash on nested language boundaries.
|
|
12
|
+
|
|
1
13
|
## 6.10.7 (2024-12-17)
|
|
2
14
|
|
|
3
15
|
### Bug fixes
|
package/README.md
CHANGED
|
@@ -16,3 +16,51 @@ We aim to be an inclusive, welcoming community. To make that explicit,
|
|
|
16
16
|
we have a [code of
|
|
17
17
|
conduct](http://contributor-covenant.org/version/1/1/0/) that applies
|
|
18
18
|
to communication around the project.
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
Setting up a language from a [Lezer](https://lezer.codemirror.net)
|
|
23
|
+
parser looks like this:
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
import {parser} from "@lezer/json"
|
|
27
|
+
import {LRLanguage, continuedIndent, indentNodeProp,
|
|
28
|
+
foldNodeProp, foldInside} from "@codemirror/language"
|
|
29
|
+
|
|
30
|
+
export const jsonLanguage = LRLanguage.define({
|
|
31
|
+
name: "json",
|
|
32
|
+
parser: parser.configure({
|
|
33
|
+
props: [
|
|
34
|
+
indentNodeProp.add({
|
|
35
|
+
Object: continuedIndent({except: /^\s*\}/}),
|
|
36
|
+
Array: continuedIndent({except: /^\s*\]/})
|
|
37
|
+
}),
|
|
38
|
+
foldNodeProp.add({
|
|
39
|
+
"Object Array": foldInside
|
|
40
|
+
})
|
|
41
|
+
]
|
|
42
|
+
}),
|
|
43
|
+
languageData: {
|
|
44
|
+
closeBrackets: {brackets: ["[", "{", '"']},
|
|
45
|
+
indentOnInput: /^\s*[\}\]]$/
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Often, you'll also use this package just to access some specific
|
|
51
|
+
language-related features, such as accessing the editor's syntax
|
|
52
|
+
tree...
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
import {syntaxTree} from "@codemirror/language"
|
|
56
|
+
|
|
57
|
+
const tree = syntaxTree(view)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
... or computing the appriate indentation at a given point.
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
import {getIndentation} from "@codemirror/language"
|
|
64
|
+
|
|
65
|
+
console.log(getIndentation(view.state, view.state.selection.main.head))
|
|
66
|
+
```
|
package/dist/index.cjs
CHANGED
|
@@ -998,7 +998,7 @@ function syntaxIndentation(cx, ast, pos) {
|
|
|
998
998
|
let inner = ast.resolveInner(pos, -1).resolve(pos, 0).enterUnfinishedNodesBefore(pos);
|
|
999
999
|
if (inner != stack.node) {
|
|
1000
1000
|
let add = [];
|
|
1001
|
-
for (let cur = inner; cur
|
|
1001
|
+
for (let cur = inner; cur && !(cur.from == stack.node.from && cur.type == stack.node.type); cur = cur.parent)
|
|
1002
1002
|
add.push(cur);
|
|
1003
1003
|
for (let i = add.length - 1; i >= 0; i--)
|
|
1004
1004
|
stack = { node: add[i], next: stack };
|
|
@@ -2181,7 +2181,8 @@ function fullParser(spec) {
|
|
|
2181
2181
|
copyState: spec.copyState || defaultCopyState,
|
|
2182
2182
|
indent: spec.indent || (() => null),
|
|
2183
2183
|
languageData: spec.languageData || {},
|
|
2184
|
-
tokenTable: spec.tokenTable || noTokens
|
|
2184
|
+
tokenTable: spec.tokenTable || noTokens,
|
|
2185
|
+
mergeTokens: spec.mergeTokens !== false
|
|
2185
2186
|
};
|
|
2186
2187
|
}
|
|
2187
2188
|
function defaultCopyState(state) {
|
|
@@ -2404,7 +2405,8 @@ class Parse {
|
|
|
2404
2405
|
size += this.chunk.length - len0;
|
|
2405
2406
|
}
|
|
2406
2407
|
let last = this.chunk.length - 4;
|
|
2407
|
-
if (size == 4 && last >= 0 &&
|
|
2408
|
+
if (this.lang.streamParser.mergeTokens && size == 4 && last >= 0 &&
|
|
2409
|
+
this.chunk[last] == id && this.chunk[last + 2] == from)
|
|
2408
2410
|
this.chunk[last + 2] = to;
|
|
2409
2411
|
else
|
|
2410
2412
|
this.chunk.push(id, from, to, size);
|
package/dist/index.d.cts
CHANGED
|
@@ -1182,6 +1182,11 @@ interface StreamParser<State> {
|
|
|
1182
1182
|
tokenTable?: {
|
|
1183
1183
|
[name: string]: Tag | readonly Tag[];
|
|
1184
1184
|
};
|
|
1185
|
+
/**
|
|
1186
|
+
By default, adjacent tokens of the same type are merged in the
|
|
1187
|
+
output tree. Set this to false to disable that.
|
|
1188
|
+
*/
|
|
1189
|
+
mergeTokens?: boolean;
|
|
1185
1190
|
}
|
|
1186
1191
|
/**
|
|
1187
1192
|
A [language](https://codemirror.net/6/docs/ref/#language.Language) class based on a CodeMirror
|
package/dist/index.d.ts
CHANGED
|
@@ -1182,6 +1182,11 @@ interface StreamParser<State> {
|
|
|
1182
1182
|
tokenTable?: {
|
|
1183
1183
|
[name: string]: Tag | readonly Tag[];
|
|
1184
1184
|
};
|
|
1185
|
+
/**
|
|
1186
|
+
By default, adjacent tokens of the same type are merged in the
|
|
1187
|
+
output tree. Set this to false to disable that.
|
|
1188
|
+
*/
|
|
1189
|
+
mergeTokens?: boolean;
|
|
1185
1190
|
}
|
|
1186
1191
|
/**
|
|
1187
1192
|
A [language](https://codemirror.net/6/docs/ref/#language.Language) class based on a CodeMirror
|
package/dist/index.js
CHANGED
|
@@ -996,7 +996,7 @@ function syntaxIndentation(cx, ast, pos) {
|
|
|
996
996
|
let inner = ast.resolveInner(pos, -1).resolve(pos, 0).enterUnfinishedNodesBefore(pos);
|
|
997
997
|
if (inner != stack.node) {
|
|
998
998
|
let add = [];
|
|
999
|
-
for (let cur = inner; cur
|
|
999
|
+
for (let cur = inner; cur && !(cur.from == stack.node.from && cur.type == stack.node.type); cur = cur.parent)
|
|
1000
1000
|
add.push(cur);
|
|
1001
1001
|
for (let i = add.length - 1; i >= 0; i--)
|
|
1002
1002
|
stack = { node: add[i], next: stack };
|
|
@@ -2179,7 +2179,8 @@ function fullParser(spec) {
|
|
|
2179
2179
|
copyState: spec.copyState || defaultCopyState,
|
|
2180
2180
|
indent: spec.indent || (() => null),
|
|
2181
2181
|
languageData: spec.languageData || {},
|
|
2182
|
-
tokenTable: spec.tokenTable || noTokens
|
|
2182
|
+
tokenTable: spec.tokenTable || noTokens,
|
|
2183
|
+
mergeTokens: spec.mergeTokens !== false
|
|
2183
2184
|
};
|
|
2184
2185
|
}
|
|
2185
2186
|
function defaultCopyState(state) {
|
|
@@ -2402,7 +2403,8 @@ class Parse {
|
|
|
2402
2403
|
size += this.chunk.length - len0;
|
|
2403
2404
|
}
|
|
2404
2405
|
let last = this.chunk.length - 4;
|
|
2405
|
-
if (size == 4 && last >= 0 &&
|
|
2406
|
+
if (this.lang.streamParser.mergeTokens && size == 4 && last >= 0 &&
|
|
2407
|
+
this.chunk[last] == id && this.chunk[last + 2] == from)
|
|
2406
2408
|
this.chunk[last + 2] = to;
|
|
2407
2409
|
else
|
|
2408
2410
|
this.chunk.push(id, from, to, size);
|