jexl-lezer 0.4.1 → 0.5.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/README.md +14 -1
- package/dist/index.cjs +21 -21
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +21 -21
- package/package.json +17 -7
- package/rollup.config.js +3 -3
- package/src/highlight.js +62 -192
- package/src/{jexl.grammar → javascript.grammar} +735 -745
- package/src/parser.js +21 -21
- package/src/parser.terms.js +166 -165
- package/test/decorator.txt +64 -0
- package/test/expression.txt +686 -0
- package/test/jsx.txt +79 -0
- package/test/semicolon.txt +77 -0
- package/test/statement.txt +404 -0
- package/test/test-javascript.js +17 -0
- package/test/typescript.txt +401 -0
package/src/highlight.js
CHANGED
|
@@ -1,192 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"JSXIdentifier JSXNameSpacedName": t.tagName,
|
|
64
|
-
"JSXAttribute/JSXIdentifier JSXAttribute/JSXNameSpacedName": t.attributeName,
|
|
65
|
-
"JSXBuiltin/JSXIdentifier": t.standard(t.tagName)
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
////////////////////////////////////////////
|
|
69
|
-
// tokens.js
|
|
70
|
-
////////////////////////////////////////////
|
|
71
|
-
|
|
72
|
-
/* Hand-written tokenizers for JavaScript tokens that can't be
|
|
73
|
-
expressed by lezer's built-in tokenizer. */
|
|
74
|
-
|
|
75
|
-
import {ExternalTokenizer, ContextTracker} from "@lezer/lr"
|
|
76
|
-
import {insertSemi, noSemi, noSemiType, incdec, incdecPrefix, questionDot,
|
|
77
|
-
spaces, newline, BlockComment, LineComment,
|
|
78
|
-
JSXStartTag, Dialect_jsx} from "./parser.terms.js"
|
|
79
|
-
|
|
80
|
-
const space = [9, 10, 11, 12, 13, 32, 133, 160, 5760, 8192, 8193, 8194, 8195, 8196, 8197, 8198, 8199, 8200,
|
|
81
|
-
8201, 8202, 8232, 8233, 8239, 8287, 12288]
|
|
82
|
-
|
|
83
|
-
const braceR = 125, semicolon = 59, slash = 47, star = 42, plus = 43, minus = 45, lt = 60, comma = 44,
|
|
84
|
-
question = 63, dot = 46, bracketL = 91
|
|
85
|
-
|
|
86
|
-
export const trackNewline = new ContextTracker({
|
|
87
|
-
start: false,
|
|
88
|
-
shift(context, term) {
|
|
89
|
-
return term == LineComment || term == BlockComment || term == spaces ? context : term == newline
|
|
90
|
-
},
|
|
91
|
-
strict: false
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
export const insertSemicolon = new ExternalTokenizer((input, stack) => {
|
|
95
|
-
let {next} = input
|
|
96
|
-
if (next == braceR || next == -1 || stack.context)
|
|
97
|
-
input.acceptToken(insertSemi)
|
|
98
|
-
}, {contextual: true, fallback: true})
|
|
99
|
-
|
|
100
|
-
export const noSemicolon = new ExternalTokenizer((input, stack) => {
|
|
101
|
-
let {next} = input, after
|
|
102
|
-
if (space.indexOf(next) > -1) return
|
|
103
|
-
if (next == slash && ((after = input.peek(1)) == slash || after == star)) return
|
|
104
|
-
if (next != braceR && next != semicolon && next != -1 && !stack.context)
|
|
105
|
-
input.acceptToken(noSemi)
|
|
106
|
-
}, {contextual: true})
|
|
107
|
-
|
|
108
|
-
export const noSemicolonType = new ExternalTokenizer((input, stack) => {
|
|
109
|
-
if (input.next == bracketL && !stack.context) input.acceptToken(noSemiType)
|
|
110
|
-
}, {contextual: true})
|
|
111
|
-
|
|
112
|
-
export const operatorToken = new ExternalTokenizer((input, stack) => {
|
|
113
|
-
let {next} = input
|
|
114
|
-
if (next == plus || next == minus) {
|
|
115
|
-
input.advance()
|
|
116
|
-
if (next == input.next) {
|
|
117
|
-
input.advance()
|
|
118
|
-
let mayPostfix = !stack.context && stack.canShift(incdec)
|
|
119
|
-
input.acceptToken(mayPostfix ? incdec : incdecPrefix)
|
|
120
|
-
}
|
|
121
|
-
} else if (next == question && input.peek(1) == dot) {
|
|
122
|
-
input.advance(); input.advance()
|
|
123
|
-
if (input.next < 48 || input.next > 57) // No digit after
|
|
124
|
-
input.acceptToken(questionDot)
|
|
125
|
-
}
|
|
126
|
-
}, {contextual: true})
|
|
127
|
-
|
|
128
|
-
function identifierChar(ch, start) {
|
|
129
|
-
return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 || ch == 95 || ch >= 192 ||
|
|
130
|
-
!start && ch >= 48 && ch <= 57
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export const jsx = new ExternalTokenizer((input, stack) => {
|
|
134
|
-
if (input.next != lt || !stack.dialectEnabled(Dialect_jsx)) return
|
|
135
|
-
input.advance()
|
|
136
|
-
if (input.next == slash) return
|
|
137
|
-
// Scan for an identifier followed by a comma or 'extends', don't
|
|
138
|
-
// treat this as a start tag if present.
|
|
139
|
-
let back = 0
|
|
140
|
-
while (space.indexOf(input.next) > -1) { input.advance(); back++ }
|
|
141
|
-
if (identifierChar(input.next, true)) {
|
|
142
|
-
input.advance()
|
|
143
|
-
back++
|
|
144
|
-
while (identifierChar(input.next, false)) { input.advance(); back++ }
|
|
145
|
-
while (space.indexOf(input.next) > -1) { input.advance(); back++ }
|
|
146
|
-
if (input.next == comma) return
|
|
147
|
-
for (let i = 0;; i++) {
|
|
148
|
-
if (i == 7) {
|
|
149
|
-
if (!identifierChar(input.next, true)) return
|
|
150
|
-
break
|
|
151
|
-
}
|
|
152
|
-
if (input.next != "extends".charCodeAt(i)) break
|
|
153
|
-
input.advance()
|
|
154
|
-
back++
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
input.acceptToken(JSXStartTag, -back)
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
// A very dim/dull syntax highlighting so you have something to look at, but also to trigger you to write your own ;)
|
|
161
|
-
// Also shows that you can use `export let extension = [...]`, to add extensions to the "demo text" editor.
|
|
162
|
-
import { HighlightStyle, syntaxHighlighting } from "@codemirror/language";
|
|
163
|
-
const syntax_colors = syntaxHighlighting(
|
|
164
|
-
HighlightStyle.define(
|
|
165
|
-
[
|
|
166
|
-
{ tag: t.name, color: "#a8a8a8" },
|
|
167
|
-
{ tag: t.propertyName, color: "#966a6a" },
|
|
168
|
-
{ tag: t.comment, color: "#4b4949" },
|
|
169
|
-
{ tag: t.atom, color: "#a25496" },
|
|
170
|
-
|
|
171
|
-
{ tag: t.literal, color: "#7b87b8" },
|
|
172
|
-
{ tag: t.unit, color: "#7b87b8" },
|
|
173
|
-
{ tag: t.null, color: "#7b87b8" },
|
|
174
|
-
|
|
175
|
-
{ tag: t.keyword, color: "#585858" },
|
|
176
|
-
{ tag: t.punctuation, color: "#585858" },
|
|
177
|
-
{ tag: t.derefOperator, color: "#585858" },
|
|
178
|
-
{ tag: t.special(t.brace), fontWeight: 700 },
|
|
179
|
-
|
|
180
|
-
{ tag: t.operator, color: "white" },
|
|
181
|
-
{ tag: t.self, color: "white" },
|
|
182
|
-
{ tag: t.function(t.punctuation), color: "white" },
|
|
183
|
-
{ tag: t.special(t.logicOperator), color: "white", fontWeight: "bold" },
|
|
184
|
-
{ tag: t.moduleKeyword, color: "white", fontWeight: "bold" },
|
|
185
|
-
{ tag: t.controlKeyword, color: "white", fontWeight: "bold" },
|
|
186
|
-
{ tag: t.controlOperator, color: "white", fontWeight: "bold" },
|
|
187
|
-
],
|
|
188
|
-
{ all: { color: "#585858" } }
|
|
189
|
-
)
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
export let extensions = [syntax_colors];
|
|
1
|
+
import {styleTags, tags as t} from "@lezer/highlight"
|
|
2
|
+
|
|
3
|
+
export const jsHighlight = styleTags({
|
|
4
|
+
"get set async static": t.modifier,
|
|
5
|
+
"for while do if else switch try catch finally return throw break continue default case defer": t.controlKeyword,
|
|
6
|
+
"in of await yield void typeof delete instanceof as satisfies": t.operatorKeyword,
|
|
7
|
+
"let var const using function class extends": t.definitionKeyword,
|
|
8
|
+
"import export from": t.moduleKeyword,
|
|
9
|
+
"with debugger new": t.keyword,
|
|
10
|
+
TemplateString: t.special(t.string),
|
|
11
|
+
super: t.atom,
|
|
12
|
+
BooleanLiteral: t.bool,
|
|
13
|
+
this: t.self,
|
|
14
|
+
null: t.null,
|
|
15
|
+
Star: t.modifier,
|
|
16
|
+
VariableName: t.variableName,
|
|
17
|
+
"CallExpression/VariableName TaggedTemplateExpression/VariableName": t.function(t.variableName),
|
|
18
|
+
VariableDefinition: t.definition(t.variableName),
|
|
19
|
+
Label: t.labelName,
|
|
20
|
+
PropertyName: t.propertyName,
|
|
21
|
+
PrivatePropertyName: t.special(t.propertyName),
|
|
22
|
+
"CallExpression/MemberExpression/PropertyName": t.function(t.propertyName),
|
|
23
|
+
"FunctionDeclaration/VariableDefinition": t.function(t.definition(t.variableName)),
|
|
24
|
+
"ClassDeclaration/VariableDefinition": t.definition(t.className),
|
|
25
|
+
"NewExpression/VariableName": t.className,
|
|
26
|
+
PropertyDefinition: t.definition(t.propertyName),
|
|
27
|
+
PrivatePropertyDefinition: t.definition(t.special(t.propertyName)),
|
|
28
|
+
UpdateOp: t.updateOperator,
|
|
29
|
+
"LineComment Hashbang": t.lineComment,
|
|
30
|
+
BlockComment: t.blockComment,
|
|
31
|
+
Number: t.number,
|
|
32
|
+
String: t.string,
|
|
33
|
+
Escape: t.escape,
|
|
34
|
+
ArithOp: t.arithmeticOperator,
|
|
35
|
+
LogicOp: t.logicOperator,
|
|
36
|
+
BitOp: t.bitwiseOperator,
|
|
37
|
+
CompareOp: t.compareOperator,
|
|
38
|
+
RegExp: t.regexp,
|
|
39
|
+
Equals: t.definitionOperator,
|
|
40
|
+
Arrow: t.function(t.punctuation),
|
|
41
|
+
": Spread": t.punctuation,
|
|
42
|
+
"( )": t.paren,
|
|
43
|
+
"[ ]": t.squareBracket,
|
|
44
|
+
"{ }": t.brace,
|
|
45
|
+
"InterpolationStart InterpolationEnd": t.special(t.brace),
|
|
46
|
+
".": t.derefOperator,
|
|
47
|
+
", ;": t.separator,
|
|
48
|
+
"@": t.meta,
|
|
49
|
+
|
|
50
|
+
TypeName: t.typeName,
|
|
51
|
+
TypeDefinition: t.definition(t.typeName),
|
|
52
|
+
"type enum interface implements namespace module declare": t.definitionKeyword,
|
|
53
|
+
"abstract global Privacy readonly override": t.modifier,
|
|
54
|
+
"is keyof unique infer asserts": t.operatorKeyword,
|
|
55
|
+
|
|
56
|
+
JSXAttributeValue: t.attributeValue,
|
|
57
|
+
JSXText: t.content,
|
|
58
|
+
"JSXStartTag JSXStartCloseTag JSXSelfCloseEndTag JSXEndTag": t.angleBracket,
|
|
59
|
+
"JSXIdentifier JSXNameSpacedName": t.tagName,
|
|
60
|
+
"JSXAttribute/JSXIdentifier JSXAttribute/JSXNameSpacedName": t.attributeName,
|
|
61
|
+
"JSXBuiltin/JSXIdentifier": t.standard(t.tagName)
|
|
62
|
+
})
|