@finos/legend-lego 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. package/lib/application/DocumentationLink.d.ts +27 -0
  2. package/lib/application/DocumentationLink.d.ts.map +1 -0
  3. package/lib/application/DocumentationLink.js +45 -0
  4. package/lib/application/DocumentationLink.js.map +1 -0
  5. package/lib/application/FuzzySearchAdvancedConfigMenu.d.ts +23 -0
  6. package/lib/application/FuzzySearchAdvancedConfigMenu.d.ts.map +1 -0
  7. package/lib/application/FuzzySearchAdvancedConfigMenu.js +35 -0
  8. package/lib/application/FuzzySearchAdvancedConfigMenu.js.map +1 -0
  9. package/lib/application/TabManager.d.ts +24 -0
  10. package/lib/application/TabManager.d.ts.map +1 -0
  11. package/lib/application/TabManager.js +117 -0
  12. package/lib/application/TabManager.js.map +1 -0
  13. package/lib/application/TabManagerState.d.ts +40 -0
  14. package/lib/application/TabManagerState.d.ts.map +1 -0
  15. package/lib/application/TabManagerState.js +93 -0
  16. package/lib/application/TabManagerState.js.map +1 -0
  17. package/lib/application/index.d.ts +20 -0
  18. package/lib/application/index.d.ts.map +1 -0
  19. package/lib/application/index.js +20 -0
  20. package/lib/application/index.js.map +1 -0
  21. package/lib/code-editor/CodeDiffView.d.ts +35 -0
  22. package/lib/code-editor/CodeDiffView.d.ts.map +1 -0
  23. package/lib/code-editor/CodeDiffView.js +78 -0
  24. package/lib/code-editor/CodeDiffView.js.map +1 -0
  25. package/lib/code-editor/CodeEditor.d.ts +1 -1
  26. package/lib/code-editor/CodeEditor.d.ts.map +1 -1
  27. package/lib/code-editor/CodeEditor.js +5 -3
  28. package/lib/code-editor/CodeEditor.js.map +1 -1
  29. package/lib/code-editor/CodeEditorConfig.d.ts +31 -0
  30. package/lib/code-editor/CodeEditorConfig.d.ts.map +1 -0
  31. package/lib/code-editor/CodeEditorConfig.js +33 -0
  32. package/lib/code-editor/CodeEditorConfig.js.map +1 -0
  33. package/lib/code-editor/CodeEditorUtils.d.ts +2 -0
  34. package/lib/code-editor/CodeEditorUtils.d.ts.map +1 -1
  35. package/lib/code-editor/CodeEditorUtils.js +46 -1
  36. package/lib/code-editor/CodeEditorUtils.js.map +1 -1
  37. package/lib/code-editor/PureLanguageCodeEditorSupport.d.ts +70 -0
  38. package/lib/code-editor/PureLanguageCodeEditorSupport.d.ts.map +1 -0
  39. package/lib/code-editor/PureLanguageCodeEditorSupport.js +237 -0
  40. package/lib/code-editor/PureLanguageCodeEditorSupport.js.map +1 -0
  41. package/lib/code-editor/PureLanguageService.d.ts +42 -0
  42. package/lib/code-editor/PureLanguageService.d.ts.map +1 -0
  43. package/lib/code-editor/PureLanguageService.js +437 -0
  44. package/lib/code-editor/PureLanguageService.js.map +1 -0
  45. package/lib/code-editor/__test-utils__/MockedMonacoEditor.d.ts.map +1 -0
  46. package/lib/code-editor/__test-utils__/MockedMonacoEditor.js.map +1 -0
  47. package/lib/code-editor/__test-utils__/MonacoEditorMockUtils.d.ts.map +1 -0
  48. package/lib/code-editor/{testing → __test-utils__}/MonacoEditorMockUtils.js +1 -1
  49. package/lib/code-editor/__test-utils__/MonacoEditorMockUtils.js.map +1 -0
  50. package/lib/code-editor/__test__.d.ts +17 -0
  51. package/lib/code-editor/__test__.d.ts.map +1 -0
  52. package/lib/code-editor/{testing/index.js → __test__.js} +2 -2
  53. package/lib/code-editor/__test__.js.map +1 -0
  54. package/lib/code-editor/index.d.ts +4 -0
  55. package/lib/code-editor/index.d.ts.map +1 -1
  56. package/lib/code-editor/index.js +4 -0
  57. package/lib/code-editor/index.js.map +1 -1
  58. package/lib/graph-editor/ElementIconUtils.d.ts +18 -0
  59. package/lib/graph-editor/ElementIconUtils.d.ts.map +1 -0
  60. package/lib/graph-editor/ElementIconUtils.js +37 -0
  61. package/lib/graph-editor/ElementIconUtils.js.map +1 -0
  62. package/lib/graph-editor/PackageableElementOption.d.ts +25 -0
  63. package/lib/graph-editor/PackageableElementOption.d.ts.map +1 -0
  64. package/lib/graph-editor/PackageableElementOption.js +46 -0
  65. package/lib/graph-editor/PackageableElementOption.js.map +1 -0
  66. package/lib/graph-editor/index.d.ts +18 -0
  67. package/lib/graph-editor/index.d.ts.map +1 -0
  68. package/lib/graph-editor/index.js +18 -0
  69. package/lib/graph-editor/index.js.map +1 -0
  70. package/lib/index.css +2 -2
  71. package/lib/index.css.map +1 -1
  72. package/package.json +14 -9
  73. package/src/application/DocumentationLink.tsx +82 -0
  74. package/src/application/FuzzySearchAdvancedConfigMenu.tsx +66 -0
  75. package/src/application/TabManager.tsx +285 -0
  76. package/src/application/TabManagerState.ts +124 -0
  77. package/src/application/index.ts +22 -0
  78. package/src/code-editor/CodeDiffView.tsx +128 -0
  79. package/src/code-editor/CodeEditor.tsx +8 -5
  80. package/src/code-editor/CodeEditorConfig.ts +32 -0
  81. package/src/code-editor/CodeEditorUtils.ts +76 -1
  82. package/src/code-editor/PureLanguageCodeEditorSupport.ts +338 -0
  83. package/src/code-editor/PureLanguageService.ts +501 -0
  84. package/src/code-editor/{testing → __test-utils__}/MonacoEditorMockUtils.tsx +1 -1
  85. package/src/code-editor/{testing/index.ts → __test__.ts} +1 -1
  86. package/src/code-editor/index.ts +8 -0
  87. package/src/graph-editor/ElementIconUtils.tsx +47 -0
  88. package/src/graph-editor/PackageableElementOption.tsx +86 -0
  89. package/{lib/code-editor/testing/index.d.ts → src/graph-editor/index.ts} +3 -2
  90. package/tsconfig.json +16 -4
  91. package/lib/code-editor/testing/MockedMonacoEditor.d.ts.map +0 -1
  92. package/lib/code-editor/testing/MockedMonacoEditor.js.map +0 -1
  93. package/lib/code-editor/testing/MonacoEditorMockUtils.d.ts.map +0 -1
  94. package/lib/code-editor/testing/MonacoEditorMockUtils.js.map +0 -1
  95. package/lib/code-editor/testing/index.d.ts.map +0 -1
  96. package/lib/code-editor/testing/index.js.map +0 -1
  97. /package/lib/code-editor/{testing → __test-utils__}/MockedMonacoEditor.d.ts +0 -0
  98. /package/lib/code-editor/{testing → __test-utils__}/MockedMonacoEditor.js +0 -0
  99. /package/lib/code-editor/{testing → __test-utils__}/MonacoEditorMockUtils.d.ts +0 -0
  100. /package/src/code-editor/{testing → __test-utils__}/MockedMonacoEditor.ts +0 -0
@@ -0,0 +1,501 @@
1
+ /**
2
+ * Copyright (c) 2020-present, Goldman Sachs
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /* eslint-disable prefer-named-capture-group */
18
+ import {
19
+ PARSER_SECTION_MARKER,
20
+ PURE_ELEMENT_NAME,
21
+ PURE_CONNECTION_NAME,
22
+ PURE_PARSER,
23
+ } from '@finos/legend-graph';
24
+ import {
25
+ editor as monacoEditorAPI,
26
+ languages as monacoLanguagesAPI,
27
+ } from 'monaco-editor';
28
+ import { CODE_EDITOR_LANGUAGE, CODE_EDITOR_THEME } from './CodeEditorConfig.js';
29
+
30
+ /**
31
+ * The postfix to be added to all token types, i.e. identifier.pure, number.pure, etc.
32
+ */
33
+ const PURE_GRAMMAR_TOKEN_POSTFIX = '.pure';
34
+
35
+ export enum PURE_GRAMMAR_TOKEN {
36
+ WHITESPACE = '',
37
+
38
+ KEYWORD = 'keyword',
39
+ IDENTIFIER = 'identifier',
40
+ OPERATOR = 'operator',
41
+ DELIMITER = 'delimiter',
42
+
43
+ PARSER = 'parser',
44
+ NUMBER = 'number',
45
+ DATE = 'date',
46
+ COLOR = 'color',
47
+ PACKAGE = 'package',
48
+ STRING = 'string',
49
+ COMMENT = 'comment',
50
+
51
+ LANGUAGE_STRUCT = 'language-struct',
52
+ MULTIPLICITY = 'multiplicity',
53
+ GENERICS = 'generics',
54
+ PROPERTY = 'property',
55
+ PARAMETER = 'property',
56
+ VARIABLE = 'variable',
57
+ TYPE = 'type',
58
+
59
+ INVALID = 'invalid',
60
+ }
61
+
62
+ const theme: monacoEditorAPI.IStandaloneThemeData = {
63
+ base: 'vs-dark', // can also be vs-dark or hc-black
64
+ inherit: true, // can also be false to completely replace the builtin rules
65
+ colors: {},
66
+ rules: [
67
+ // NOTE: unfortunately, `monaco-editor` only accepts HEX values, not CSS variables
68
+ { token: PURE_GRAMMAR_TOKEN.IDENTIFIER, foreground: 'dcdcaa' },
69
+ { token: PURE_GRAMMAR_TOKEN.NUMBER, foreground: 'b5cea8' },
70
+ { token: PURE_GRAMMAR_TOKEN.DATE, foreground: 'b5cea8' },
71
+ { token: PURE_GRAMMAR_TOKEN.COLOR, foreground: 'b5cea8' },
72
+ { token: PURE_GRAMMAR_TOKEN.PACKAGE, foreground: '808080' },
73
+ { token: PURE_GRAMMAR_TOKEN.PARSER, foreground: 'c586c0' },
74
+ { token: PURE_GRAMMAR_TOKEN.LANGUAGE_STRUCT, foreground: 'c586c0' },
75
+ { token: PURE_GRAMMAR_TOKEN.MULTIPLICITY, foreground: '2d796b' },
76
+ { token: PURE_GRAMMAR_TOKEN.GENERICS, foreground: '2d796b' },
77
+ { token: PURE_GRAMMAR_TOKEN.PROPERTY, foreground: '9cdcfe' },
78
+ { token: PURE_GRAMMAR_TOKEN.PARAMETER, foreground: '9cdcfe' },
79
+ { token: PURE_GRAMMAR_TOKEN.VARIABLE, foreground: '4fc1ff' },
80
+ { token: PURE_GRAMMAR_TOKEN.TYPE, foreground: '3dc9b0' },
81
+ { token: `${PURE_GRAMMAR_TOKEN.STRING}.escape`, foreground: 'd7ba7d' },
82
+ ],
83
+ };
84
+
85
+ // Taken from `monaco-languages` configuration for Java in order to do propert brace matching
86
+ // See https://github.com/microsoft/monaco-languages/blob/master/src/java/java.ts
87
+ const configuration: monacoLanguagesAPI.LanguageConfiguration = {
88
+ // NOTE: Pure identifier includes $ but not in the first position (as that is parsed as a variable)
89
+ wordPattern:
90
+ /(-?\d*\.\d\w*)|([^`~!@#%^$&*()\-=+[{\]}\\|;:'",.<>/?\s][^`~!@#%^&*()\-=+[{\]}\\|;:'",.<>/?\s]*)/,
91
+ comments: {
92
+ lineComment: '//',
93
+ blockComment: ['/*', '*/'],
94
+ },
95
+ brackets: [
96
+ ['{', '}'],
97
+ ['[', ']'],
98
+ ['(', ')'],
99
+ ],
100
+ autoClosingPairs: [
101
+ { open: '{', close: '}' },
102
+ { open: '[', close: ']' },
103
+ { open: '(', close: ')' },
104
+ { open: '"', close: '"' },
105
+ { open: "'", close: "'" },
106
+ ],
107
+ surroundingPairs: [
108
+ { open: '{', close: '}' },
109
+ { open: '[', close: ']' },
110
+ { open: '(', close: ')' },
111
+ { open: '"', close: '"' },
112
+ { open: "'", close: "'" },
113
+ { open: '<', close: '>' },
114
+ { open: '<<', close: '>>' },
115
+ ],
116
+ folding: {
117
+ markers: {
118
+ start: new RegExp('^\\s*//\\s*(?:(?:#?region\\b)|(?:<editor-fold\\b))'),
119
+ end: new RegExp('^\\s*//\\s*(?:(?:#?endregion\\b)|(?:</editor-fold>))'),
120
+ },
121
+ },
122
+ };
123
+
124
+ /**
125
+ * Create new monarch definition to support syntax-highlighting
126
+ * See https://microsoft.github.io/monaco-editor/monarch.html
127
+ *
128
+ * The way SQL monarch definition is organized is good and worth learning from
129
+ * See https://github.com/microsoft/monaco-languages/blob/master/src/sql/sql.ts
130
+ *
131
+ * NOTE: using `monarch` only allows fairly very basic syntax-highlighting
132
+ * to actually do full AST analysis, we might need something more serious like
133
+ * using TextMate grammar which is used by VSCode itself
134
+ * See https://github.com/microsoft/monaco-editor#faq
135
+ * See https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide
136
+ */
137
+ const generateLanguageMonarch = (
138
+ extraKeywords: string[],
139
+ extraParsers: string[],
140
+ ): monacoLanguagesAPI.IMonarchLanguage =>
141
+ // TODO: complete syntax-highlighter for core features like constraint, derived properties, etc.
142
+ // TODO: add syntax highlighting for modules/plugins (come up with a plugin mechanism to do this).
143
+ ({
144
+ defaultToken: 'invalid',
145
+ tokenPostfix: PURE_GRAMMAR_TOKEN_POSTFIX,
146
+
147
+ keywords: [
148
+ ...extraKeywords,
149
+ // relational
150
+ 'Schema',
151
+ 'Table',
152
+ 'Join',
153
+ 'View',
154
+ 'primaryKey',
155
+ 'groupBy',
156
+ 'mainTable',
157
+ // native
158
+ 'let',
159
+ 'extends',
160
+ 'true',
161
+ 'false',
162
+ 'projects',
163
+ // elements
164
+ PURE_ELEMENT_NAME.CLASS,
165
+ PURE_ELEMENT_NAME.ASSOCIATION,
166
+ PURE_ELEMENT_NAME.ENUMERATION,
167
+ PURE_ELEMENT_NAME.MEASURE,
168
+ PURE_ELEMENT_NAME.PROFILE,
169
+ PURE_ELEMENT_NAME.FUNCTION,
170
+ PURE_ELEMENT_NAME.MAPPING,
171
+ PURE_ELEMENT_NAME.RUNTIME,
172
+ PURE_ELEMENT_NAME.CONNECTION,
173
+ PURE_ELEMENT_NAME.FILE_GENERATION,
174
+ PURE_ELEMENT_NAME.GENERATION_SPECIFICATION,
175
+ PURE_ELEMENT_NAME.DATA_ELEMENT,
176
+ // connections
177
+ PURE_CONNECTION_NAME.JSON_MODEL_CONNECTION,
178
+ PURE_CONNECTION_NAME.MODEL_CHAIN_CONNECTION,
179
+ PURE_CONNECTION_NAME.XML_MODEL_CONNECTION,
180
+ // mapping
181
+ 'include',
182
+ 'EnumerationMapping',
183
+ 'Pure',
184
+ 'AssociationMapping',
185
+ 'XStore',
186
+ 'AggregationAware',
187
+ /**
188
+ * @modularize
189
+ * See https://github.com/finos/legend-studio/issues/65
190
+ */
191
+ PURE_ELEMENT_NAME.SERVICE,
192
+ PURE_ELEMENT_NAME.FLAT_DATA,
193
+ PURE_ELEMENT_NAME.DATABASE,
194
+ PURE_CONNECTION_NAME.FLAT_DATA_CONNECTION,
195
+ PURE_CONNECTION_NAME.RELATIONAL_DATABASE_CONNECTION,
196
+ 'Relational',
197
+ ],
198
+
199
+ operators: [
200
+ '=',
201
+ '>',
202
+ '<',
203
+ '!',
204
+ '~',
205
+ '?',
206
+ ':',
207
+ '==',
208
+ '<=',
209
+ '>=',
210
+ '&&',
211
+ '||',
212
+ '++',
213
+ '--',
214
+ '+',
215
+ '-',
216
+ '*',
217
+ '/',
218
+ '&',
219
+ '|',
220
+ '^',
221
+ '%',
222
+ '->',
223
+ '#{',
224
+ '}#',
225
+ '@',
226
+ '<<',
227
+ '>>',
228
+ ],
229
+
230
+ languageStructs: ['import', 'native'],
231
+
232
+ parsers: (
233
+ [
234
+ PURE_PARSER.PURE,
235
+ PURE_PARSER.CONNECTION,
236
+ PURE_PARSER.RUNTIME,
237
+ PURE_PARSER.MAPPING,
238
+ PURE_PARSER.SERVICE,
239
+ PURE_PARSER.FLATDATA,
240
+ PURE_PARSER.RELATIONAL,
241
+ PURE_PARSER.GENERATION_SPECIFICATION,
242
+ PURE_PARSER.FILE_GENERATION_SPECIFICATION,
243
+ PURE_PARSER.DATA,
244
+ ] as string[]
245
+ )
246
+ .concat(extraParsers)
247
+ .map((parser) => `${PARSER_SECTION_MARKER}${parser}`),
248
+
249
+ // common regular expressions to be used in tokenizer
250
+ identifier: /[a-zA-Z_$][\w$]*/,
251
+ symbols: /[=><!~?:&|+\-*/^%#@]+/,
252
+ escapes:
253
+ /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
254
+ digits: /\d+(_+\d+)*/,
255
+ octaldigits: /[0-7]+(_+[0-7]+)*/,
256
+ binarydigits: /[0-1]+(_+[0-1]+)*/,
257
+ hexdigits: /[[0-9a-fA-F]+(_+[0-9a-fA-F]+)*/,
258
+ multiplicity: /\[(?:[a-zA-Z0-9]+(?:\.\.(?:[a-zA-Z0-9]+|\*|))?|\*)\]/,
259
+ package: /(?:[\w_]+::)+/,
260
+ // NOTE: generics is a little tricky because in order to do it right, we have to
261
+ // do some sort of bracket matching, but we just can use a simple tokenizer here
262
+ // so to account for cases like `<Nil,Any|*>)->` `Function<{T[1]->Boolean[1]}>[1]`
263
+ // we have to make sure the content does not contain any `:` or `.` characters
264
+ // in order to avoid the accidental greedy match with inputs like
265
+ // `function doSomething<T>(a: Function<T[1]->Boolean[1]>)`
266
+ // nor we want to make sure the last character of the content is not `-` to avoid
267
+ // accidentally matching `->` as the end of the generics
268
+ generics: /(?:(?:<\w+>)|(?:<[^:.@^()]+[^-]>))/,
269
+ date: /%-?\d+(?:-\d+(?:-\d+(?:T(?:\d+(?::\d+(?::\d+(?:.\d+)?)?)?)(?:[+-][0-9]{4})?)))/,
270
+ time: /%\d+(?::\d+(?::\d+(?:.\d+)?)?)?/,
271
+
272
+ tokenizer: {
273
+ root: [
274
+ // NOTE: since `monaco-editor` Monarch is only meant for tokenizing
275
+ // and the need to highlight Pure syntax is more than just token-based,
276
+ // but semantic/syntax-based we have to create these complex rules.
277
+ // the things to note here is these are not meant to match multilines
278
+ // and they must be placed before identifier rules since token matching
279
+ // is run in order
280
+ // See https://github.com/microsoft/monaco-editor/issues/316#issuecomment-273555698
281
+ // See https://github.com/microsoft/monaco-editor/issues/571#issuecomment-342555050
282
+ // See https://microsoft.github.io/monaco-editor/monarch.html
283
+ { include: '@pure' },
284
+
285
+ { include: '@date' },
286
+ { include: '@color' },
287
+
288
+ // parser markers
289
+ [
290
+ // NOTE: any leading whitespace to the section header is considered invalid syntax
291
+ /^\s*###[\w]+/,
292
+ {
293
+ cases: {
294
+ '@parsers': PURE_GRAMMAR_TOKEN.PARSER,
295
+ '@default': PURE_GRAMMAR_TOKEN.INVALID,
296
+ },
297
+ },
298
+ ],
299
+
300
+ // identifiers and keywords
301
+ [
302
+ /(@identifier)/,
303
+ {
304
+ cases: {
305
+ '@languageStructs': PURE_GRAMMAR_TOKEN.LANGUAGE_STRUCT,
306
+ '@keywords': `${PURE_GRAMMAR_TOKEN.KEYWORD}.$0`,
307
+ // function descriptor
308
+ '([a-zA-Z_$][\\w$]*)_((\\w+_(([a-zA-Z0-9]+)|(\\$[a-zA-Z0-9]+_[a-zA-Z0-9]+\\$)))__)*(\\w+_(([a-zA-Z0-9]+)|(\\$[a-zA-Z0-9]+_[a-zA-Z0-9]+\\$)))_':
309
+ PURE_GRAMMAR_TOKEN.TYPE,
310
+ '@default': PURE_GRAMMAR_TOKEN.IDENTIFIER,
311
+ },
312
+ },
313
+ ],
314
+
315
+ // whitespace
316
+ { include: '@whitespace' },
317
+
318
+ // delimiters and operators
319
+ [/[{}()[\]]/, '@brackets'],
320
+ [/[<>](?!@symbols)/, '@brackets'],
321
+ [
322
+ /@symbols/,
323
+ {
324
+ cases: {
325
+ '@operators': PURE_GRAMMAR_TOKEN.OPERATOR,
326
+ '@default': PURE_GRAMMAR_TOKEN.IDENTIFIER,
327
+ },
328
+ },
329
+ ],
330
+
331
+ { include: '@number' },
332
+
333
+ // delimiter: after number because of .\d floats
334
+ [/[;,.]/, PURE_GRAMMAR_TOKEN.DELIMITER],
335
+
336
+ // strings
337
+ // NOTE: including non-teminated string so as people type ', we can start showing them that they're working on a string
338
+ [/'([^'\\]|\\.)*$/, `${PURE_GRAMMAR_TOKEN.STRING}.invalid`],
339
+ [/'/, PURE_GRAMMAR_TOKEN.STRING, '@string'],
340
+
341
+ { include: '@characters' },
342
+ ],
343
+
344
+ pure: [
345
+ // type
346
+ [/(@package\*)/, [PURE_GRAMMAR_TOKEN.PACKAGE]], // import path
347
+ [
348
+ /(@package?)(@identifier)(@generics?)(\s*)(@multiplicity)/,
349
+ [
350
+ PURE_GRAMMAR_TOKEN.PACKAGE,
351
+ PURE_GRAMMAR_TOKEN.TYPE,
352
+ PURE_GRAMMAR_TOKEN.GENERICS,
353
+ PURE_GRAMMAR_TOKEN.WHITESPACE,
354
+ PURE_GRAMMAR_TOKEN.MULTIPLICITY,
355
+ ],
356
+ ],
357
+ [
358
+ /(@package)(@identifier)(@generics?)/,
359
+ [
360
+ PURE_GRAMMAR_TOKEN.PACKAGE,
361
+ PURE_GRAMMAR_TOKEN.TYPE,
362
+ PURE_GRAMMAR_TOKEN.GENERICS,
363
+ ],
364
+ ],
365
+
366
+ // special operators that uses type (e.g. constructor, cast)
367
+ [
368
+ /([@^])(\s*)(@package?)(@identifier)(@generics?)(@multiplicity?)/,
369
+ [
370
+ `${PURE_GRAMMAR_TOKEN.TYPE}.operator`,
371
+ PURE_GRAMMAR_TOKEN.WHITESPACE,
372
+ PURE_GRAMMAR_TOKEN.PACKAGE,
373
+ PURE_GRAMMAR_TOKEN.TYPE,
374
+ PURE_GRAMMAR_TOKEN.GENERICS,
375
+ PURE_GRAMMAR_TOKEN.MULTIPLICITY,
376
+ ],
377
+ ],
378
+
379
+ // property / parameter
380
+ [
381
+ /(\.\s*)(@identifier)/,
382
+ [PURE_GRAMMAR_TOKEN.DELIMITER, PURE_GRAMMAR_TOKEN.PROPERTY],
383
+ ],
384
+ [
385
+ /(@identifier)(\s*=)/,
386
+ [PURE_GRAMMAR_TOKEN.PROPERTY, PURE_GRAMMAR_TOKEN.OPERATOR],
387
+ ],
388
+ [
389
+ /(@identifier)(\.)(@identifier)/,
390
+ [
391
+ PURE_GRAMMAR_TOKEN.TYPE,
392
+ PURE_GRAMMAR_TOKEN.OPERATOR,
393
+ PURE_GRAMMAR_TOKEN.PROPERTY,
394
+ ],
395
+ ], // could be: property chain, profile tag, and stereotype
396
+ [
397
+ /(@identifier)(\s*:)/,
398
+ [PURE_GRAMMAR_TOKEN.PARAMETER, PURE_GRAMMAR_TOKEN.OPERATOR],
399
+ ],
400
+
401
+ // variables
402
+ [
403
+ /(let)(\s+)(@identifier)(\s*=)/,
404
+ [
405
+ PURE_GRAMMAR_TOKEN.KEYWORD,
406
+ PURE_GRAMMAR_TOKEN.WHITESPACE,
407
+ PURE_GRAMMAR_TOKEN.VARIABLE,
408
+ PURE_GRAMMAR_TOKEN.OPERATOR,
409
+ ],
410
+ ],
411
+ [/(\$@identifier)/, [`${PURE_GRAMMAR_TOKEN.VARIABLE}.reference`]],
412
+ ],
413
+
414
+ date: [
415
+ [/(%latest)/, [`${PURE_GRAMMAR_TOKEN.DATE}.latest`]],
416
+ [/(@date)/, [PURE_GRAMMAR_TOKEN.DATE]],
417
+ [/(@time)/, [`${PURE_GRAMMAR_TOKEN.DATE}.time`]],
418
+ ],
419
+
420
+ color: [[/(#[0-9a-fA-F]{6})/, [PURE_GRAMMAR_TOKEN.COLOR]]],
421
+
422
+ number: [
423
+ [
424
+ /(@digits)[eE]([-+]?(@digits))?[fFdD]?/,
425
+ `${PURE_GRAMMAR_TOKEN.NUMBER}.float`,
426
+ ],
427
+ [
428
+ /(@digits)\.(@digits)([eE][-+]?(@digits))?[fFdD]?/,
429
+ `${PURE_GRAMMAR_TOKEN.NUMBER}.float`,
430
+ ],
431
+ [/0[xX](@hexdigits)[Ll]?/, `${PURE_GRAMMAR_TOKEN.NUMBER}.hex`],
432
+ [/0(@octaldigits)[Ll]?/, `${PURE_GRAMMAR_TOKEN.NUMBER}.octal`],
433
+ [/0[bB](@binarydigits)[Ll]?/, `${PURE_GRAMMAR_TOKEN.NUMBER}.binary`],
434
+ [/(@digits)[fFdD]/, `${PURE_GRAMMAR_TOKEN.NUMBER}.float`],
435
+ [/(@digits)[lL]?/, PURE_GRAMMAR_TOKEN.NUMBER],
436
+ ],
437
+
438
+ whitespace: [
439
+ [/[ \t\r\n]+/, PURE_GRAMMAR_TOKEN.WHITESPACE],
440
+ [/\/\*\*(?!\/)/, `${PURE_GRAMMAR_TOKEN.COMMENT}.doc`, '@doc'],
441
+ [/\/\*/, PURE_GRAMMAR_TOKEN.COMMENT, '@comment'],
442
+ [/\/\/.*$/, PURE_GRAMMAR_TOKEN.COMMENT],
443
+ ],
444
+
445
+ comment: [
446
+ [/[^/*]+/, PURE_GRAMMAR_TOKEN.COMMENT],
447
+ // [/\/\*/, PURE_GRAMMAR_TOKEN.COMMENT, '@push' ], // nested comment not allowed :-(
448
+ // [/\/\*/, ${PURE_GRAMMAR_TOKEN.COMMENT}.invalid` ], // this breaks block comments in the shape of /* //*/
449
+ [/\*\//, PURE_GRAMMAR_TOKEN.COMMENT, '@pop'],
450
+ [/[/*]/, PURE_GRAMMAR_TOKEN.COMMENT],
451
+ ],
452
+
453
+ // Identical copy of comment above, except for the addition of .doc
454
+ doc: [
455
+ [/[^/*]+/, `${PURE_GRAMMAR_TOKEN.COMMENT}.doc`],
456
+ // [/\/\*/, `${PURE_GRAMMAR_TOKEN.COMMENT}.doc`, '@push' ], // nested comment not allowed :-(
457
+ [/\/\*/, `${PURE_GRAMMAR_TOKEN.COMMENT}.doc.invalid`],
458
+ [/\*\//, `${PURE_GRAMMAR_TOKEN.COMMENT}.doc`, '@pop'],
459
+ [/[/*]/, `${PURE_GRAMMAR_TOKEN.COMMENT}.doc`],
460
+ ],
461
+
462
+ string: [
463
+ [/[^\\']+/, PURE_GRAMMAR_TOKEN.STRING],
464
+ [/@escapes/, `${PURE_GRAMMAR_TOKEN.STRING}.escape`],
465
+ [/\\./, `${PURE_GRAMMAR_TOKEN.STRING}.escape.invalid`],
466
+ [/'/, PURE_GRAMMAR_TOKEN.STRING, '@pop'],
467
+ ],
468
+
469
+ characters: [
470
+ [/'[^\\']'/, PURE_GRAMMAR_TOKEN.STRING],
471
+ [
472
+ /(')(@escapes)(')/,
473
+ [
474
+ PURE_GRAMMAR_TOKEN.STRING,
475
+ `${PURE_GRAMMAR_TOKEN.STRING}.escape`,
476
+ PURE_GRAMMAR_TOKEN.STRING,
477
+ ],
478
+ ],
479
+ [/'/, `${PURE_GRAMMAR_TOKEN.STRING}.invalid`],
480
+ ],
481
+ },
482
+ } as monacoLanguagesAPI.IMonarchLanguage);
483
+
484
+ export function setupPureLanguageService(options?: {
485
+ extraKeywords?: string[] | undefined;
486
+ extraParserKeywords?: string[] | undefined;
487
+ }): void {
488
+ monacoEditorAPI.defineTheme(CODE_EDITOR_THEME.LEGEND, theme);
489
+ monacoLanguagesAPI.register({ id: CODE_EDITOR_LANGUAGE.PURE });
490
+ monacoLanguagesAPI.setLanguageConfiguration(
491
+ CODE_EDITOR_LANGUAGE.PURE,
492
+ configuration,
493
+ );
494
+ monacoLanguagesAPI.setMonarchTokensProvider(
495
+ CODE_EDITOR_LANGUAGE.PURE,
496
+ generateLanguageMonarch(
497
+ options?.extraKeywords ?? [],
498
+ options?.extraParserKeywords ?? [],
499
+ ),
500
+ );
501
+ }
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import { createMock } from '@finos/legend-shared';
17
+ import { createMock } from '@finos/legend-shared/test';
18
18
 
19
19
  /**
20
20
  * NOTE: we have tried different ways to mock `monaco-editor`. But those ways often involve
@@ -14,4 +14,4 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- export * from './MonacoEditorMockUtils.js';
17
+ export * from './__test-utils__/MonacoEditorMockUtils.js';
@@ -14,5 +14,13 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
+ export {
18
+ PURE_GRAMMAR_TOKEN,
19
+ setupPureLanguageService,
20
+ } from './PureLanguageService.js';
21
+ export * from './PureLanguageCodeEditorSupport.js';
22
+
23
+ export * from './CodeEditorConfig.js';
17
24
  export * from './CodeEditor.js';
18
25
  export * from './CodeEditorUtils.js';
26
+ export * from './CodeDiffView.js';
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Copyright (c) 2020-present, Goldman Sachs
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import {
18
+ type Type,
19
+ Class,
20
+ Enumeration,
21
+ Measure,
22
+ Unit,
23
+ PrimitiveType,
24
+ } from '@finos/legend-graph';
25
+ import {
26
+ PURE_ClassIcon,
27
+ PURE_PrimitiveTypeIcon,
28
+ PURE_EnumerationIcon,
29
+ PURE_MeasureIcon,
30
+ PURE_UnknownElementTypeIcon,
31
+ PURE_UnitIcon,
32
+ } from '@finos/legend-art';
33
+
34
+ export const getClassPropertyIcon = (type: Type): React.ReactNode => {
35
+ if (type instanceof PrimitiveType) {
36
+ return <PURE_PrimitiveTypeIcon />;
37
+ } else if (type instanceof Class) {
38
+ return <PURE_ClassIcon />;
39
+ } else if (type instanceof Enumeration) {
40
+ return <PURE_EnumerationIcon />;
41
+ } else if (type instanceof Measure) {
42
+ return <PURE_MeasureIcon />;
43
+ } else if (type instanceof Unit) {
44
+ return <PURE_UnitIcon />;
45
+ }
46
+ return <PURE_UnknownElementTypeIcon />;
47
+ };
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Copyright (c) 2020-present, Goldman Sachs
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import {
18
+ type PackageableElement,
19
+ isSystemElement,
20
+ isGeneratedElement,
21
+ isDependencyElement,
22
+ } from '@finos/legend-graph';
23
+
24
+ export interface PackageableElementOption<T extends PackageableElement> {
25
+ label: string;
26
+ value: T;
27
+ }
28
+
29
+ export const buildElementOption = <T extends PackageableElement>(
30
+ element: T,
31
+ ): PackageableElementOption<T> => ({
32
+ label: element.name,
33
+ value: element,
34
+ });
35
+
36
+ const getElementColorCode = (element: PackageableElement): string =>
37
+ isSystemElement(element)
38
+ ? 'system'
39
+ : isGeneratedElement(element)
40
+ ? 'generated'
41
+ : isDependencyElement(element)
42
+ ? 'dependency'
43
+ : '';
44
+
45
+ const generateOptionTooltipText = (
46
+ element: PackageableElement,
47
+ ): string | undefined =>
48
+ isSystemElement(element)
49
+ ? 'system element'
50
+ : isGeneratedElement(element)
51
+ ? 'generated element'
52
+ : isDependencyElement(element)
53
+ ? 'dependency element'
54
+ : undefined;
55
+
56
+ export const getPackageableElementOptionFormatter = (props: {
57
+ darkMode?: boolean | undefined;
58
+ }): ((
59
+ option: PackageableElementOption<PackageableElement>,
60
+ ) => React.ReactNode) =>
61
+ function PackageableElementOptionLabel(
62
+ option: PackageableElementOption<PackageableElement>,
63
+ ): React.ReactNode {
64
+ const { darkMode } = props;
65
+ const className = darkMode
66
+ ? 'packageable-element-option-label--dark'
67
+ : 'packageable-element-option-label';
68
+ const colorCode = getElementColorCode(option.value);
69
+
70
+ return (
71
+ <div className={className}>
72
+ <div
73
+ title={generateOptionTooltipText(option.value)}
74
+ className={`packageable-element-option-label__type ${
75
+ colorCode
76
+ ? `packageable-element-option-label__type--${colorCode}`
77
+ : ''
78
+ } `}
79
+ ></div>
80
+ <div className={`${className}__name`}>{option.label}</div>
81
+ {option.value.package && (
82
+ <div className={`${className}__tag`}>{option.value.path}</div>
83
+ )}
84
+ </div>
85
+ );
86
+ };
@@ -13,5 +13,6 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export * from './MonacoEditorMockUtils.js';
17
- //# sourceMappingURL=index.d.ts.map
16
+
17
+ export * from './PackageableElementOption.js';
18
+ export * from './ElementIconUtils.js';