@lvce-editor/shared-process 0.11.7 → 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.
Files changed (31) hide show
  1. package/config/defaultKeyBindings.json +4 -0
  2. package/config/defaultSettings.json +2 -0
  3. package/extensions/builtin.language-basics-cpp/src/tokenizeCpp.js +29 -6
  4. package/extensions/builtin.language-basics-css/src/tokenizeCss.js +176 -25
  5. package/extensions/builtin.language-basics-gn/README.md +14 -0
  6. package/extensions/builtin.language-basics-gn/extension.json +12 -0
  7. package/extensions/builtin.language-basics-gn/src/tokenizeGn.js +178 -0
  8. package/extensions/builtin.language-basics-javascript/src/tokenizeJavaScript.js +5 -0
  9. package/extensions/builtin.language-basics-json5/README.md +16 -0
  10. package/extensions/builtin.language-basics-json5/extension.json +12 -0
  11. package/extensions/builtin.language-basics-json5/src/tokenizeJson5.js +321 -0
  12. package/extensions/builtin.language-basics-perl/extension.json +2 -1
  13. package/extensions/builtin.language-basics-perl/src/tokenizePerl.js +53 -6
  14. package/extensions/builtin.language-basics-python/extension.json +2 -1
  15. package/extensions/builtin.language-basics-python/src/tokenizePython.js +129 -36
  16. package/extensions/builtin.language-basics-shellscript/src/tokenizeShellScript.js +274 -13
  17. package/extensions/builtin.language-basics-typescript/src/tokenizeTypeScript.js +197 -15
  18. package/extensions/builtin.theme-ayu/color-theme.json +2 -0
  19. package/extensions/builtin.theme-slime/color-theme.json +6 -0
  20. package/package.json +4 -4
  21. package/src/parts/Command/Command.js +38 -40
  22. package/src/parts/ErrorCodes/ErrorCodes.js +9 -17
  23. package/src/parts/GetResponse/GetResponse.js +2 -2
  24. package/src/parts/Module/Module.js +2 -2
  25. package/src/parts/ModuleMap/ModuleMap.js +1 -1
  26. package/src/parts/PrettyError/PrettyError.js +55 -5
  27. package/src/parts/RipGrep/RipGrep.js +30 -0
  28. package/src/parts/SearchFile/SearchFile.js +12 -16
  29. package/src/parts/TextSearch/TextSearch.ipc.js +7 -0
  30. package/src/parts/{Search/Search.js → TextSearch/TextSearch.js} +11 -17
  31. package/src/parts/Search/Search.ipc.js +0 -7
@@ -746,5 +746,9 @@
746
746
  {
747
747
  "key": "ctrl+r",
748
748
  "command": "Window.reload"
749
+ },
750
+ {
751
+ "key": "ctrl+\\",
752
+ "command": "Run And Debug.togglePause"
749
753
  }
750
754
  ]
@@ -18,6 +18,8 @@
18
18
  "Thumbs.db": true
19
19
  },
20
20
 
21
+ "search.threads": 1,
22
+
21
23
  "sessionReplay.enabled": false,
22
24
 
23
25
  "serviceWorker.enabled": false,
@@ -9,6 +9,7 @@ export const State = {
9
9
  AfterIncludeAfterWhitespace: 5,
10
10
  AfterMacroError: 6,
11
11
  AfterMacroErrorAfterWhitespace: 7,
12
+ InsideBlockComment: 8,
12
13
  }
13
14
 
14
15
  /**
@@ -64,7 +65,8 @@ const RE_NUMERIC =
64
65
  /^((0(x|X)[0-9a-fA-F]*)|(([0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)/
65
66
  const RE_NEWLINE_WHITESPACE = /^\n\s*/
66
67
  const RE_BLOCK_COMMENT_START = /^\/\*/
67
- const RE_BLOCK_COMMENT_CONTENT = /^.+(?=\*\/|$)/s
68
+ const RE_BLOCK_COMMENT_CONTENT_1 = /^.+(?=\*\/)/s
69
+ const RE_BLOCK_COMMENT_CONTENT_2 = /^.+(?=$)/s
68
70
  const RE_BLOCK_COMMENT_END = /^\*\//
69
71
  const RE_UNKNOWN_VALUE = /^[^\}\{\s,"]+/
70
72
  const RE_IMPORT = /^[a-zA-Z\.]+/
@@ -98,6 +100,9 @@ export const initialLineState = {
98
100
  state: State.TopLevelContent,
99
101
  }
100
102
 
103
+ export const hasArrayReturn = true
104
+
105
+ // @ts-ignore
101
106
  export const isLineStateEqual = (lineStateA, lineStateB) => {
102
107
  return lineStateA.state === lineStateB.state
103
108
  }
@@ -150,6 +155,9 @@ export const tokenizeLine = (line, lineState) => {
150
155
  } else if ((next = part.match(RE_LINE_COMMENT))) {
151
156
  token = TokenType.Comment
152
157
  state = State.InsideLineComment
158
+ } else if ((next = part.match(RE_BLOCK_COMMENT_START))) {
159
+ token = TokenType.Comment
160
+ state = State.InsideBlockComment
153
161
  } else if ((next = part.match(RE_PUNCTUATION))) {
154
162
  token = TokenType.Punctuation
155
163
  state = State.TopLevelContent
@@ -205,15 +213,30 @@ export const tokenizeLine = (line, lineState) => {
205
213
  throw new Error('no')
206
214
  }
207
215
  break
216
+ case State.InsideBlockComment:
217
+ if ((next = part.match(RE_BLOCK_COMMENT_END))) {
218
+ token = TokenType.Comment
219
+ state = State.TopLevelContent
220
+ } else if ((next = part.match(RE_BLOCK_COMMENT_CONTENT_1))) {
221
+ token = TokenType.Comment
222
+ state = State.InsideBlockComment
223
+ } else if ((next = part.match(RE_BLOCK_COMMENT_CONTENT_2))) {
224
+ token = TokenType.Comment
225
+ state = State.InsideBlockComment
226
+ } else if ((next = part.match(RE_ANYTHING_UNTIL_END))) {
227
+ token = TokenType.Comment
228
+ state = State.InsideBlockComment
229
+ } else {
230
+ throw new Error('no')
231
+ }
232
+ break
208
233
  default:
209
234
  state
210
235
  throw new Error('no')
211
236
  }
212
- index += next[0].length
213
- tokens.push({
214
- type: token,
215
- length: next[0].length,
216
- })
237
+ const tokenLength = next[0].length
238
+ index += tokenLength
239
+ tokens.push(token, tokenLength)
217
240
  }
218
241
  return {
219
242
  state,
@@ -7,7 +7,6 @@ export const State = {
7
7
  InsideSelector: 3,
8
8
  AfterPropertyName: 4,
9
9
  AfterPropertyNameAfterColon: 5,
10
- AfterPropertyValue: 6,
11
10
  InsideBlockComment: 7,
12
11
  InsidePseudoSelector: 8,
13
12
  InsideAttributeSelector: 9,
@@ -15,6 +14,11 @@ export const State = {
15
14
  InsideRound: 11,
16
15
  AfterQueryWithRules: 12,
17
16
  InsideRule: 13,
17
+ AfterFunctionName: 14,
18
+ InsideDoubleQuoteString: 15,
19
+ InsideSingleQuoteString: 16,
20
+ AfterFunctionNameInsideArguments: 17,
21
+ AfterKeywordImport: 18,
18
22
  }
19
23
 
20
24
  export const StateMap = {
@@ -23,7 +27,6 @@ export const StateMap = {
23
27
  [State.InsideSelector]: 'InsideSelector',
24
28
  [State.AfterPropertyName]: 'AfterPropertyName',
25
29
  [State.AfterPropertyNameAfterColon]: 'AfterPropertyNameAfterColon',
26
- [State.AfterPropertyValue]: 'AfterPropertyValue',
27
30
  }
28
31
 
29
32
  /**
@@ -49,6 +52,9 @@ export const TokenType = {
49
52
  Query: 886,
50
53
  Text: 887,
51
54
  CssSelectorId: 889,
55
+ FuntionName: 890,
56
+ String: 891,
57
+ KeywordImport: 892,
52
58
  }
53
59
 
54
60
  export const TokenMap = {
@@ -72,20 +78,25 @@ export const TokenMap = {
72
78
  [TokenType.Query]: 'CssAtRule',
73
79
  [TokenType.Text]: 'Text',
74
80
  [TokenType.CssSelectorId]: 'CssSelectorId',
81
+ [TokenType.FuntionName]: 'Function',
82
+ [TokenType.String]: 'String',
83
+ [TokenType.KeywordImport]: 'KeywordImport',
75
84
  }
76
85
 
77
- const RE_SELECTOR = /^[\.a-zA-Z\d\-\:>\+\~\_%]+/
86
+ const RE_SELECTOR = /^[\.a-zA-Z\d\-\:>\+\~\_%\\]+/
78
87
  const RE_SELECTOR_ID = /^#[\w\-\_]+/
79
88
  const RE_WHITESPACE = /^\s+/
80
89
  const RE_CURLY_OPEN = /^\{/
81
90
  const RE_CURLY_CLOSE = /^\}/
82
- const RE_PROPERTY_NAME = /^[a-zA-Z\-]+\b/
91
+ const RE_PROPERTY_NAME = /^[a-zA-Z\-\w]+\b/
83
92
  const RE_COLON = /^:/
84
93
  const RE_PROPERTY_VALUE = /^[^;\}]+/
94
+ const RE_PROPERTY_VALUE_SHORT = /^[^;\}\s\)]+/
95
+ const RE_PROPERTY_VALUE_INSIDE_FUNCTION = /^[^\}\s\)]+/
85
96
  const RE_SEMICOLON = /^;/
86
97
  const RE_COMMA = /^,/
87
98
  const RE_ANYTHING = /^.+/s
88
- const RE_NUMERIC = /^(([0-9]+\.?[0-9]*)|(\.[0-9]+))/
99
+ const RE_NUMERIC = /^\-?(([0-9]+\.?[0-9]*)|(\.[0-9]+))/
89
100
  const RE_ANYTHING_UNTIL_CLOSE_BRACE = /^[^\}]+/
90
101
  const RE_BLOCK_COMMENT_START = /^\/\*/
91
102
  const RE_BLOCK_COMMENT_END = /^\*\//
@@ -98,9 +109,17 @@ const RE_SQUARE_CLOSE = /^\]/
98
109
  const RE_ATTRIBUTE_SELECTOR_CONTENT = /^[^\]]+/
99
110
  const RE_QUERY = /^@[a-z\-]+/
100
111
  const RE_STAR = /^\*/
101
- const RE_QUERY_NAME = /^[a-z\-]+/
112
+ const RE_QUERY_NAME = /^[a-zA-Z\w\-\d\_]+/
102
113
  const RE_QUERY_CONTENT = /^[^\)]+/
103
114
  const RE_COMBINATOR = /^[\+\>\~]/
115
+ const RE_FUNCTION = /^[a-zA-Z][a-zA-Z\-]+(?=\()/
116
+ const RE_VARIABLE_NAME = /^\-\-[a-zA-Z\w\-\_]+/
117
+ const RE_PERCENT = /^\%/
118
+ const RE_OPERATOR = /^[\-\/\*\+]/
119
+ const RE_DOUBLE_QUOTE = /^"/
120
+ const RE_STRING_DOUBLE_QUOTE_CONTENT = /^[^"]+/
121
+ const RE_STRING_SINGLE_QUOTE_CONTENT = /^[^']+/
122
+ const RE_SINGLE_QUOTE = /^'/
104
123
 
105
124
  export const initialLineState = {
106
125
  state: State.TopLevelContent,
@@ -160,6 +179,10 @@ export const tokenizeLine = (line, lineState) => {
160
179
  token = TokenType.Query
161
180
  state = State.AfterQueryWithRules
162
181
  break
182
+ case '@import':
183
+ token = TokenType.KeywordImport
184
+ state = State.AfterKeywordImport
185
+ break
163
186
  case '@keyframes':
164
187
  default:
165
188
  token = TokenType.Query
@@ -172,6 +195,9 @@ export const tokenizeLine = (line, lineState) => {
172
195
  } else if ((next = part.match(RE_CURLY_CLOSE))) {
173
196
  token = TokenType.Punctuation
174
197
  state = State.TopLevelContent
198
+ } else if ((next = part.match(RE_SEMICOLON))) {
199
+ token = TokenType.Punctuation
200
+ state = State.TopLevelContent
175
201
  } else if ((next = part.match(RE_ANYTHING))) {
176
202
  token = TokenType.Unknown
177
203
  state = State.TopLevelContent
@@ -202,6 +228,9 @@ export const tokenizeLine = (line, lineState) => {
202
228
  } else if ((next = part.match(RE_SQUARE_OPEN))) {
203
229
  token = TokenType.Punctuation
204
230
  state = State.InsideAttributeSelector
231
+ } else if ((next = part.match(RE_STAR))) {
232
+ token = TokenType.CssSelector
233
+ state = State.AfterSelector
205
234
  } else if ((next = part.match(RE_ANYTHING))) {
206
235
  token = TokenType.Unknown
207
236
  state = State.TopLevelContent
@@ -225,6 +254,9 @@ export const tokenizeLine = (line, lineState) => {
225
254
  token = TokenType.Punctuation
226
255
  state = State.InsideRound
227
256
  stack.push(State.AfterQuery)
257
+ } else if ((next = part.match(RE_COMMA))) {
258
+ token = TokenType.Punctuation
259
+ state = State.AfterQuery
228
260
  } else {
229
261
  part
230
262
  throw new Error('no')
@@ -302,35 +334,27 @@ export const tokenizeLine = (line, lineState) => {
302
334
  state = State.AfterPropertyNameAfterColon
303
335
  } else if ((next = part.match(RE_NUMERIC))) {
304
336
  token = TokenType.Numeric
305
- state = State.AfterPropertyValue
306
- } else if ((next = part.match(RE_PROPERTY_VALUE))) {
337
+ state = State.AfterPropertyNameAfterColon
338
+ } else if ((next = part.match(RE_FUNCTION))) {
339
+ token = TokenType.FuntionName
340
+ state = State.AfterFunctionName
341
+ } else if ((next = part.match(RE_FUNCTION))) {
342
+ token = TokenType.FuntionName
343
+ state = State.AfterFunctionName
344
+ } else if ((next = part.match(RE_PROPERTY_VALUE_SHORT))) {
307
345
  token = TokenType.CssPropertyValue
308
- state = State.AfterPropertyValue
346
+ state = State.AfterPropertyNameAfterColon
309
347
  } else if ((next = part.match(RE_SEMICOLON))) {
310
348
  token = TokenType.Punctuation
311
349
  state = State.InsideSelector
312
- } else {
313
- throw new Error('no')
314
- }
315
- break
316
- case State.AfterPropertyValue:
317
- if ((next = part.match(RE_SEMICOLON))) {
318
- token = TokenType.CssPropertySemicolon
319
- state = State.InsideSelector
320
- } else if ((next = part.match(RE_WHITESPACE))) {
321
- token = TokenType.Whitespace
322
- state = State.AfterPropertyValue
323
- } else if ((next = part.match(RE_NUMERIC))) {
324
- token = TokenType.Numeric
325
- state = State.AfterPropertyValue
326
350
  } else if ((next = part.match(RE_PROPERTY_VALUE))) {
327
351
  token = TokenType.CssPropertyValue
328
- state = State.AfterPropertyValue
352
+ state = State.AfterPropertyNameAfterColon
329
353
  } else if ((next = part.match(RE_CURLY_CLOSE))) {
330
354
  token = TokenType.Punctuation
331
355
  state = State.TopLevelContent
332
356
  } else {
333
- part //?
357
+ part
334
358
  throw new Error('no')
335
359
  }
336
360
  break
@@ -367,6 +391,133 @@ export const tokenizeLine = (line, lineState) => {
367
391
  throw new Error('no')
368
392
  }
369
393
  break
394
+ case State.AfterFunctionName:
395
+ if ((next = part.match(RE_ROUND_OPEN))) {
396
+ token = TokenType.Punctuation
397
+ state = State.AfterFunctionNameInsideArguments
398
+ } else if ((next = part.match(RE_NUMERIC))) {
399
+ token = TokenType.Numeric
400
+ state = State.AfterFunctionName
401
+ } else if ((next = part.match(RE_WHITESPACE))) {
402
+ token = TokenType.Whitespace
403
+ state = State.AfterFunctionName
404
+ } else if ((next = part.match(RE_ROUND_CLOSE))) {
405
+ token = TokenType.Punctuation
406
+ state = State.AfterFunctionName
407
+ } else if ((next = part.match(RE_SEMICOLON))) {
408
+ token = TokenType.Punctuation
409
+ state = State.InsideSelector
410
+ } else if ((next = part.match(RE_COMMA))) {
411
+ token = TokenType.Punctuation
412
+ state = State.AfterFunctionName
413
+ } else if ((next = part.match(RE_FUNCTION))) {
414
+ token = TokenType.FuntionName
415
+ state = State.AfterFunctionName
416
+ } else if ((next = part.match(RE_VARIABLE_NAME))) {
417
+ token = TokenType.Variable
418
+ state = State.AfterFunctionName
419
+ } else if ((next = part.match(RE_PERCENT))) {
420
+ token = TokenType.CssPropertyValue
421
+ state = State.AfterFunctionName
422
+ } else if ((next = part.match(RE_DOUBLE_QUOTE))) {
423
+ token = TokenType.Punctuation
424
+ state = State.InsideDoubleQuoteString
425
+ stack.push(State.AfterFunctionName)
426
+ } else if ((next = part.match(RE_SINGLE_QUOTE))) {
427
+ token = TokenType.Punctuation
428
+ state = State.InsideSingleQuoteString
429
+ stack.push(State.AfterFunctionName)
430
+ } else if ((next = part.match(RE_PROPERTY_VALUE_SHORT))) {
431
+ token = TokenType.CssPropertyValue
432
+ state = State.AfterFunctionName
433
+ } else if ((next = part.match(RE_CURLY_CLOSE))) {
434
+ token = TokenType.Punctuation
435
+ state = State.TopLevelContent
436
+ } else {
437
+ part
438
+ throw new Error('no')
439
+ }
440
+ break
441
+ case State.AfterFunctionNameInsideArguments:
442
+ if ((next = part.match(RE_ROUND_OPEN))) {
443
+ token = TokenType.Punctuation
444
+ state = State.AfterFunctionName
445
+ } else if ((next = part.match(RE_NUMERIC))) {
446
+ token = TokenType.Numeric
447
+ state = State.AfterFunctionName
448
+ } else if ((next = part.match(RE_WHITESPACE))) {
449
+ token = TokenType.Whitespace
450
+ state = State.AfterFunctionName
451
+ } else if ((next = part.match(RE_ROUND_CLOSE))) {
452
+ token = TokenType.Punctuation
453
+ state = State.AfterFunctionNameInsideArguments
454
+ } else if ((next = part.match(RE_SEMICOLON))) {
455
+ token = TokenType.Punctuation
456
+ state = State.InsideSelector
457
+ } else if ((next = part.match(RE_COMMA))) {
458
+ token = TokenType.Punctuation
459
+ state = State.AfterFunctionName
460
+ } else if ((next = part.match(RE_FUNCTION))) {
461
+ token = TokenType.FuntionName
462
+ state = State.AfterFunctionName
463
+ } else if ((next = part.match(RE_VARIABLE_NAME))) {
464
+ token = TokenType.Variable
465
+ state = State.AfterFunctionName
466
+ } else if ((next = part.match(RE_PERCENT))) {
467
+ token = TokenType.CssPropertyValue
468
+ state = State.AfterFunctionName
469
+ } else if ((next = part.match(RE_DOUBLE_QUOTE))) {
470
+ token = TokenType.Punctuation
471
+ state = State.InsideDoubleQuoteString
472
+ stack.push(State.AfterFunctionName)
473
+ } else if ((next = part.match(RE_SINGLE_QUOTE))) {
474
+ token = TokenType.Punctuation
475
+ state = State.InsideSingleQuoteString
476
+ stack.push(State.AfterFunctionName)
477
+ } else if ((next = part.match(RE_PROPERTY_VALUE_INSIDE_FUNCTION))) {
478
+ token = TokenType.CssPropertyValue
479
+ state = State.AfterFunctionName
480
+ } else {
481
+ part
482
+ throw new Error('no')
483
+ }
484
+ break
485
+ case State.InsideDoubleQuoteString:
486
+ if ((next = part.match(RE_DOUBLE_QUOTE))) {
487
+ token = TokenType.Punctuation
488
+ state = stack.pop() || State.TopLevelContent
489
+ } else if ((next = part.match(RE_STRING_DOUBLE_QUOTE_CONTENT))) {
490
+ token = TokenType.String
491
+ state = State.InsideDoubleQuoteString
492
+ } else {
493
+ throw new Error('no')
494
+ }
495
+ break
496
+ case State.AfterKeywordImport:
497
+ if ((next = part.match(RE_WHITESPACE))) {
498
+ token = TokenType.Whitespace
499
+ state = State.AfterKeywordImport
500
+ } else if ((next = part.match(RE_SINGLE_QUOTE))) {
501
+ token = TokenType.Punctuation
502
+ state = State.InsideSingleQuoteString
503
+ } else if ((next = part.match(RE_DOUBLE_QUOTE))) {
504
+ token = TokenType.Punctuation
505
+ state = State.InsideDoubleQuoteString
506
+ } else {
507
+ throw new Error('no')
508
+ }
509
+ break
510
+ case State.InsideSingleQuoteString:
511
+ if ((next = part.match(RE_SINGLE_QUOTE))) {
512
+ token = TokenType.Punctuation
513
+ state = stack.pop() || State.TopLevelContent
514
+ } else if ((next = part.match(RE_STRING_SINGLE_QUOTE_CONTENT))) {
515
+ token = TokenType.String
516
+ state = State.InsideSingleQuoteString
517
+ } else {
518
+ throw new Error('no')
519
+ }
520
+ break
370
521
  default:
371
522
  console.log({ state, line })
372
523
  throw new Error('no')
@@ -0,0 +1,14 @@
1
+ # Language Basics GN
2
+
3
+ ## Contributing
4
+
5
+ ```sh
6
+ git clone git@github.com:lvce-editor/language-basics-gn.git &&
7
+ cd language-basics-gn &&
8
+ npm ci &&
9
+ npm test
10
+ ```
11
+
12
+ ## Gitpod
13
+
14
+ [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/lvce-editor/language-basics-gn)
@@ -0,0 +1,12 @@
1
+ {
2
+ "id": "builtin.language-basics-gn",
3
+ "name": "Language Basics GN",
4
+ "description": "Provides syntax highlighting and bracket matching in gn files.",
5
+ "languages": [
6
+ {
7
+ "id": "gn",
8
+ "extensions": [".gn", ".gni"],
9
+ "tokenize": "src/tokenizeGn.js"
10
+ }
11
+ ]
12
+ }
@@ -0,0 +1,178 @@
1
+ /**
2
+ * @enum number
3
+ */
4
+ export const State = {
5
+ TopLevelContent: 1,
6
+ InsideString: 2,
7
+ InsideLineComment: 3,
8
+ }
9
+
10
+ export const StateMap = {
11
+ [State.TopLevelContent]: 'TopLevelContent',
12
+ }
13
+
14
+ /**
15
+ * @enum number
16
+ */
17
+ export const TokenType = {
18
+ None: 1,
19
+ Whitespace: 2,
20
+ PunctuationString: 3,
21
+ String: 4,
22
+ Keyword: 5,
23
+ Numeric: 6,
24
+ Punctuation: 7,
25
+ VariableName: 8,
26
+ Comment: 885,
27
+ Text: 9,
28
+ Function: 10,
29
+ LanguageConstant: 11,
30
+ KeywordImport: 12,
31
+ }
32
+
33
+ export const TokenMap = {
34
+ [TokenType.None]: 'None',
35
+ [TokenType.Whitespace]: 'Whitespace',
36
+ [TokenType.PunctuationString]: 'PunctuationString',
37
+ [TokenType.String]: 'String',
38
+ [TokenType.Keyword]: 'Keyword',
39
+ [TokenType.Numeric]: 'Numeric',
40
+ [TokenType.Punctuation]: 'Punctuation',
41
+ [TokenType.VariableName]: 'VariableName',
42
+ [TokenType.Comment]: 'Comment',
43
+ [TokenType.Text]: 'Text',
44
+ [TokenType.Function]: 'Function',
45
+ [TokenType.LanguageConstant]: 'LanguageConstant',
46
+ [TokenType.KeywordImport]: 'KeywordImport',
47
+ }
48
+
49
+ const RE_LINE_COMMENT = /^#.*/s
50
+ const RE_WHITESPACE = /^ +/
51
+ const RE_ANYTHING = /^.+/s
52
+ const RE_QUOTE_DOUBLE = /^"/
53
+ const RE_STRING_DOUBLE_QUOTE_CONTENT = /^[^"]+/
54
+ const RE_KEYWORD =
55
+ /^(?:if|else|true|false|assert|config|declare_args|defined|exec_script|foreach|get_label_info|get_path_info|get_target_outputs|getenv|import|print|process_file_template|propagates_configs|read_file|rebase_path|set_default_toolchain|set_defaults|set_sources_assignment_filter|template|tool|toolchain_args|toolchain|write_file)\b/
56
+ const RE_VARIABLE_NAME = /^[a-zA-Z\_\/\-]+/
57
+ const RE_PUNCTUATION = /^[:,;\{\}\[\]\.=\(\)<>\+\|\!\&]/
58
+ const RE_NUMERIC = /^\d+/
59
+
60
+ export const initialLineState = {
61
+ state: State.TopLevelContent,
62
+ tokens: [],
63
+ }
64
+
65
+ /**
66
+ *
67
+ * @param {any} lineStateA
68
+ * @param {any} lineStateB
69
+ * @returns
70
+ */
71
+ export const isEqualLineState = (lineStateA, lineStateB) => {
72
+ return lineStateA.state === lineStateB.state
73
+ }
74
+
75
+ export const hasArrayReturn = true
76
+
77
+ /**
78
+ * @param {string} line
79
+ * @param {any} lineState
80
+ */
81
+ export const tokenizeLine = (line, lineState) => {
82
+ let next = null
83
+ let index = 0
84
+ let tokens = []
85
+ let token = TokenType.None
86
+ let state = lineState.state
87
+ while (index < line.length) {
88
+ const part = line.slice(index)
89
+ switch (state) {
90
+ case State.TopLevelContent:
91
+ if ((next = part.match(RE_WHITESPACE))) {
92
+ token = TokenType.Whitespace
93
+ state = State.TopLevelContent
94
+ } else if ((next = part.match(RE_KEYWORD))) {
95
+ switch (next[0]) {
96
+ case 'true':
97
+ case 'false':
98
+ token = TokenType.LanguageConstant
99
+ break
100
+ case 'assert':
101
+ case 'config':
102
+ case 'declare_args':
103
+ case 'defined':
104
+ case 'exec_script':
105
+ case 'foreach':
106
+ case 'get_label_info':
107
+ case 'get_path_info':
108
+ case 'get_target_outputs':
109
+ case 'getenv':
110
+ case 'print':
111
+ case 'process_file_template':
112
+ case 'propagates_configs':
113
+ case 'read_file':
114
+ case 'rebase_path':
115
+ case 'set_default_toolchain':
116
+ case 'set_defaults':
117
+ case 'set_sources_assignment_filter':
118
+ case 'template':
119
+ case 'tool':
120
+ case 'toolchain_args':
121
+ case 'toolchain':
122
+ case 'write_file':
123
+ token = TokenType.Function
124
+ break
125
+ case 'import':
126
+ token = TokenType.KeywordImport
127
+ break
128
+ default:
129
+ token = TokenType.Keyword
130
+ break
131
+ }
132
+ state = State.TopLevelContent
133
+ } else if ((next = part.match(RE_PUNCTUATION))) {
134
+ token = TokenType.Punctuation
135
+ state = State.TopLevelContent
136
+ } else if ((next = part.match(RE_VARIABLE_NAME))) {
137
+ token = TokenType.VariableName
138
+ state = State.TopLevelContent
139
+ } else if ((next = part.match(RE_NUMERIC))) {
140
+ token = TokenType.Numeric
141
+ state = State.TopLevelContent
142
+ } else if ((next = part.match(RE_QUOTE_DOUBLE))) {
143
+ token = TokenType.PunctuationString
144
+ state = State.InsideString
145
+ } else if ((next = part.match(RE_LINE_COMMENT))) {
146
+ token = TokenType.Comment
147
+ state = State.TopLevelContent
148
+ } else if ((next = part.match(RE_ANYTHING))) {
149
+ token = TokenType.Text
150
+ state = State.TopLevelContent
151
+ } else {
152
+ part //?
153
+ throw new Error('no')
154
+ }
155
+ break
156
+ case State.InsideString:
157
+ if ((next = part.match(RE_QUOTE_DOUBLE))) {
158
+ token = TokenType.PunctuationString
159
+ state = State.TopLevelContent
160
+ } else if ((next = part.match(RE_STRING_DOUBLE_QUOTE_CONTENT))) {
161
+ token = TokenType.String
162
+ state = State.InsideString
163
+ } else {
164
+ throw new Error('no')
165
+ }
166
+ break
167
+ default:
168
+ throw new Error('no')
169
+ }
170
+ const tokenLength = next[0].length
171
+ index += tokenLength
172
+ tokens.push(token, tokenLength)
173
+ }
174
+ return {
175
+ state,
176
+ tokens,
177
+ }
178
+ }
@@ -169,6 +169,11 @@ export const tokenizeLine = (line, lineState) => {
169
169
  case 'if':
170
170
  case 'break':
171
171
  case 'throw':
172
+ case 'for':
173
+ case 'try':
174
+ case 'catch':
175
+ case 'finally':
176
+ case 'continue':
172
177
  token = TokenType.KeywordControl
173
178
  break
174
179
  case 'async':
@@ -0,0 +1,16 @@
1
+ # Language Basics JSON5
2
+
3
+ Provides syntax highlighting in JSON5 files.
4
+
5
+ ## Contributing
6
+
7
+ ```sh
8
+ git clone git@github.com:lvce-editor/language-basics-json5.git &&
9
+ cd language-basics-json5 &&
10
+ npm ci &&
11
+ npm test
12
+ ```
13
+
14
+ ## Gitpod
15
+
16
+ [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/lvce-editor/language-basics-json5)
@@ -0,0 +1,12 @@
1
+ {
2
+ "id": "builtin.language-basics-json5",
3
+ "name": "Language Basics JSON5",
4
+ "description": "Provides syntax highlighting and bracket matching in JSON5 files.",
5
+ "languages": [
6
+ {
7
+ "id": "json5",
8
+ "extensions": [".json5"],
9
+ "tokenize": "src/tokenizeJson5.js"
10
+ }
11
+ ]
12
+ }