jexl-lezer 0.4.0 → 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/package.json CHANGED
@@ -1,24 +1,34 @@
1
1
  {
2
2
  "name": "jexl-lezer",
3
- "description": "lezer-based Apache JEXL",
4
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
+ "description": "lezer-based JavaScript grammar",
5
+ "main": "dist/index.cjs",
5
6
  "type": "module",
6
7
  "exports": {
7
8
  "import": "./dist/index.js",
8
9
  "require": "./dist/index.cjs"
9
10
  },
11
+ "module": "dist/index.js",
12
+ "types": "dist/index.d.ts",
10
13
  "devDependencies": {
11
14
  "@lezer/generator": "^1.7.0",
12
- "@rollup/plugin-node-resolve": "^9.0.0",
13
15
  "mocha": "^10.2.0",
14
- "rollup": "^2.52.2"
16
+ "rollup": "^2.52.2",
17
+ "@rollup/plugin-node-resolve": "^9.0.0"
15
18
  },
16
19
  "dependencies": {
20
+ "@lezer/lr": "^1.3.0",
17
21
  "@lezer/common": "^1.2.0",
18
- "@lezer/highlight": "^1.1.3",
19
- "@lezer/lr": "^1.3.0"
22
+ "@lezer/highlight": "^1.1.3"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/lezer-parser/javascript.git"
20
27
  },
21
28
  "scripts": {
22
- "prepare": "rollup -c"
29
+ "build": "lezer-generator src/javascript.grammar -o src/parser && rollup -c",
30
+ "build-debug": "lezer-generator src/javascript.grammar --names -o src/parser && rollup -c",
31
+ "prepare": "npm run build",
32
+ "test": "mocha test/test-*.js"
23
33
  }
24
34
  }
package/rollup.config.js CHANGED
@@ -1,7 +1,7 @@
1
- import {lezer} from "@lezer/generator/rollup"
1
+ import {nodeResolve} from "@rollup/plugin-node-resolve"
2
2
 
3
3
  export default {
4
- input: "./src/jexl.grammar",
4
+ input: "./src/parser.js",
5
5
  output: [{
6
6
  format: "cjs",
7
7
  file: "./dist/index.cjs"
@@ -9,8 +9,8 @@ export default {
9
9
  format: "es",
10
10
  file: "./dist/index.js"
11
11
  }],
12
- external: ["@lezer/lr", "@lezer/highlight"],
12
+ external(id) { return !/^[\.\/]/.test(id) },
13
13
  plugins: [
14
- lezer()
14
+ nodeResolve()
15
15
  ]
16
16
  }
package/src/highlight.js CHANGED
@@ -1,192 +1,62 @@
1
- ////////////////////////////////////////////
2
- // highlight.js
3
- ////////////////////////////////////////////
4
- import { styleTags, tags as t } from "@lezer/highlight";
5
-
6
- export const jsHighlight = styleTags({
7
- "get set async static": t.modifier,
8
- "for while do if else switch try catch finally return throw break continue default case": t.controlKeyword,
9
- "in of await yield void typeof delete instanceof": t.operatorKeyword,
10
- "let var const using function class extends": t.definitionKeyword,
11
- "pragma import export from": t.moduleKeyword,
12
- "with debugger as new": t.keyword,
13
- TemplateString: t.special(t.string),
14
- super: t.atom,
15
- BooleanLiteral: t.bool,
16
- this: t.self,
17
- null: t.null,
18
- Star: t.modifier,
19
- VariableName: t.variableName,
20
- "CallExpression/VariableName TaggedTemplateExpression/VariableName": t.function(t.variableName),
21
- VariableDefinition: t.definition(t.variableName),
22
- Label: t.labelName,
23
- PropertyName: t.propertyName,
24
- PrivatePropertyName: t.special(t.propertyName),
25
- "CallExpression/MemberExpression/PropertyName": t.function(t.propertyName),
26
- "FunctionDeclaration/VariableDefinition": t.function(t.definition(t.variableName)),
27
- "ClassDeclaration/VariableDefinition": t.definition(t.className),
28
- "NewExpression/VariableName": t.className,
29
- PropertyDefinition: t.definition(t.propertyName),
30
- PrivatePropertyDefinition: t.definition(t.special(t.propertyName)),
31
- UpdateOp: t.updateOperator,
32
- "LineComment Hashbang": t.lineComment,
33
- BlockComment: t.blockComment,
34
- Number: t.number,
35
- String: t.string,
36
- Escape: t.escape,
37
- ArithOp: t.arithmeticOperator,
38
- LogicOp: t.logicOperator,
39
- BitOp: t.bitwiseOperator,
40
- CompareOp: t.compareOperator,
41
- RegExp: t.regexp,
42
- Equals: t.definitionOperator,
43
- Arrow: t.function(t.punctuation),
44
- ": Spread": t.punctuation,
45
- "( )": t.paren,
46
- "[ ]": t.squareBracket,
47
- "{ }": t.brace,
48
- "InterpolationStart InterpolationEnd": t.special(t.brace),
49
- ".": t.derefOperator,
50
- ", ;": t.separator,
51
- "@": t.meta,
52
- ClassPath: t.labelName,
53
-
54
- TypeName: t.typeName,
55
- TypeDefinition: t.definition(t.typeName),
56
- "type enum interface implements namespace module declare": t.definitionKeyword,
57
- "abstract global Privacy readonly override": t.modifier,
58
- "is keyof unique infer asserts": t.operatorKeyword,
59
-
60
- JSXAttributeValue: t.attributeValue,
61
- JSXText: t.content,
62
- "JSXStartTag JSXStartCloseTag JSXSelfCloseEndTag JSXEndTag": t.angleBracket,
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
+ })