@lvce-editor/shared-process 0.11.8 → 0.11.10
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/config/defaultKeyBindings.json +25 -0
- package/config/defaultSettings.json +2 -7
- package/extensions/builtin.language-basics-coffeescript/src/tokenizeCoffeeScript.js +232 -3
- package/extensions/builtin.language-basics-cpp/src/tokenizeCpp.js +14 -0
- package/extensions/builtin.language-basics-css/src/tokenizeCss.js +8 -0
- package/extensions/builtin.language-basics-javascript/src/tokenizeJavaScript.js +52 -4
- package/extensions/builtin.language-basics-perl/extension.json +2 -1
- package/extensions/builtin.language-basics-perl/src/tokenizePerl.js +53 -6
- package/extensions/builtin.language-basics-python/src/tokenizePython.js +86 -3
- package/extensions/builtin.language-basics-ruby/README.md +14 -0
- package/extensions/builtin.language-basics-ruby/extension.json +48 -0
- package/extensions/builtin.language-basics-ruby/src/tokenizeRuby.js +241 -0
- package/extensions/builtin.language-basics-scss/README.md +14 -0
- package/extensions/builtin.language-basics-scss/extension.json +12 -0
- package/extensions/builtin.language-basics-scss/src/tokenizeScss.js +28 -0
- package/extensions/builtin.language-basics-shellscript/extension.json +2 -1
- package/extensions/builtin.language-basics-shellscript/src/tokenizeShellScript.js +326 -13
- package/extensions/builtin.language-basics-toml/src/tokenizeToml.js +87 -13
- package/extensions/builtin.language-basics-xml/extension.json +2 -1
- package/extensions/builtin.language-basics-xml/src/tokenizeXml.js +7 -0
- package/extensions/builtin.language-basics-yaml/src/tokenizeYaml.js +8 -1
- package/extensions/builtin.theme-cobalt2/color-theme.json +4 -0
- package/extensions/builtin.theme-gruvbox/color-theme.json +4 -0
- package/extensions/builtin.theme-palenight/color-theme.json +4 -0
- package/extensions/builtin.theme-slime/color-theme.json +9 -1
- package/package.json +5 -5
- package/src/parts/Cli/Cli.js +2 -2
- package/src/parts/CliInstall/CliInstall.js +21 -6
- package/src/parts/CliList/CliList.js +3 -2
- package/src/parts/CliUnlink/CliUnlink.js +1 -1
- package/src/parts/DownloadAndExtract/DownloadAndExtract.js +18 -8
- package/src/parts/ErrorCodes/ErrorCodes.js +8 -18
- package/src/parts/ErrorHandling/ErrorHandling.js +4 -9
- package/src/parts/ExportStatic/ExportStatic.js +57 -330
- package/src/parts/ExtensionHost/ExtensionHost.js +4 -7
- package/src/parts/ExtensionInstallFromGitHub/ExtensionInstallFromGitHub.js +1 -4
- package/src/parts/ExtensionManagement/ExtensionManagementColorTheme.js +3 -4
- package/src/parts/FileSystem/FileSystem.js +5 -15
- package/src/parts/GetResponse/GetResponse.js +10 -14
- package/src/parts/JsonRpc/JsonRpc.js +3 -6
- package/src/parts/JsonRpcErrorCode/JsonRpcErrorCode.js +2 -0
- package/src/parts/JsonRpcVersion/JsonRpcVersion.js +1 -0
- package/src/parts/OutputChannel/OutputChannel.ipc.js +3 -2
- package/src/parts/Terminal/Terminal.js +5 -4
- package/src/sharedProcessMain.js +2 -5
|
@@ -750,5 +750,30 @@
|
|
|
750
750
|
{
|
|
751
751
|
"key": "ctrl+\\",
|
|
752
752
|
"command": "Run And Debug.togglePause"
|
|
753
|
+
},
|
|
754
|
+
{
|
|
755
|
+
"key": "Enter",
|
|
756
|
+
"command": "Run And Debug.handleEvaluate",
|
|
757
|
+
"when": "focus.DebugInput"
|
|
758
|
+
},
|
|
759
|
+
{
|
|
760
|
+
"key": "ArrowLeft",
|
|
761
|
+
"command": "EditorImage.moveLeft",
|
|
762
|
+
"when": "focus.EditorImage"
|
|
763
|
+
},
|
|
764
|
+
{
|
|
765
|
+
"key": "ArrowRight",
|
|
766
|
+
"command": "EditorImage.moveRight",
|
|
767
|
+
"when": "focus.EditorImage"
|
|
768
|
+
},
|
|
769
|
+
{
|
|
770
|
+
"key": "ArrowUp",
|
|
771
|
+
"command": "EditorImage.moveUp",
|
|
772
|
+
"when": "focus.EditorImage"
|
|
773
|
+
},
|
|
774
|
+
{
|
|
775
|
+
"key": "ArrowDown",
|
|
776
|
+
"command": "EditorImage.moveDown",
|
|
777
|
+
"when": "focus.EditorImage"
|
|
753
778
|
}
|
|
754
779
|
]
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
"editor.fontFamily": "'Fira Code'",
|
|
8
8
|
"editor.lineHeight": 20,
|
|
9
9
|
"editor.formatOnSave": false,
|
|
10
|
+
"editor.letterSpacing": 0.5,
|
|
10
11
|
|
|
11
12
|
"extensions.autoUpdate": true,
|
|
12
13
|
|
|
@@ -37,11 +38,5 @@
|
|
|
37
38
|
|
|
38
39
|
"workspace.defaultWorkspace": "fetch:///playground",
|
|
39
40
|
|
|
40
|
-
"keyBindings.fallTroughBrowserView": [
|
|
41
|
-
"ctrl+p",
|
|
42
|
-
"ctrl+shift+p",
|
|
43
|
-
"ctrl+b",
|
|
44
|
-
"ctrl+m",
|
|
45
|
-
"ctrl+Tab"
|
|
46
|
-
]
|
|
41
|
+
"keyBindings.fallTroughBrowserView": ["ctrl+p", "ctrl+shift+p", "ctrl+b", "ctrl+m", "ctrl+Tab"]
|
|
47
42
|
}
|
|
@@ -1,14 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @enum number
|
|
3
|
+
*/
|
|
4
|
+
export const State = {
|
|
5
|
+
TopLevelContent: 1,
|
|
6
|
+
InsideDoubleQuoteString: 2,
|
|
7
|
+
InsideSingleQuoteString: 3,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const StateMap = {
|
|
11
|
+
[State.TopLevelContent]: 'TopLevelContent',
|
|
12
|
+
}
|
|
13
|
+
|
|
1
14
|
/**
|
|
2
15
|
* @enum number
|
|
3
16
|
*/
|
|
4
17
|
export const TokenType = {
|
|
18
|
+
None: 0,
|
|
5
19
|
Text: 1,
|
|
20
|
+
Comment: 2,
|
|
21
|
+
Whitespace: 3,
|
|
22
|
+
VariableName: 4,
|
|
23
|
+
Punctuation: 5,
|
|
24
|
+
Numeric: 6,
|
|
25
|
+
String: 7,
|
|
26
|
+
LanguageConstant: 8,
|
|
27
|
+
Keyword: 9,
|
|
28
|
+
KeywordImport: 215,
|
|
29
|
+
KeywordControl: 881,
|
|
30
|
+
KeywordModifier: 882,
|
|
31
|
+
KeywordReturn: 883,
|
|
32
|
+
KeywordNew: 884,
|
|
33
|
+
FunctionName: 885,
|
|
34
|
+
KeywordThis: 886,
|
|
35
|
+
KeywordOperator: 887,
|
|
36
|
+
Regex: 888,
|
|
6
37
|
}
|
|
7
38
|
|
|
8
39
|
export const TokenMap = {
|
|
9
40
|
[TokenType.Text]: 'Text',
|
|
41
|
+
[TokenType.Comment]: 'Comment',
|
|
42
|
+
[TokenType.Whitespace]: 'Whitespace',
|
|
43
|
+
[TokenType.VariableName]: 'VariableName',
|
|
44
|
+
[TokenType.Punctuation]: 'Punctuation',
|
|
45
|
+
[TokenType.Numeric]: 'Numeric',
|
|
46
|
+
[TokenType.String]: 'String',
|
|
47
|
+
[TokenType.KeywordImport]: 'KeywordImport',
|
|
48
|
+
[TokenType.KeywordControl]: 'KeywordControl',
|
|
49
|
+
[TokenType.KeywordModifier]: 'KeywordModifier',
|
|
50
|
+
[TokenType.KeywordReturn]: 'KeywordReturn',
|
|
51
|
+
[TokenType.KeywordNew]: 'KeywordNew',
|
|
52
|
+
[TokenType.FunctionName]: 'Function',
|
|
53
|
+
[TokenType.KeywordThis]: 'KeywordThis',
|
|
54
|
+
[TokenType.KeywordOperator]: 'KeywordOperator',
|
|
55
|
+
[TokenType.LanguageConstant]: 'LanguageConstant',
|
|
56
|
+
[TokenType.Keyword]: 'Keyword',
|
|
57
|
+
[TokenType.Regex]: 'Regex',
|
|
10
58
|
}
|
|
11
59
|
|
|
60
|
+
const RE_LINE_COMMENT = /^#[^\n]*/
|
|
61
|
+
const RE_WHITESPACE = /^\s+/
|
|
62
|
+
const RE_VARIABLE_NAME = /^[\@a-zA-Z\_\$][a-zA-Z\_\/\-\$#\d\-]*/
|
|
63
|
+
const RE_PUNCTUATION = /^[:,;\{\}\[\]\.=\(\)<>\!\|\+\&\>\)\?]/
|
|
64
|
+
const RE_NUMERIC =
|
|
65
|
+
/^((0(x|X)[0-9a-fA-F]*)|(([0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)\b/
|
|
66
|
+
const RE_STRING_ESCAPE = /^\\./
|
|
67
|
+
const RE_BACKSLASH_AT_END = /^\\$/
|
|
68
|
+
const RE_ANYTHING = /^.+/s
|
|
69
|
+
const RE_QUOTE_DOUBLE = /^"/
|
|
70
|
+
const RE_QUOTE_SINGLE = /^'/
|
|
71
|
+
const RE_STRING_DOUBLE_QUOTE_CONTENT = /^[^"\\]+/
|
|
72
|
+
const RE_STRING_SINGLE_QUOTE_CONTENT = /^[^'\\]+/
|
|
73
|
+
const RE_KEYWORD =
|
|
74
|
+
/^(?:and|arguments|async|await|break|by|case|catch|class|const|debugger|default|delete|do|else|enum|export|extends|false|finally|for|function|if|implements|import|in|Infinity|instanceof|interface|is|isnt|let|loop|NaN|native|new|no|not|null|of|off|on|or|package|private|protected|public|return|static|super|switch|then|this|throw|try|true|typeof|undefined|unless|var|void|when|while|with|yes)\b/
|
|
75
|
+
// copied from https://github.com/PrismJS/prism/blob/master/components/prism-javascript.js#L57
|
|
76
|
+
const RE_REGEX =
|
|
77
|
+
/^((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/
|
|
78
|
+
const RE_SLASH = /^\//
|
|
79
|
+
const RE_ANYTHING_UNTIL_END = /^.+/s
|
|
80
|
+
const RE_FUNCTION_CALL_NAME = /^[\@\w]+(?=\s*('|\=\s*function|\=\s*\(|\?\(|\())/
|
|
81
|
+
|
|
12
82
|
export const initialLineState = {
|
|
13
83
|
state: 1,
|
|
14
84
|
tokens: [],
|
|
@@ -18,11 +88,170 @@ export const hasArrayReturn = true
|
|
|
18
88
|
|
|
19
89
|
/**
|
|
20
90
|
* @param {string} line
|
|
91
|
+
* @param {any} lineState
|
|
21
92
|
*/
|
|
22
|
-
export const tokenizeLine = (line) => {
|
|
23
|
-
|
|
93
|
+
export const tokenizeLine = (line, lineState) => {
|
|
94
|
+
let next = null
|
|
95
|
+
let index = 0
|
|
96
|
+
let tokens = []
|
|
97
|
+
let token = TokenType.None
|
|
98
|
+
let state = lineState.state
|
|
99
|
+
while (index < line.length) {
|
|
100
|
+
const part = line.slice(index)
|
|
101
|
+
switch (state) {
|
|
102
|
+
case State.TopLevelContent:
|
|
103
|
+
if ((next = part.match(RE_WHITESPACE))) {
|
|
104
|
+
token = TokenType.Whitespace
|
|
105
|
+
state = State.TopLevelContent
|
|
106
|
+
} else if ((next = part.match(RE_KEYWORD))) {
|
|
107
|
+
switch (next[0]) {
|
|
108
|
+
case 'true':
|
|
109
|
+
case 'false':
|
|
110
|
+
case 'null':
|
|
111
|
+
case 'on':
|
|
112
|
+
case 'off':
|
|
113
|
+
case 'yes':
|
|
114
|
+
case 'no':
|
|
115
|
+
case 'undefined':
|
|
116
|
+
token = TokenType.LanguageConstant
|
|
117
|
+
break
|
|
118
|
+
case 'import':
|
|
119
|
+
case 'export':
|
|
120
|
+
case 'from':
|
|
121
|
+
token = TokenType.KeywordImport
|
|
122
|
+
break
|
|
123
|
+
case 'as':
|
|
124
|
+
case 'switch':
|
|
125
|
+
case 'default':
|
|
126
|
+
case 'case':
|
|
127
|
+
case 'else':
|
|
128
|
+
case 'then':
|
|
129
|
+
case 'if':
|
|
130
|
+
case 'break':
|
|
131
|
+
case 'throw':
|
|
132
|
+
case 'for':
|
|
133
|
+
case 'try':
|
|
134
|
+
case 'catch':
|
|
135
|
+
case 'finally':
|
|
136
|
+
case 'while':
|
|
137
|
+
case 'when':
|
|
138
|
+
case 'unless':
|
|
139
|
+
token = TokenType.KeywordControl
|
|
140
|
+
break
|
|
141
|
+
case 'async':
|
|
142
|
+
case 'await':
|
|
143
|
+
token = TokenType.KeywordModifier
|
|
144
|
+
break
|
|
145
|
+
case 'return':
|
|
146
|
+
token = TokenType.KeywordReturn
|
|
147
|
+
break
|
|
148
|
+
case 'new':
|
|
149
|
+
token = TokenType.KeywordNew
|
|
150
|
+
break
|
|
151
|
+
case 'this':
|
|
152
|
+
token = TokenType.KeywordThis
|
|
153
|
+
break
|
|
154
|
+
case 'delete':
|
|
155
|
+
case 'typeof':
|
|
156
|
+
case 'in':
|
|
157
|
+
case 'instanceof':
|
|
158
|
+
case 'and':
|
|
159
|
+
case 'is':
|
|
160
|
+
case 'isnt':
|
|
161
|
+
token = TokenType.KeywordOperator
|
|
162
|
+
break
|
|
163
|
+
case 'Infinity':
|
|
164
|
+
token = TokenType.Numeric
|
|
165
|
+
break
|
|
166
|
+
default:
|
|
167
|
+
token = TokenType.Keyword
|
|
168
|
+
break
|
|
169
|
+
}
|
|
170
|
+
state = State.TopLevelContent
|
|
171
|
+
} else if ((next = part.match(RE_PUNCTUATION))) {
|
|
172
|
+
token = TokenType.Punctuation
|
|
173
|
+
state = State.TopLevelContent
|
|
174
|
+
} else if ((next = part.match(RE_FUNCTION_CALL_NAME))) {
|
|
175
|
+
token = TokenType.FunctionName
|
|
176
|
+
state = State.TopLevelContent
|
|
177
|
+
} else if ((next = part.match(RE_VARIABLE_NAME))) {
|
|
178
|
+
token = TokenType.VariableName
|
|
179
|
+
state = State.TopLevelContent
|
|
180
|
+
} else if ((next = part.match(RE_NUMERIC))) {
|
|
181
|
+
token = TokenType.Numeric
|
|
182
|
+
state = State.TopLevelContent
|
|
183
|
+
} else if ((next = part.match(RE_SLASH))) {
|
|
184
|
+
if ((next = part.match(RE_REGEX))) {
|
|
185
|
+
token = TokenType.Regex
|
|
186
|
+
state = State.TopLevelContent
|
|
187
|
+
} else {
|
|
188
|
+
next = part.match(RE_SLASH)
|
|
189
|
+
token = TokenType.Punctuation
|
|
190
|
+
state = State.TopLevelContent
|
|
191
|
+
}
|
|
192
|
+
} else if ((next = part.match(RE_QUOTE_DOUBLE))) {
|
|
193
|
+
token = TokenType.Punctuation
|
|
194
|
+
state = State.InsideDoubleQuoteString
|
|
195
|
+
} else if ((next = part.match(RE_QUOTE_SINGLE))) {
|
|
196
|
+
token = TokenType.Punctuation
|
|
197
|
+
state = State.InsideSingleQuoteString
|
|
198
|
+
} else if ((next = part.match(RE_LINE_COMMENT))) {
|
|
199
|
+
token = TokenType.Comment
|
|
200
|
+
state = State.TopLevelContent
|
|
201
|
+
} else if ((next = part.match(RE_NUMERIC))) {
|
|
202
|
+
token = TokenType.Numeric
|
|
203
|
+
state = State.TopLevelContent
|
|
204
|
+
} else if ((next = part.match(RE_ANYTHING))) {
|
|
205
|
+
token = TokenType.Text
|
|
206
|
+
state = State.TopLevelContent
|
|
207
|
+
} else {
|
|
208
|
+
part //?
|
|
209
|
+
throw new Error('no')
|
|
210
|
+
}
|
|
211
|
+
break
|
|
212
|
+
case State.InsideDoubleQuoteString:
|
|
213
|
+
if ((next = part.match(RE_QUOTE_DOUBLE))) {
|
|
214
|
+
token = TokenType.Punctuation
|
|
215
|
+
state = State.TopLevelContent
|
|
216
|
+
} else if ((next = part.match(RE_STRING_DOUBLE_QUOTE_CONTENT))) {
|
|
217
|
+
token = TokenType.String
|
|
218
|
+
state = State.InsideDoubleQuoteString
|
|
219
|
+
} else if ((next = part.match(RE_STRING_ESCAPE))) {
|
|
220
|
+
token = TokenType.String
|
|
221
|
+
state = State.InsideDoubleQuoteString
|
|
222
|
+
} else if ((next = part.match(RE_BACKSLASH_AT_END))) {
|
|
223
|
+
token = TokenType.String
|
|
224
|
+
state = State.InsideDoubleQuoteString
|
|
225
|
+
} else {
|
|
226
|
+
throw new Error('no')
|
|
227
|
+
}
|
|
228
|
+
break
|
|
229
|
+
case State.InsideSingleQuoteString:
|
|
230
|
+
if ((next = part.match(RE_QUOTE_SINGLE))) {
|
|
231
|
+
token = TokenType.Punctuation
|
|
232
|
+
state = State.TopLevelContent
|
|
233
|
+
} else if ((next = part.match(RE_STRING_SINGLE_QUOTE_CONTENT))) {
|
|
234
|
+
token = TokenType.String
|
|
235
|
+
state = State.InsideSingleQuoteString
|
|
236
|
+
} else if ((next = part.match(RE_STRING_ESCAPE))) {
|
|
237
|
+
token = TokenType.String
|
|
238
|
+
state = State.InsideSingleQuoteString
|
|
239
|
+
} else if ((next = part.match(RE_BACKSLASH_AT_END))) {
|
|
240
|
+
token = TokenType.String
|
|
241
|
+
state = State.InsideSingleQuoteString
|
|
242
|
+
} else {
|
|
243
|
+
throw new Error('no')
|
|
244
|
+
}
|
|
245
|
+
break
|
|
246
|
+
default:
|
|
247
|
+
throw new Error('no')
|
|
248
|
+
}
|
|
249
|
+
const tokenLength = next[0].length
|
|
250
|
+
index += tokenLength
|
|
251
|
+
tokens.push(token, tokenLength)
|
|
252
|
+
}
|
|
24
253
|
return {
|
|
25
|
-
state
|
|
254
|
+
state,
|
|
26
255
|
tokens,
|
|
27
256
|
}
|
|
28
257
|
}
|
|
@@ -161,6 +161,9 @@ export const tokenizeLine = (line, lineState) => {
|
|
|
161
161
|
} else if ((next = part.match(RE_PUNCTUATION))) {
|
|
162
162
|
token = TokenType.Punctuation
|
|
163
163
|
state = State.TopLevelContent
|
|
164
|
+
} else if ((next = part.match(RE_DOUBLE_QUOTE))) {
|
|
165
|
+
token = TokenType.Punctuation
|
|
166
|
+
state = State.InsideDoubleQuoteString
|
|
164
167
|
} else if ((next = part.match(RE_TEXT))) {
|
|
165
168
|
token = TokenType.Text
|
|
166
169
|
state = State.TopLevelContent
|
|
@@ -230,6 +233,17 @@ export const tokenizeLine = (line, lineState) => {
|
|
|
230
233
|
throw new Error('no')
|
|
231
234
|
}
|
|
232
235
|
break
|
|
236
|
+
case State.InsideDoubleQuoteString:
|
|
237
|
+
if ((next = part.match(RE_STRING_DOUBLE_QUOTE_CONTENT))) {
|
|
238
|
+
token = TokenType.String
|
|
239
|
+
state = State.InsideDoubleQuoteString
|
|
240
|
+
} else if ((next = part.match(RE_DOUBLE_QUOTE))) {
|
|
241
|
+
token = TokenType.Punctuation
|
|
242
|
+
state = State.TopLevelContent
|
|
243
|
+
} else {
|
|
244
|
+
throw new Error('no')
|
|
245
|
+
}
|
|
246
|
+
break
|
|
233
247
|
default:
|
|
234
248
|
state
|
|
235
249
|
throw new Error('no')
|
|
@@ -341,6 +341,14 @@ export const tokenizeLine = (line, lineState) => {
|
|
|
341
341
|
} else if ((next = part.match(RE_FUNCTION))) {
|
|
342
342
|
token = TokenType.FuntionName
|
|
343
343
|
state = State.AfterFunctionName
|
|
344
|
+
} else if ((next = part.match(RE_SINGLE_QUOTE))) {
|
|
345
|
+
token = TokenType.Punctuation
|
|
346
|
+
state = State.InsideSingleQuoteString
|
|
347
|
+
stack.push(State.AfterPropertyNameAfterColon)
|
|
348
|
+
} else if ((next = part.match(RE_DOUBLE_QUOTE))) {
|
|
349
|
+
token = TokenType.Punctuation
|
|
350
|
+
state = State.InsideDoubleQuoteString
|
|
351
|
+
stack.push(State.AfterPropertyNameAfterColon)
|
|
344
352
|
} else if ((next = part.match(RE_PROPERTY_VALUE_SHORT))) {
|
|
345
353
|
token = TokenType.CssPropertyValue
|
|
346
354
|
state = State.AfterPropertyNameAfterColon
|
|
@@ -20,6 +20,7 @@ const State = {
|
|
|
20
20
|
InsideSingleQuoteString: 15,
|
|
21
21
|
InsideDoubleQuoteString: 16,
|
|
22
22
|
InsideBacktickString: 17,
|
|
23
|
+
AfterPropertyDot: 18,
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
/**
|
|
@@ -50,6 +51,7 @@ export const TokenType = {
|
|
|
50
51
|
KeywordNew: 884,
|
|
51
52
|
FunctionName: 885,
|
|
52
53
|
KeywordThis: 886,
|
|
54
|
+
KeywordOperator: 887,
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
export const TokenMap = {
|
|
@@ -77,6 +79,7 @@ export const TokenMap = {
|
|
|
77
79
|
[TokenType.KeywordNew]: 'KeywordNew',
|
|
78
80
|
[TokenType.FunctionName]: 'Function',
|
|
79
81
|
[TokenType.KeywordThis]: 'KeywordThis',
|
|
82
|
+
[TokenType.KeywordOperator]: 'KeywordOperator',
|
|
80
83
|
}
|
|
81
84
|
|
|
82
85
|
const RE_KEYWORD =
|
|
@@ -119,11 +122,14 @@ const RE_STRING_BACKTICK_QUOTE_CONTENT = /^[^`\\]+/
|
|
|
119
122
|
const RE_STRING_ESCAPE = /^\\./
|
|
120
123
|
const RE_SHEBANG = /^#!.*/
|
|
121
124
|
const RE_FUNCTION_CALL_NAME = /^[\w]+(?=\s*(\(|\=\s*function|\=\s*\())/
|
|
125
|
+
const RE_DECORATOR = /^@\w+/
|
|
122
126
|
|
|
123
127
|
// copied from https://github.com/PrismJS/prism/blob/master/components/prism-javascript.js#L57
|
|
124
128
|
const RE_REGEX =
|
|
125
129
|
/^((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/
|
|
126
130
|
|
|
131
|
+
const RE_VARIABLE_NAME_SPECIAL = /\p{L}/u
|
|
132
|
+
|
|
127
133
|
export const initialLineState = {
|
|
128
134
|
state: State.TopLevelContent,
|
|
129
135
|
}
|
|
@@ -174,6 +180,7 @@ export const tokenizeLine = (line, lineState) => {
|
|
|
174
180
|
case 'catch':
|
|
175
181
|
case 'finally':
|
|
176
182
|
case 'continue':
|
|
183
|
+
case 'while':
|
|
177
184
|
token = TokenType.KeywordControl
|
|
178
185
|
break
|
|
179
186
|
case 'async':
|
|
@@ -189,6 +196,11 @@ export const tokenizeLine = (line, lineState) => {
|
|
|
189
196
|
case 'this':
|
|
190
197
|
token = TokenType.KeywordThis
|
|
191
198
|
break
|
|
199
|
+
case 'delete':
|
|
200
|
+
case 'typeof':
|
|
201
|
+
case 'in':
|
|
202
|
+
token = TokenType.KeywordOperator
|
|
203
|
+
break
|
|
192
204
|
default:
|
|
193
205
|
token = TokenType.Keyword
|
|
194
206
|
break
|
|
@@ -205,17 +217,21 @@ export const tokenizeLine = (line, lineState) => {
|
|
|
205
217
|
state = State.TopLevelContent
|
|
206
218
|
} else if ((next = part.match(RE_PUNCTUATION))) {
|
|
207
219
|
token = TokenType.Punctuation
|
|
208
|
-
|
|
220
|
+
if (next[0] === '.') {
|
|
221
|
+
state = State.AfterPropertyDot
|
|
222
|
+
} else {
|
|
223
|
+
state = State.TopLevelContent
|
|
224
|
+
}
|
|
209
225
|
} else if ((next = part.match(RE_SLASH))) {
|
|
210
226
|
if ((next = part.match(RE_BLOCK_COMMENT_START))) {
|
|
211
227
|
token = TokenType.Comment
|
|
212
228
|
state = State.InsideBlockComment
|
|
213
|
-
} else if ((next = part.match(RE_REGEX))) {
|
|
214
|
-
token = TokenType.Regex
|
|
215
|
-
state = State.TopLevelContent
|
|
216
229
|
} else if ((next = part.match(RE_LINE_COMMENT_START))) {
|
|
217
230
|
token = TokenType.Comment
|
|
218
231
|
state = State.InsideLineComment
|
|
232
|
+
} else if ((next = part.match(RE_REGEX))) {
|
|
233
|
+
token = TokenType.Regex
|
|
234
|
+
state = State.TopLevelContent
|
|
219
235
|
} else {
|
|
220
236
|
next = part.match(RE_SLASH)
|
|
221
237
|
token = TokenType.Punctuation
|
|
@@ -236,6 +252,12 @@ export const tokenizeLine = (line, lineState) => {
|
|
|
236
252
|
} else if ((next = part.match(RE_SHEBANG))) {
|
|
237
253
|
token = TokenType.Comment
|
|
238
254
|
state = State.TopLevelContent
|
|
255
|
+
} else if ((next = part.match(RE_DECORATOR))) {
|
|
256
|
+
token = TokenType.VariableName
|
|
257
|
+
state = State.TopLevelContent
|
|
258
|
+
} else if ((next = part.match(RE_VARIABLE_NAME_SPECIAL))) {
|
|
259
|
+
token = TokenType.VariableName
|
|
260
|
+
state = State.TopLevelContent
|
|
239
261
|
} else {
|
|
240
262
|
throw new Error('no')
|
|
241
263
|
}
|
|
@@ -316,6 +338,29 @@ export const tokenizeLine = (line, lineState) => {
|
|
|
316
338
|
throw new Error('no')
|
|
317
339
|
}
|
|
318
340
|
break
|
|
341
|
+
case State.AfterPropertyDot:
|
|
342
|
+
if ((next = part.match(RE_WHITESPACE))) {
|
|
343
|
+
token = TokenType.Whitespace
|
|
344
|
+
state = State.AfterPropertyDot
|
|
345
|
+
} else if ((next = part.match(RE_FUNCTION_CALL_NAME))) {
|
|
346
|
+
token = TokenType.FunctionName
|
|
347
|
+
state = State.TopLevelContent
|
|
348
|
+
} else if ((next = part.match(RE_VARIABLE_NAME))) {
|
|
349
|
+
token = TokenType.VariableName
|
|
350
|
+
state = State.TopLevelContent
|
|
351
|
+
} else if ((next = part.match(RE_LINE_COMMENT))) {
|
|
352
|
+
token = TokenType.Comment
|
|
353
|
+
state = State.InsideLineComment
|
|
354
|
+
} else if ((next = part.match(RE_BLOCK_COMMENT_START))) {
|
|
355
|
+
token = TokenType.Comment
|
|
356
|
+
state = State.InsideBlockComment
|
|
357
|
+
} else if ((next = part.match(RE_PUNCTUATION))) {
|
|
358
|
+
token = TokenType.Punctuation
|
|
359
|
+
state = State.TopLevelContent
|
|
360
|
+
} else {
|
|
361
|
+
throw new Error('no')
|
|
362
|
+
}
|
|
363
|
+
break
|
|
319
364
|
default:
|
|
320
365
|
state
|
|
321
366
|
throw new Error('no')
|
|
@@ -324,6 +369,9 @@ export const tokenizeLine = (line, lineState) => {
|
|
|
324
369
|
index += tokenLength
|
|
325
370
|
tokens.push(token, tokenLength)
|
|
326
371
|
}
|
|
372
|
+
if (state === State.InsideLineComment) {
|
|
373
|
+
state = State.TopLevelContent
|
|
374
|
+
}
|
|
327
375
|
return {
|
|
328
376
|
state,
|
|
329
377
|
tokens,
|
|
@@ -5,6 +5,7 @@ export const State = {
|
|
|
5
5
|
TopLevelContent: 1,
|
|
6
6
|
InsideString: 2,
|
|
7
7
|
InsideLineComment: 3,
|
|
8
|
+
InsideSingleQuoteString: 4,
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
export const StateMap = {
|
|
@@ -25,6 +26,9 @@ export const TokenType = {
|
|
|
25
26
|
VariableName: 8,
|
|
26
27
|
Comment: 885,
|
|
27
28
|
Text: 9,
|
|
29
|
+
KeywordControl: 10,
|
|
30
|
+
KeywordReturn: 11,
|
|
31
|
+
Function: 12,
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
export const TokenMap = {
|
|
@@ -38,11 +42,14 @@ export const TokenMap = {
|
|
|
38
42
|
[TokenType.VariableName]: 'VariableName',
|
|
39
43
|
[TokenType.Comment]: 'Comment',
|
|
40
44
|
[TokenType.Text]: 'Text',
|
|
45
|
+
[TokenType.KeywordControl]: 'KeywordControl',
|
|
46
|
+
[TokenType.KeywordReturn]: 'KeywordReturn',
|
|
47
|
+
[TokenType.Function]: 'Function',
|
|
41
48
|
}
|
|
42
49
|
|
|
43
50
|
const RE_LINE_COMMENT = /^#.*/s
|
|
44
51
|
const RE_SELECTOR = /^[\.a-zA-Z\d\-\:>]+/
|
|
45
|
-
const RE_WHITESPACE =
|
|
52
|
+
const RE_WHITESPACE = /^\s+/
|
|
46
53
|
const RE_CURLY_OPEN = /^\{/
|
|
47
54
|
const RE_CURLY_CLOSE = /^\}/
|
|
48
55
|
const RE_PROPERTY_NAME = /^[a-zA-Z\-]+\b/
|
|
@@ -55,11 +62,13 @@ const RE_ANYTHING_UNTIL_CLOSE_BRACE = /^[^\}]+/
|
|
|
55
62
|
const RE_QUOTE_DOUBLE = /^"/
|
|
56
63
|
const RE_STRING_DOUBLE_QUOTE_CONTENT = /^[^"]+/
|
|
57
64
|
const RE_KEYWORD =
|
|
58
|
-
/^(?:case|continue|default|die|no|else|elsif|eval|exit|for|foreach|given|goto|if|last|next|redo|require|return|select|switch|unless|until|use|wait|when|while)\b/
|
|
59
|
-
|
|
60
|
-
const RE_VARIABLE_NAME = /^[a-zA-Z\_]+/
|
|
61
|
-
const RE_PUNCTUATION = /^[:,;\{\}\[\]\.=\(\)
|
|
65
|
+
/^(?:case|continue|default|die|no|else|elsif|eval|exit|for|foreach|given|goto|if|last|next|push|redo|require|return|select|shift|sub|switch|unless|until|use|wait|when|while)\b/
|
|
66
|
+
const RE_STRING_SINGLE_QUOTE_CONTENT = /^[^']+/
|
|
67
|
+
const RE_VARIABLE_NAME = /^[$a-zA-Z\_@%]+/
|
|
68
|
+
const RE_PUNCTUATION = /^[:,;\{\}\[\]\.=\(\)<>\\\-\?]/
|
|
62
69
|
const RE_NUMERIC = /^\d+/
|
|
70
|
+
const RE_QUOTE_BACKTICK = /^`/
|
|
71
|
+
const RE_QUOTE_SINGLE = /^'/
|
|
63
72
|
|
|
64
73
|
export const initialLineState = {
|
|
65
74
|
state: State.TopLevelContent,
|
|
@@ -96,7 +105,31 @@ export const tokenizeLine = (line, lineState) => {
|
|
|
96
105
|
token = TokenType.Whitespace
|
|
97
106
|
state = State.TopLevelContent
|
|
98
107
|
} else if ((next = part.match(RE_KEYWORD))) {
|
|
99
|
-
|
|
108
|
+
switch (next[0]) {
|
|
109
|
+
case 'unless':
|
|
110
|
+
case 'foreach':
|
|
111
|
+
case 'if':
|
|
112
|
+
case 'while':
|
|
113
|
+
case 'next':
|
|
114
|
+
case 'else':
|
|
115
|
+
case 'last':
|
|
116
|
+
case 'elsif':
|
|
117
|
+
token = TokenType.KeywordControl
|
|
118
|
+
break
|
|
119
|
+
case 'return':
|
|
120
|
+
token = TokenType.KeywordReturn
|
|
121
|
+
break
|
|
122
|
+
case 'shift':
|
|
123
|
+
case 'push':
|
|
124
|
+
case 'eval':
|
|
125
|
+
case 'exit':
|
|
126
|
+
case 'die':
|
|
127
|
+
token = TokenType.Function
|
|
128
|
+
break
|
|
129
|
+
default:
|
|
130
|
+
token = TokenType.Keyword
|
|
131
|
+
break
|
|
132
|
+
}
|
|
100
133
|
state = State.TopLevelContent
|
|
101
134
|
} else if ((next = part.match(RE_PUNCTUATION))) {
|
|
102
135
|
token = TokenType.Punctuation
|
|
@@ -110,6 +143,9 @@ export const tokenizeLine = (line, lineState) => {
|
|
|
110
143
|
} else if ((next = part.match(RE_QUOTE_DOUBLE))) {
|
|
111
144
|
token = TokenType.PunctuationString
|
|
112
145
|
state = State.InsideString
|
|
146
|
+
} else if ((next = part.match(RE_QUOTE_SINGLE))) {
|
|
147
|
+
token = TokenType.Punctuation
|
|
148
|
+
state = State.InsideSingleQuoteString
|
|
113
149
|
} else if ((next = part.match(RE_LINE_COMMENT))) {
|
|
114
150
|
token = TokenType.Comment
|
|
115
151
|
state = State.TopLevelContent
|
|
@@ -132,6 +168,17 @@ export const tokenizeLine = (line, lineState) => {
|
|
|
132
168
|
throw new Error('no')
|
|
133
169
|
}
|
|
134
170
|
break
|
|
171
|
+
case State.InsideSingleQuoteString:
|
|
172
|
+
if ((next = part.match(RE_QUOTE_SINGLE))) {
|
|
173
|
+
token = TokenType.Punctuation
|
|
174
|
+
state = State.TopLevelContent
|
|
175
|
+
} else if ((next = part.match(RE_STRING_SINGLE_QUOTE_CONTENT))) {
|
|
176
|
+
token = TokenType.String
|
|
177
|
+
state = State.InsideSingleQuoteString
|
|
178
|
+
} else {
|
|
179
|
+
throw new Error('no')
|
|
180
|
+
}
|
|
181
|
+
break
|
|
135
182
|
default:
|
|
136
183
|
throw new Error('no')
|
|
137
184
|
}
|