@lvce-editor/shared-process 0.11.8 → 0.11.9

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.
@@ -6,7 +6,8 @@
6
6
  {
7
7
  "id": "perl",
8
8
  "extensions": [".pl", ".pm", ".pod", ".t", ".pL", ".psgi"],
9
- "tokenize": "src/tokenizePerl.js"
9
+ "tokenize": "src/tokenizePerl.js",
10
+ "firstLine": "^#!.*\\bperl\\b"
10
11
  }
11
12
  ]
12
13
  }
@@ -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
- token = TokenType.Keyword
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
  }
@@ -16,6 +16,8 @@ export const State = {
16
16
  InsideDoubleQuoteString: 11,
17
17
  InsideLineComment: 12,
18
18
  InsideSingleQuoteString: 13,
19
+ InsideTripleDoubleQuoteString: 14,
20
+ InsideTripleSingleQuoteString: 15,
19
21
  }
20
22
 
21
23
  /**
@@ -69,11 +71,13 @@ export const TokenMap = {
69
71
 
70
72
  const RE_WHITESPACE = /^\s+/
71
73
  const RE_DOUBLE_QUOTE = /^"/
74
+ const RE_TRIPLE_DOUBLE_QUOTE = /^"{3}/
72
75
  const RE_SINGLE_QUOTE = /^'/
73
76
  const RE_TEXT = /^.+/
74
77
  const RE_ANY_TEXT = /^[^\n]+/
75
- const RE_STRING_DOUBLE_QUOTE_CONTENT = /^[^"]+/
76
- const RE_STRING_SINGLE_QUOTE_CONTENT = /^[^']+/
78
+ const RE_STRING_DOUBLE_QUOTE_CONTENT = /^[^"\\]+/
79
+ const RE_STRING_SINGLE_QUOTE_CONTENT = /^[^'\\]+/
80
+ const RE_STRING_TRIPLE_DOUBLE_QUOTE_CONTENT = /^.+(?=""")/
77
81
  const RE_LINE_COMMENT = /^#/
78
82
  const RE_KEYWORD =
79
83
  /^(?:__debug__|Ellipsis|yield|with|while|try|true|True|return|raise|pass|or|NotImplemented|not|nonlocal|None|lambda|is|in|import|if|global|from|for|finally|False|false|except|else|elif|del|def|continue|class|break|await|async|assert|as|and)\b/
@@ -82,6 +86,14 @@ const RE_NUMERIC =
82
86
  /^((0(x|X)[0-9a-fA-F]*)|(([0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)\b/
83
87
  const RE_PUNCTUATION = /^[\(\)\{\}:,\+\-\*&=\/\\\[\]!\.<>%]+/
84
88
  const RE_FUNCTION_CALL_NAME = /^[\w]+(?=\s*\()/
89
+ const RE_DECORATOR = /^@[\w]+/
90
+ const RE_TRIPLE_QUOTED_STRING_CONTENT_DOUBLE_QUOTES = /.*(?=""")/s
91
+ const RE_TRIPLE_QUOTED_STRING_CONTENT_SINGLE_QUOTES = /.*(?=''')/s
92
+ const RE_TRIPLE_QUOTED_STRING_CONTENT_COMMON = /.*/s
93
+ const RE_STRING_ESCAPE = /^\\./
94
+ const RE_BACKSLASH = /^\\/
95
+ const RE_TRIPLE_SINGLE_QUOTE = /^'{3}/
96
+ const RE_NUMERIC_OCTAL = /^0(?:o|O)?[0-7][0-7_]*(n)?\b/
85
97
 
86
98
  export const initialLineState = {
87
99
  state: State.TopLevelContent,
@@ -130,6 +142,14 @@ export const tokenizeLine = (line, lineState) => {
130
142
  case 'finally':
131
143
  case 'while':
132
144
  case 'for':
145
+ case 'continue':
146
+ case 'not':
147
+ case 'except':
148
+ case 'with':
149
+ case 'as':
150
+ case 'raise':
151
+ case 'break':
152
+ case 'pass':
133
153
  token = TokenType.KeywordControl
134
154
  break
135
155
  default:
@@ -149,6 +169,15 @@ export const tokenizeLine = (line, lineState) => {
149
169
  } else if ((next = part.match(RE_NUMERIC))) {
150
170
  token = TokenType.Numeric
151
171
  state = State.TopLevelContent
172
+ } else if ((next = part.match(RE_NUMERIC_OCTAL))) {
173
+ token = TokenType.Numeric
174
+ state = State.TopLevelContent
175
+ } else if ((next = part.match(RE_TRIPLE_DOUBLE_QUOTE))) {
176
+ token = TokenType.Punctuation
177
+ state = State.InsideTripleDoubleQuoteString
178
+ } else if ((next = part.match(RE_TRIPLE_SINGLE_QUOTE))) {
179
+ token = TokenType.Punctuation
180
+ state = State.InsideTripleSingleQuoteString
152
181
  } else if ((next = part.match(RE_DOUBLE_QUOTE))) {
153
182
  token = TokenType.PunctuationString
154
183
  state = State.InsideDoubleQuoteString
@@ -158,6 +187,9 @@ export const tokenizeLine = (line, lineState) => {
158
187
  } else if ((next = part.match(RE_LINE_COMMENT))) {
159
188
  token = TokenType.Comment
160
189
  state = State.InsideLineComment
190
+ } else if ((next = part.match(RE_DECORATOR))) {
191
+ token = TokenType.VariableName
192
+ state = State.TopLevelContent
161
193
  } else if ((next = part.match(RE_TEXT))) {
162
194
  token = TokenType.Text
163
195
  state = State.TopLevelContent
@@ -173,6 +205,12 @@ export const tokenizeLine = (line, lineState) => {
173
205
  } else if ((next = part.match(RE_DOUBLE_QUOTE))) {
174
206
  token = TokenType.PunctuationString
175
207
  state = State.TopLevelContent
208
+ } else if ((next = part.match(RE_STRING_ESCAPE))) {
209
+ token = TokenType.String
210
+ state = State.InsideDoubleQuoteString
211
+ } else if ((next = part.match(RE_BACKSLASH))) {
212
+ token = TokenType.String
213
+ state = State.InsideDoubleQuoteString
176
214
  } else {
177
215
  throw new Error('no')
178
216
  }
@@ -184,6 +222,49 @@ export const tokenizeLine = (line, lineState) => {
184
222
  } else if ((next = part.match(RE_SINGLE_QUOTE))) {
185
223
  token = TokenType.PunctuationString
186
224
  state = State.TopLevelContent
225
+ } else if ((next = part.match(RE_STRING_ESCAPE))) {
226
+ token = TokenType.String
227
+ state = State.InsideSingleQuoteString
228
+ } else if ((next = part.match(RE_BACKSLASH))) {
229
+ token = TokenType.String
230
+ state = State.InsideSingleQuoteString
231
+ } else {
232
+ throw new Error('no')
233
+ }
234
+ break
235
+ case State.InsideTripleDoubleQuoteString:
236
+ if ((next = part.match(RE_TRIPLE_DOUBLE_QUOTE))) {
237
+ token = TokenType.Punctuation
238
+ state = State.TopLevelContent
239
+ } else if (
240
+ (next = part.match(RE_TRIPLE_QUOTED_STRING_CONTENT_DOUBLE_QUOTES))
241
+ ) {
242
+ token = TokenType.String
243
+ state = State.InsideTripleDoubleQuoteString
244
+ } else if (
245
+ (next = part.match(RE_TRIPLE_QUOTED_STRING_CONTENT_COMMON))
246
+ ) {
247
+ token = TokenType.String
248
+ state = State.InsideTripleDoubleQuoteString
249
+ } else {
250
+ throw new Error('no')
251
+ }
252
+ break
253
+ case State.InsideTripleSingleQuoteString:
254
+ if ((next = part.match(RE_TRIPLE_SINGLE_QUOTE))) {
255
+ token = TokenType.Punctuation
256
+ state = State.TopLevelContent
257
+ } else if (
258
+ (next = part.match(RE_TRIPLE_QUOTED_STRING_CONTENT_SINGLE_QUOTES))
259
+ ) {
260
+ token = TokenType.String
261
+ state = State.InsideTripleSingleQuoteString
262
+ } else if (
263
+ (next = part.match(RE_TRIPLE_QUOTED_STRING_CONTENT_COMMON))
264
+ ) {
265
+ next
266
+ token = TokenType.String
267
+ state = State.InsideTripleSingleQuoteString
187
268
  } else {
188
269
  throw new Error('no')
189
270
  }
@@ -209,3 +290,5 @@ export const tokenizeLine = (line, lineState) => {
209
290
  tokens,
210
291
  }
211
292
  }
293
+
294
+ tokenizeLine(`'''test'''`, initialLineState) //?
@@ -3,8 +3,12 @@
3
3
  */
4
4
  export const State = {
5
5
  TopLevelContent: 1,
6
- InsideString: 2,
6
+ InsideDoubleQuoteString: 2,
7
7
  InsideLineComment: 3,
8
+ InsideSingleQuoteString: 4,
9
+ InsideBackTickString: 5,
10
+ InsideEof: 6,
11
+ AfterKeywordFunction: 7,
8
12
  }
9
13
 
10
14
  export const StateMap = {
@@ -25,6 +29,10 @@ export const TokenType = {
25
29
  VariableName: 8,
26
30
  Comment: 885,
27
31
  Text: 9,
32
+ KeywordControl: 10,
33
+ Function: 11,
34
+ LanguageConstant: 12,
35
+ KeywordReturn: 13,
28
36
  }
29
37
 
30
38
  export const TokenMap = {
@@ -38,11 +46,15 @@ export const TokenMap = {
38
46
  [TokenType.VariableName]: 'VariableName',
39
47
  [TokenType.Comment]: 'Comment',
40
48
  [TokenType.Text]: 'Text',
49
+ [TokenType.KeywordControl]: 'KeywordControl',
50
+ [TokenType.Function]: 'Function',
51
+ [TokenType.LanguageConstant]: 'LanguageConstant',
52
+ [TokenType.KeywordReturn]: 'KeywordReturn',
41
53
  }
42
54
 
43
55
  const RE_LINE_COMMENT = /^#.*/s
44
56
  const RE_SELECTOR = /^[\.a-zA-Z\d\-\:>]+/
45
- const RE_WHITESPACE = /^ +/
57
+ const RE_WHITESPACE = /^\s+/
46
58
  const RE_CURLY_OPEN = /^\{/
47
59
  const RE_CURLY_CLOSE = /^\}/
48
60
  const RE_PROPERTY_NAME = /^[a-zA-Z\-]+\b/
@@ -50,20 +62,31 @@ const RE_COLON = /^:/
50
62
  const RE_PROPERTY_VALUE = /^[^;\}]+/
51
63
  const RE_SEMICOLON = /^;/
52
64
  const RE_COMMA = /^,/
65
+ const RE_ANYTHING_SHORT = /^[^\s"']+/
53
66
  const RE_ANYTHING = /^.+/s
54
67
  const RE_ANYTHING_UNTIL_CLOSE_BRACE = /^[^\}]+/
55
68
  const RE_QUOTE_DOUBLE = /^"/
56
- const RE_STRING_DOUBLE_QUOTE_CONTENT = /^[^"]+/
69
+ const RE_QUOTE_SINGLE = /^'/
70
+ const RE_QUOTE_BACKTICK = /^`/
71
+ const RE_STRING_DOUBLE_QUOTE_CONTENT = /^[^"\\]+/
72
+ const RE_STRING_SINGLE_QUOTE_CONTENT = /^[^']+/
73
+ const RE_STRING_BACKTICK_QUOTE_CONTENT = /^[^`]+/
57
74
  const RE_KEYWORD =
58
- /^(?:alias|bg|bind|break|builtin|caller|cd|command|compgen|complete|dirs|disown|echo|enable|eval|exec|exit|false|fc|fg|getopts|hash|help|history|jobs|kill|let|logout|popd|printf|pushd|pwd|read|readonly|set|shift|shopt|source|suspend|test|times|trap|true|type|ulimit|umask|unalias|unset|wait)\b/
59
-
60
- const RE_VARIABLE_NAME = /^[a-zA-Z\_\/\-]+/
61
- const RE_PUNCTUATION = /^[:,;\{\}\[\]\.=\(\)<>]/
62
- const RE_NUMERIC = /^\d+/
75
+ /^(?:7za|7zr|alias|ar|awk|bg|bind|break|builtin|bunzip|bunzip2|caller|cargo|case|cat|catdoc|cd|chmod|chown|command|compgen|complete|continue|cp|curl|cygstart|dde-open|dirs|disown|do|done|done|dpkg|echo|elif|else|emulate|enable|enlightenment_open|esac|eval|eval_gettext|exec|exit|expr|false|fc|fg|fi|for|function|gdbus|getopts|gio|gnome-open|grep|grub-mount|gvfs-open|gzip|hash|head|help|history|identity|if|in|ip|jobs|kde-open|kfmclient|kill|less|let|lha|logout|ls|ls|lunzip|lzip|lzma|miniunz|miniunzip|mkdir|mktemp|mv|node|npm|open|pcmanfm|pdftotext|popd|prezip-bin|printf|ps|pushd|pwd|rar|read|readlink|readonly|return|rm|rpm|sed|set|shift|shopt|sleep|snap|sort|source|stty|suspend|tail|tar|tee|test|texi2dvi|then|times|touch|trap|true|tty|type|ulimit|umask|umask|unalias|unarj|unmkinitramfs|unrar|unset|unwrapdiff|unzip|unzoo|wait|which|while|xprop|xz|zoo|zstd)\b/
76
+ const RE_VARIABLE_NAME = /^[a-zA-Z\_\/\-\$][a-zA-Z\_\/\-\$#\d\-]*/
77
+ const RE_PUNCTUATION = /^[:,;\{\}\[\]\.=\(\)<>\!\|\+\&\>\)]/
78
+ const RE_NUMERIC = /^\d+(?=\s|$)/
79
+ const RE_FUNCTION_NAME = /^\w+(?=\s*\()/
80
+ const RE_EOF_START = /^<<\s*([\w\!]+)/
81
+ const RE_EOF_CONTENT = /.*/s
82
+ const RE_STRING_ESCAPE = /^\\./
83
+ const RE_BACKSLASH_AT_END = /^\\$/
63
84
 
64
85
  export const initialLineState = {
65
86
  state: State.TopLevelContent,
66
87
  tokens: [],
88
+ knownFunctionNames: new Set(),
89
+ stringEnd: '',
67
90
  }
68
91
 
69
92
  /**
@@ -88,6 +111,8 @@ export const tokenizeLine = (line, lineState) => {
88
111
  let tokens = []
89
112
  let token = TokenType.None
90
113
  let state = lineState.state
114
+ let stringEnd = lineState.stringEnd
115
+ const knownFunctionNames = new Set(lineState.knownFunctionNames)
91
116
  while (index < line.length) {
92
117
  const part = line.slice(index)
93
118
  switch (state) {
@@ -96,23 +121,200 @@ export const tokenizeLine = (line, lineState) => {
96
121
  token = TokenType.Whitespace
97
122
  state = State.TopLevelContent
98
123
  } else if ((next = part.match(RE_KEYWORD))) {
99
- token = TokenType.Keyword
100
124
  state = State.TopLevelContent
125
+ switch (next[0]) {
126
+ case 'break':
127
+ case 'case':
128
+ case 'continue':
129
+ case 'do':
130
+ case 'done':
131
+ case 'elif':
132
+ case 'else':
133
+ case 'esac':
134
+ case 'fi':
135
+ case 'for':
136
+ case 'if':
137
+ case 'in':
138
+ case 'then':
139
+ case 'while':
140
+ token = TokenType.KeywordControl
141
+ break
142
+ case '7za':
143
+ case '7za':
144
+ case '7zr':
145
+ case 'alias':
146
+ case 'ar':
147
+ case 'awk':
148
+ case 'bg':
149
+ case 'bind':
150
+ case 'builtin':
151
+ case 'bunzip':
152
+ case 'bunzip2':
153
+ case 'caller':
154
+ case 'cargo':
155
+ case 'cat':
156
+ case 'catdoc':
157
+ case 'cd':
158
+ case 'chmod':
159
+ case 'chown':
160
+ case 'command':
161
+ case 'compgen':
162
+ case 'complete':
163
+ case 'cp':
164
+ case 'curl':
165
+ case 'dirs':
166
+ case 'disown':
167
+ case 'dpkg':
168
+ case 'echo':
169
+ case 'emulate':
170
+ case 'enable':
171
+ case 'eval':
172
+ case 'eval_gettext':
173
+ case 'exec':
174
+ case 'exit':
175
+ case 'fc':
176
+ case 'fg':
177
+ case 'getopts':
178
+ case 'grep':
179
+ case 'grub-mount':
180
+ case 'gzip':
181
+ case 'hash':
182
+ case 'head':
183
+ case 'help':
184
+ case 'history':
185
+ case 'identity':
186
+ case 'jobs':
187
+ case 'kill':
188
+ case 'less':
189
+ case 'lha':
190
+ case 'logout':
191
+ case 'ls':
192
+ case 'lunzip':
193
+ case 'lzip':
194
+ case 'lzma':
195
+ case 'miniunz':
196
+ case 'miniunzip':
197
+ case 'mkdir':
198
+ case 'mktemp':
199
+ case 'mv':
200
+ case 'node':
201
+ case 'npm':
202
+ case 'pdftotext':
203
+ case 'popd':
204
+ case 'printf':
205
+ case 'ps':
206
+ case 'pushd':
207
+ case 'pwd':
208
+ case 'rar':
209
+ case 'read':
210
+ case 'rm':
211
+ case 'rpm':
212
+ case 'sed':
213
+ case 'set':
214
+ case 'shift':
215
+ case 'shopt':
216
+ case 'sleep':
217
+ case 'snap':
218
+ case 'source':
219
+ case 'stty':
220
+ case 'suspend':
221
+ case 'tar':
222
+ case 'tee':
223
+ case 'test':
224
+ case 'times':
225
+ case 'trap':
226
+ case 'type':
227
+ case 'ulimit':
228
+ case 'umask':
229
+ case 'umask':
230
+ case 'unalias':
231
+ case 'unarj':
232
+ case 'unmkinitramfs':
233
+ case 'unrar':
234
+ case 'unset':
235
+ case 'unwrapdiff':
236
+ case 'unzip':
237
+ case 'unzoo':
238
+ case 'wait':
239
+ case 'which':
240
+ case 'xz':
241
+ case 'zoo':
242
+ case 'zstd':
243
+ case 'expr':
244
+ case 'tty':
245
+ case 'sort':
246
+ case 'ls':
247
+ case 'readlink':
248
+ case 'gio':
249
+ case 'gvfs-open':
250
+ case 'gnome-open':
251
+ case 'xprop':
252
+ case 'cygstart':
253
+ case 'open':
254
+ case 'kde-open':
255
+ case 'kfmclient':
256
+ case 'dde-open':
257
+ case 'enlightenment_open':
258
+ case 'gdbus':
259
+ case 'pcmanfm':
260
+ case 'texi2dvi':
261
+ case 'tail':
262
+ case 'touch':
263
+ case 'prezip-bin':
264
+ case 'ip':
265
+ token = TokenType.Function
266
+ break
267
+ case 'true':
268
+ case 'false':
269
+ token = TokenType.LanguageConstant
270
+ break
271
+ case 'return':
272
+ token = TokenType.KeywordReturn
273
+ break
274
+ case 'function':
275
+ token = TokenType.Keyword
276
+ state = State.AfterKeywordFunction
277
+ break
278
+ default:
279
+ token = TokenType.Keyword
280
+ break
281
+ }
282
+ } else if ((next = part.match(RE_EOF_START))) {
283
+ token = TokenType.Punctuation
284
+ state = State.InsideEof
285
+ stringEnd = next[1]
101
286
  } else if ((next = part.match(RE_PUNCTUATION))) {
102
287
  token = TokenType.Punctuation
103
288
  state = State.TopLevelContent
289
+ } else if ((next = part.match(RE_FUNCTION_NAME))) {
290
+ token = TokenType.Function
291
+ state = State.TopLevelContent
292
+ knownFunctionNames.add(next[0])
104
293
  } else if ((next = part.match(RE_VARIABLE_NAME))) {
105
- token = TokenType.VariableName
294
+ if (knownFunctionNames.has(next[0])) {
295
+ token = TokenType.Function
296
+ } else {
297
+ token = TokenType.VariableName
298
+ }
106
299
  state = State.TopLevelContent
107
300
  } else if ((next = part.match(RE_NUMERIC))) {
108
301
  token = TokenType.Numeric
109
302
  state = State.TopLevelContent
110
303
  } else if ((next = part.match(RE_QUOTE_DOUBLE))) {
111
304
  token = TokenType.PunctuationString
112
- state = State.InsideString
305
+ state = State.InsideDoubleQuoteString
306
+ } else if ((next = part.match(RE_QUOTE_SINGLE))) {
307
+ token = TokenType.Punctuation
308
+ state = State.InsideSingleQuoteString
309
+ } else if ((next = part.match(RE_QUOTE_BACKTICK))) {
310
+ token = TokenType.Punctuation
311
+ state = State.InsideBackTickString
113
312
  } else if ((next = part.match(RE_LINE_COMMENT))) {
114
313
  token = TokenType.Comment
115
314
  state = State.TopLevelContent
315
+ } else if ((next = part.match(RE_ANYTHING_SHORT))) {
316
+ token = TokenType.VariableName
317
+ state = State.TopLevelContent
116
318
  } else if ((next = part.match(RE_ANYTHING))) {
117
319
  token = TokenType.Text
118
320
  state = State.TopLevelContent
@@ -121,13 +323,70 @@ export const tokenizeLine = (line, lineState) => {
121
323
  throw new Error('no')
122
324
  }
123
325
  break
124
- case State.InsideString:
326
+ case State.InsideDoubleQuoteString:
125
327
  if ((next = part.match(RE_QUOTE_DOUBLE))) {
126
328
  token = TokenType.PunctuationString
127
329
  state = State.TopLevelContent
128
330
  } else if ((next = part.match(RE_STRING_DOUBLE_QUOTE_CONTENT))) {
129
331
  token = TokenType.String
130
- state = State.InsideString
332
+ state = State.InsideDoubleQuoteString
333
+ } else if ((next = part.match(RE_STRING_ESCAPE))) {
334
+ token = TokenType.String
335
+ state = State.InsideDoubleQuoteString
336
+ } else if ((next = part.match(RE_BACKSLASH_AT_END))) {
337
+ token = TokenType.String
338
+ state = State.InsideDoubleQuoteString
339
+ } else {
340
+ throw new Error('no')
341
+ }
342
+ break
343
+ case State.InsideSingleQuoteString:
344
+ if ((next = part.match(RE_QUOTE_SINGLE))) {
345
+ token = TokenType.PunctuationString
346
+ state = State.TopLevelContent
347
+ } else if ((next = part.match(RE_STRING_SINGLE_QUOTE_CONTENT))) {
348
+ token = TokenType.String
349
+ state = State.InsideSingleQuoteString
350
+ } else if ((next = part.match(RE_BACKSLASH_AT_END))) {
351
+ token = TokenType.String
352
+ state = State.InsideSingleQuoteString
353
+ } else {
354
+ throw new Error('no')
355
+ }
356
+ break
357
+ case State.InsideBackTickString:
358
+ if ((next = part.match(RE_QUOTE_BACKTICK))) {
359
+ token = TokenType.PunctuationString
360
+ state = State.TopLevelContent
361
+ } else if ((next = part.match(RE_STRING_BACKTICK_QUOTE_CONTENT))) {
362
+ token = TokenType.String
363
+ state = State.InsideBackTickString
364
+ } else {
365
+ throw new Error('no')
366
+ }
367
+ break
368
+ case State.InsideEof:
369
+ if ((next = part.match(stringEnd))) {
370
+ token = TokenType.Punctuation
371
+ state = State.TopLevelContent
372
+ } else if ((next = part.match(RE_EOF_CONTENT))) {
373
+ token = TokenType.String
374
+ state = State.InsideEof
375
+ } else {
376
+ throw new Error('no')
377
+ }
378
+ break
379
+ case State.AfterKeywordFunction:
380
+ if ((next = part.match(RE_VARIABLE_NAME))) {
381
+ token = TokenType.Function
382
+ state = State.TopLevelContent
383
+ knownFunctionNames.add(next[0])
384
+ } else if ((next = part.match(RE_WHITESPACE))) {
385
+ token = TokenType.Whitespace
386
+ state = State.AfterKeywordFunction
387
+ } else if ((next = part.match(RE_ANYTHING))) {
388
+ token = TokenType.Text
389
+ state = State.TopLevelContent
131
390
  } else {
132
391
  throw new Error('no')
133
392
  }
@@ -142,5 +401,7 @@ export const tokenizeLine = (line, lineState) => {
142
401
  return {
143
402
  state,
144
403
  tokens,
404
+ knownFunctionNames,
405
+ stringEnd,
145
406
  }
146
407
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/shared-process",
3
- "version": "0.11.8",
3
+ "version": "0.11.9",
4
4
  "description": "Utility package for @lvce-editor/server",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -17,9 +17,9 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@babel/code-frame": "^7.18.6",
20
- "@lvce-editor/extension-host": "0.11.8",
21
- "@lvce-editor/extension-host-helper-process": "0.11.8",
22
- "@lvce-editor/pty-host": "0.11.8",
20
+ "@lvce-editor/extension-host": "0.11.9",
21
+ "@lvce-editor/extension-host-helper-process": "0.11.9",
22
+ "@lvce-editor/pty-host": "0.11.9",
23
23
  "debug": "^4.3.4",
24
24
  "execa": "^6.1.0",
25
25
  "exit-hook": "^3.1.4",
@@ -1,23 +1,13 @@
1
- export const ENOENT = 'ENOENT'
2
-
3
- export const EXDEV = 'EXDEV'
4
-
5
- export const EEXIST = 'EEXIST'
6
-
7
- export const ENOTDIR = 'ENOTDIR'
8
-
9
- export const E_MANIFEST_NOT_FOUND = 'E_MANIFEST_NOT_FOUND'
10
-
11
- export const EPIPE = 'EPIPE'
12
-
13
- export const ERR_IPC_CHANNEL_CLOSED = 'ERR_IPC_CHANNEL_CLOSED'
14
-
15
1
  export const E_COLOR_THEME_NOT_FOUND = 'E_COLOR_THEME_NOT_FOUND'
16
-
17
2
  export const E_ICON_THEME_NOT_FOUND = 'E_ICON_THEME_NOT_FOUND'
18
-
3
+ export const E_MANIFEST_NOT_FOUND = 'E_MANIFEST_NOT_FOUND'
19
4
  export const ECONNRESET = 'ECONNRESET'
20
-
5
+ export const EEXIST = 'EEXIST'
6
+ export const ELOOP = 'ELOOP'
7
+ export const ENOENT = 'ENOENT'
8
+ export const ENOTDIR = 'ENOTDIR'
21
9
  export const EPERM = 'EPERM'
22
-
10
+ export const EPIPE = 'EPIPE'
11
+ export const ERR_IPC_CHANNEL_CLOSED = 'ERR_IPC_CHANNEL_CLOSED'
23
12
  export const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND'
13
+ export const EXDEV = 'EXDEV'