sheel-deer 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/launch.json +51 -0
- package/.vscode/settings.json +94 -0
- package/.vscode/tasks.json +57 -0
- package/App.elen +70 -0
- package/README.MD +0 -0
- package/Test.elen +24 -0
- package/compile-all-ts.js +76 -0
- package/dist/index.es.js +1 -0
- package/dist/index.umd.js +1 -0
- package/elen/App.elen +7 -0
- package/elen/LICENSE +15 -0
- package/elen/dist/extension.js +130 -0
- package/elen/dist/init.js +28 -0
- package/elen/elen-1.0.0.vsix +0 -0
- package/elen/extension.ts +122 -0
- package/elen/icon-theme.json +2423 -0
- package/elen/icon.svg +1 -0
- package/elen/images/icon.svg +1 -0
- package/elen/init.ts +28 -0
- package/elen/language-configuration.json +26 -0
- package/elen/package-lock.json +549 -0
- package/elen/package.json +52 -0
- package/elen/seti.woff +0 -0
- package/elen/src/App.elen +0 -0
- package/elen/syntaxes/elen.tmLanguage.json +312 -0
- package/elen/tsconfig.json +14 -0
- package/elen-icon-theme/LICENSE +15 -0
- package/elen-icon-theme/README.md +18 -0
- package/elen-icon-theme/elen-icon-theme-1.0.0.vsix +0 -0
- package/elen-icon-theme/elen-icon-theme-1.0.1.vsix +0 -0
- package/elen-icon-theme/elen-icon-theme-1.0.13.vsix +0 -0
- package/elen-icon-theme/elen-icon-theme-1.0.15.vsix +0 -0
- package/elen-icon-theme/elen-icon-theme-1.0.16.vsix +0 -0
- package/elen-icon-theme/elen-icon-theme-1.0.17.vsix +0 -0
- package/elen-icon-theme/elen-icon-theme-1.0.18.vsix +0 -0
- package/elen-icon-theme/elen-icon-theme-1.0.19.vsix +0 -0
- package/elen-icon-theme/elen-icon-theme-1.0.2.vsix +0 -0
- package/elen-icon-theme/elen-icon-theme-1.0.20.vsix +0 -0
- package/elen-icon-theme/elen-icon-theme-1.0.3.vsix +0 -0
- package/elen-icon-theme/elen-icon-theme-1.0.4.vsix +0 -0
- package/elen-icon-theme/elen-icon-theme-1.0.5.vsix +0 -0
- package/elen-icon-theme/elen-icon-theme-1.0.6.vsix +0 -0
- package/elen-icon-theme/elen-icon-theme-1.0.7.vsix +0 -0
- package/elen-icon-theme/elen-icon-theme-1.0.8.vsix +0 -0
- package/elen-icon-theme/elen-icon-theme-1.0.9.vsix +0 -0
- package/elen-icon-theme/extension.js +226 -0
- package/elen-icon-theme/icon-theme.json +2425 -0
- package/elen-icon-theme/icon.svg +1 -0
- package/elen-icon-theme/images/icon.svg +1 -0
- package/elen-icon-theme/package.json +36 -0
- package/elen-icon-theme/seti.woff +0 -0
- package/icon.svg +8 -0
- package/index.html +11 -0
- package/init-start-page.ts +59 -0
- package/logo.html +15 -0
- package/package.json +42 -0
- package/server.ts +31 -0
- package/shells/data-page/Elen.ts +23 -0
- package/squarings/.json +132 -0
- package/squarings/App.json +59 -0
- package/squarings/Test.json +27 -0
- package/src/base/Component.ts +113 -0
- package/src/classes/BinaryData.ts +81 -0
- package/src/classes/DataModel.ts +386 -0
- package/src/classes/DataTypes.ts +116 -0
- package/src/components/squaring.ts +226 -0
- package/src/components/vtm.ts +231 -0
- package/src/data/ascii.ts +134 -0
- package/src/data/binary-resources.ts +209 -0
- package/src/events/event-handler.js +34 -0
- package/src/index.ts +1 -0
- package/src/methods/app-template.ts +7 -0
- package/src/methods/array-helpers.ts +176 -0
- package/src/methods/css-template.ts +5 -0
- package/src/methods/errors-helpers.ts +26 -0
- package/src/methods/html-template.ts +22 -0
- package/src/methods/parsers.ts +1012 -0
- package/src/methods/square.ts +80 -0
- package/src/methods/ts-template.ts +36 -0
- package/src/methods/using-template.ts +3 -0
- package/src/models/ascii.ts +26 -0
- package/src/models/data-stream.ts +5 -0
- package/src/models/data-type-model.ts +22 -0
- package/src/models/template-binary-model.ts +5 -0
- package/src/routes.ts +9 -0
- package/syntaxes/enel.tmLanguage.json +28 -0
- package/tsconfig.json +68 -0
- package/viewController/Inital.elen +8 -0
- package/vite.config.ts +25 -0
- package/vue.config.js +30 -0
|
@@ -0,0 +1,1012 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { ComponentData, DataProperty, getCurrentSquaring, ImportData, Methods, NotationData, setCurrentSquaring, Squaring, SquaringParameters } from '../components/squaring';
|
|
4
|
+
import { commentSeparation, componentTypeSeparator, eventTypeSeparator, classDeclartionSeparator, importTypeSeparator, methodReturnTypeBitMap, methodTypeSeparator, NotationTypeSeparator, rowSeparation, typeBitMap, newRow, newTab, propertyCloseSeparator, nullable, empty, using } from '../data/binary-resources';
|
|
5
|
+
import { DataList, DataListType } from '../models/data-type-model';
|
|
6
|
+
import { asciiTable } from './../data/ascii';
|
|
7
|
+
import { TsSquareMethods } from './square';
|
|
8
|
+
import { byteMapStartWith, trimWhiteSpaceFromLeft, isArrayEqual, splitArray, findLast, isListEqual, startsWithMultipleByteMap, removeArrayExclamationMark, setProperty, indexOf, atPosition } from './array-helpers';
|
|
9
|
+
import { ContentFile, CurrentRow } from '../models/ascii';
|
|
10
|
+
import { bracketsEndNotFound, bracketsStartNotFound, closingSeparatorNotFound, propertyIsNull } from '../methods/errors-helpers';
|
|
11
|
+
|
|
12
|
+
export const returnCssLinkByteArray = (cssPage: string) => {
|
|
13
|
+
let string = `<link rel="stylesheet" href="./${cssPage}.css">`;
|
|
14
|
+
let result = [] as number[];
|
|
15
|
+
|
|
16
|
+
for(let char of string){
|
|
17
|
+
result = [...result, asciiTable.ascii.find(x=> x.char == char)!.code];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const returnJSLinkByteArray = (jsPage: string) => {
|
|
24
|
+
let string = `<script src='${jsPage}.js'></script>`;
|
|
25
|
+
|
|
26
|
+
let result = [] as number[];
|
|
27
|
+
|
|
28
|
+
for(let char of string){
|
|
29
|
+
result = [...result, asciiTable.ascii.find(x=> x.char == char)!.code];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
export const TranslateRegularPage = (number: number[], name: string = '') : { arrays: number[] }[] => {
|
|
37
|
+
let data: DataList = new DataList();
|
|
38
|
+
let trimWhiteSpace: number[] = [];
|
|
39
|
+
let prevWasSpace = false;
|
|
40
|
+
|
|
41
|
+
for (let i = 0; i < number.length; i++) {
|
|
42
|
+
if (number[i] === 32) {
|
|
43
|
+
if (!prevWasSpace) {
|
|
44
|
+
trimWhiteSpace = [...trimWhiteSpace, 32];
|
|
45
|
+
prevWasSpace = true;
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
trimWhiteSpace = [...trimWhiteSpace, number[i]];
|
|
49
|
+
prevWasSpace = false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let i = 0;
|
|
54
|
+
for(let num of trimWhiteSpace){
|
|
55
|
+
if(i == trimWhiteSpace.length - 1) { break; }
|
|
56
|
+
if(!data.list.length){
|
|
57
|
+
data.list[i] = new DataListType();
|
|
58
|
+
data.list[i].array = [num];
|
|
59
|
+
|
|
60
|
+
}else if(i > 0 && fitRowSeparator(num, data.list[i - 1].array[data.list[i - 1].array.length - 1])){
|
|
61
|
+
i++;
|
|
62
|
+
data.list[i].array = [...data.list[i].array, num];
|
|
63
|
+
}else{
|
|
64
|
+
data.list[i].array = [...data.list[i].array, num];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let square = new TsSquareMethods();
|
|
69
|
+
|
|
70
|
+
let squaring: Squaring = new Squaring();
|
|
71
|
+
|
|
72
|
+
let squaringComponents: ComponentData[] = [];
|
|
73
|
+
let notations: NotationData[] = [];
|
|
74
|
+
let methods: Methods[] = [];
|
|
75
|
+
let imports: ImportData[] = [];
|
|
76
|
+
|
|
77
|
+
squaringComponents = [{
|
|
78
|
+
name: "",
|
|
79
|
+
properties: [],
|
|
80
|
+
template: "",
|
|
81
|
+
annotations: [],
|
|
82
|
+
version: "1.0.0"
|
|
83
|
+
} as ComponentData];
|
|
84
|
+
|
|
85
|
+
notations = [{
|
|
86
|
+
name: "",
|
|
87
|
+
properties: [],
|
|
88
|
+
template: "",
|
|
89
|
+
annotations: [],
|
|
90
|
+
version: "1.0.0"
|
|
91
|
+
} as NotationData];
|
|
92
|
+
|
|
93
|
+
methods = [{
|
|
94
|
+
name: "",
|
|
95
|
+
type: "",
|
|
96
|
+
body: [],
|
|
97
|
+
value: null,
|
|
98
|
+
parameters: [],
|
|
99
|
+
returnType: ""
|
|
100
|
+
} as Methods];
|
|
101
|
+
|
|
102
|
+
imports = [{
|
|
103
|
+
name: "",
|
|
104
|
+
type: "",
|
|
105
|
+
properties: []
|
|
106
|
+
} as ImportData];
|
|
107
|
+
|
|
108
|
+
squaring.data = square.createComponentData(squaringComponents, notations, methods, imports);
|
|
109
|
+
let content = fromAscii(data.list[0].array).split('\n');
|
|
110
|
+
squaring.name = "Inital";
|
|
111
|
+
|
|
112
|
+
let squaringParameters: SquaringParameters[] = []
|
|
113
|
+
|
|
114
|
+
let bracketValue = "";
|
|
115
|
+
let bracketClosed = true;
|
|
116
|
+
let bracketProperty: DataProperty | null = null;
|
|
117
|
+
for(let listItem of content){
|
|
118
|
+
let dataRow = fromString(listItem);
|
|
119
|
+
|
|
120
|
+
if(dataRow.length &&
|
|
121
|
+
!byteMapStartWith(dataRow, commentSeparation.bitMap) &&
|
|
122
|
+
!(dataRow.length == 1 && dataRow[0] == 32)) {
|
|
123
|
+
|
|
124
|
+
///using statement
|
|
125
|
+
if(byteMapStartWith(dataRow, using.bitMap) && bracketClosed){
|
|
126
|
+
let array = splitArray(dataRow, 32); let value;
|
|
127
|
+
let property = square.createComponentProperty(fromAscii(array[1]), fromAscii(array[0]), value, value == null || value == undefined ? true : false);
|
|
128
|
+
|
|
129
|
+
let usingStatements = splitArray(dataRow, 32);
|
|
130
|
+
let using = atPosition(usingStatements, 0);
|
|
131
|
+
let from = atPosition(usingStatements, 1);
|
|
132
|
+
|
|
133
|
+
squaringParameters = [...squaringParameters, {
|
|
134
|
+
name: fromAscii(using),
|
|
135
|
+
path: fromAscii(from),
|
|
136
|
+
parameters: [fromAscii(using), fromAscii(from)],
|
|
137
|
+
version: "1.0.0"
|
|
138
|
+
} as SquaringParameters]
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
///dataType string title = "";
|
|
142
|
+
for(let tbm of typeBitMap){
|
|
143
|
+
if(byteMapStartWith(trimWhiteSpaceFromLeft(dataRow), tbm.code)){
|
|
144
|
+
let array = splitArray(dataRow, 32); let value;
|
|
145
|
+
let property = square.createComponentProperty(fromAscii(array[1]), fromAscii(array[0]), value, value == null || value == undefined ? true : false);
|
|
146
|
+
|
|
147
|
+
let usingStatements = splitArray(dataRow, 32);
|
|
148
|
+
let using = atPosition(usingStatements, 0);
|
|
149
|
+
let from = atPosition(usingStatements, 1);
|
|
150
|
+
|
|
151
|
+
if(closingSeparatorNotFound(from)){
|
|
152
|
+
let equal = atPosition(usingStatements, 2);
|
|
153
|
+
|
|
154
|
+
if(bracketsStartNotFound(from)){
|
|
155
|
+
try{
|
|
156
|
+
bracketValue += fromAscii(atPosition(usingStatements, 3));
|
|
157
|
+
bracketValue += newRow.name;
|
|
158
|
+
bracketClosed = false;
|
|
159
|
+
bracketProperty = property;
|
|
160
|
+
|
|
161
|
+
}catch(ex){
|
|
162
|
+
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
}else{
|
|
166
|
+
bracketValue += fromAscii(atPosition(usingStatements, 3));
|
|
167
|
+
bracketValue += newRow.name;
|
|
168
|
+
bracketClosed = false;
|
|
169
|
+
bracketProperty = property;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if(!closingSeparatorNotFound(from)){
|
|
174
|
+
let equal = atPosition(usingStatements, 2);
|
|
175
|
+
let value = atPosition(usingStatements, 3);
|
|
176
|
+
property.value = value;
|
|
177
|
+
property.nullable = propertyIsNull(dataRow);
|
|
178
|
+
squaring.data.components[0].properties.push(property);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if(!bracketClosed){
|
|
184
|
+
if(bracketsEndNotFound(dataRow)){
|
|
185
|
+
bracketValue += fromAscii(dataRow);
|
|
186
|
+
bracketValue += newRow.name;
|
|
187
|
+
bracketProperty!.value += bracketValue;
|
|
188
|
+
}else{
|
|
189
|
+
if(closingSeparatorNotFound(dataRow)){
|
|
190
|
+
bracketValue += fromAscii(dataRow);
|
|
191
|
+
bracketValue += newRow.name;
|
|
192
|
+
bracketProperty!.value += bracketValue;
|
|
193
|
+
}else{
|
|
194
|
+
bracketValue += fromAscii(dataRow);
|
|
195
|
+
bracketValue += newRow.name;
|
|
196
|
+
bracketProperty!.value += bracketValue;
|
|
197
|
+
squaring.data.components[0].properties.push(bracketProperty!);
|
|
198
|
+
bracketClosed = true;
|
|
199
|
+
bracketProperty = null;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
///methodType override void beforeInit()
|
|
207
|
+
let currentRow = new CurrentRow();
|
|
208
|
+
for(let mts of methodReturnTypeBitMap){
|
|
209
|
+
if(byteMapStartWith(trimWhiteSpaceFromLeft(dataRow), mts.code) && !currentRow.begin){
|
|
210
|
+
let array = splitArray(dataRow, 32);
|
|
211
|
+
let name = fromAscii(array[2]).replace(/[^a-zA-Z]/g, '');
|
|
212
|
+
let returnType = fromAscii(array[1]);
|
|
213
|
+
let method = square.createSquareMethods(name.replace('()', ''), returnType, null, [], returnType);
|
|
214
|
+
squaring.data.methods.push(method);
|
|
215
|
+
|
|
216
|
+
currentRow.begin = true;
|
|
217
|
+
currentRow.current = currentRow.out;
|
|
218
|
+
currentRow.currentData = dataRow;
|
|
219
|
+
}else if(currentRow.begin &&
|
|
220
|
+
currentRow.current == currentRow.out &&
|
|
221
|
+
!byteMapStartWith(trimWhiteSpaceFromLeft(dataRow), mts.code), !byteMapStartWith(trimWhiteSpaceFromLeft(dataRow), [125]) &&
|
|
222
|
+
!equal(dataRow, currentRow.currentData) &&
|
|
223
|
+
!startsWithMultipleByteMap(dataRow, methodReturnTypeBitMap)){
|
|
224
|
+
currentRow.lastDataBody = currentRow.currentDataBody;
|
|
225
|
+
currentRow.currentDataBody = dataRow;
|
|
226
|
+
|
|
227
|
+
if(!equal(currentRow.lastDataBody, currentRow.currentDataBody) || currentRow.lastDataBody.length == 0){
|
|
228
|
+
let method = findLast(squaring.data.methods);
|
|
229
|
+
method.body.push(fromAscii(dataRow));
|
|
230
|
+
method.body.push(newRow.name);
|
|
231
|
+
}
|
|
232
|
+
}else{
|
|
233
|
+
currentRow.begin = false;
|
|
234
|
+
currentRow.out = currentRow.out++;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
let contentFile = new ContentFile();
|
|
242
|
+
for(let item of squaring.data.squaringReferences){
|
|
243
|
+
for(let parameters of item.squaringParameters){
|
|
244
|
+
contentFile.contentFile.push(`import ${parameters.name} from ${parameters.path}`);
|
|
245
|
+
contentFile.contentFile.push(newRow.name);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
contentFile.contentFile.push(newRow.name);
|
|
250
|
+
contentFile.contentFile.push(newRow.name);
|
|
251
|
+
contentFile.contentFile.push(`export default class ${squaring.name} extends Component {`);
|
|
252
|
+
contentFile.contentFile.push(newRow.name);
|
|
253
|
+
|
|
254
|
+
for(let item of squaring.data.components){
|
|
255
|
+
for(let property of item.properties){
|
|
256
|
+
contentFile.contentFile.push(newTab.name);
|
|
257
|
+
contentFile.contentFile.push(`${property.name}${property.nullable ? nullable.name: empty.name}: ${property.type}`);
|
|
258
|
+
contentFile = setProperty(property, contentFile);
|
|
259
|
+
contentFile.contentFile.push(`${fromAscii(propertyCloseSeparator.bitMap)}`);
|
|
260
|
+
contentFile.contentFile.push(newRow.name);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
for(let item of squaring.data.notations){
|
|
265
|
+
for(let property of item.properties){
|
|
266
|
+
contentFile.contentFile.push(newTab.name);
|
|
267
|
+
contentFile.contentFile.push(`${property.name}${property.nullable ? nullable.name: empty.name}: ${property.type}`);
|
|
268
|
+
contentFile = setProperty(property, contentFile);
|
|
269
|
+
contentFile.contentFile.push(`${fromAscii(propertyCloseSeparator.bitMap)}`);
|
|
270
|
+
contentFile.contentFile.push(newRow.name);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
for(let item of squaring.data.methods){
|
|
275
|
+
if(item.name){
|
|
276
|
+
contentFile.contentFile.push(newTab.name);
|
|
277
|
+
contentFile.contentFile.push(`\t${item.name}`);
|
|
278
|
+
if(item.parameters.length){
|
|
279
|
+
for(let parameter of item.parameters){
|
|
280
|
+
contentFile.contentFile.push(newTab.name);
|
|
281
|
+
contentFile.contentFile.push(`(${parameter.name}: ${parameter.type}) `);
|
|
282
|
+
contentFile.contentFile.push(newRow.name);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
else{
|
|
286
|
+
contentFile.contentFile.push(newTab.name);
|
|
287
|
+
contentFile.contentFile.push('()');
|
|
288
|
+
contentFile.contentFile.push(newRow.name);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
contentFile.contentFile.push(newTab.name);
|
|
292
|
+
contentFile.contentFile.push(`: ${item.returnType} {`);
|
|
293
|
+
contentFile.contentFile.push(newRow.name);
|
|
294
|
+
if(item.body.length){
|
|
295
|
+
contentFile.contentFile.push(newTab.name);
|
|
296
|
+
for(let bd of item.body){
|
|
297
|
+
contentFile.contentFile.push(`${bd}`);
|
|
298
|
+
}
|
|
299
|
+
contentFile.contentFile.push(`${newRow.name}`);
|
|
300
|
+
}
|
|
301
|
+
contentFile.contentFile.push(newTab.name);
|
|
302
|
+
contentFile.contentFile.push(`}`);
|
|
303
|
+
contentFile.contentFile.push(newRow.name);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
contentFile.contentFile.push(newRow.name);
|
|
308
|
+
contentFile.contentFile.push(`}`);
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
setCurrentSquaring([...getCurrentSquaring(), squaring])
|
|
312
|
+
return createFromString(contentFile);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
export const translateTS = (number: number[], name: string = '') : { arrays: number[] }[] => {
|
|
318
|
+
let data: DataList = new DataList();
|
|
319
|
+
let trimWhiteSpace: number[] = [];
|
|
320
|
+
let prevWasSpace = false;
|
|
321
|
+
|
|
322
|
+
for (let i = 0; i < number.length; i++) {
|
|
323
|
+
if (number[i] === 32) {
|
|
324
|
+
if (!prevWasSpace) {
|
|
325
|
+
trimWhiteSpace = [...trimWhiteSpace, 32];
|
|
326
|
+
prevWasSpace = true;
|
|
327
|
+
}
|
|
328
|
+
} else {
|
|
329
|
+
trimWhiteSpace = [...trimWhiteSpace, number[i]];
|
|
330
|
+
prevWasSpace = false;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
let i = 0;
|
|
335
|
+
for(let num of trimWhiteSpace){
|
|
336
|
+
if(i == trimWhiteSpace.length - 1) { break; }
|
|
337
|
+
if(!data.list.length){
|
|
338
|
+
data.list[i] = new DataListType();
|
|
339
|
+
data.list[i].array = [num];
|
|
340
|
+
|
|
341
|
+
}else if(i > 0 && fitRowSeparator(num, data.list[i - 1].array[data.list[i - 1].array.length - 1])){
|
|
342
|
+
i++;
|
|
343
|
+
data.list[i].array = [...data.list[i].array, num];
|
|
344
|
+
}else{
|
|
345
|
+
data.list[i].array = [...data.list[i].array, num];
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
let result: number[] = [];
|
|
350
|
+
|
|
351
|
+
let square = new TsSquareMethods();
|
|
352
|
+
|
|
353
|
+
let squaring: Squaring = new Squaring();
|
|
354
|
+
|
|
355
|
+
let squaringComponents: ComponentData[] = [];
|
|
356
|
+
let notations: NotationData[] = [];
|
|
357
|
+
let methods: Methods[] = [];
|
|
358
|
+
let imports: ImportData[] = [];
|
|
359
|
+
|
|
360
|
+
squaringComponents = [{
|
|
361
|
+
name: "",
|
|
362
|
+
properties: [],
|
|
363
|
+
template: "",
|
|
364
|
+
annotations: [],
|
|
365
|
+
version: "1.0.0"
|
|
366
|
+
} as ComponentData];
|
|
367
|
+
|
|
368
|
+
notations = [{
|
|
369
|
+
name: "",
|
|
370
|
+
properties: [],
|
|
371
|
+
template: "",
|
|
372
|
+
annotations: [],
|
|
373
|
+
version: "1.0.0"
|
|
374
|
+
} as NotationData];
|
|
375
|
+
|
|
376
|
+
methods = [{
|
|
377
|
+
name: "",
|
|
378
|
+
type: "",
|
|
379
|
+
body: [],
|
|
380
|
+
value: null,
|
|
381
|
+
parameters: [],
|
|
382
|
+
returnType: ""
|
|
383
|
+
} as Methods];
|
|
384
|
+
|
|
385
|
+
imports = [{
|
|
386
|
+
name: "",
|
|
387
|
+
type: "",
|
|
388
|
+
properties: []
|
|
389
|
+
} as ImportData];
|
|
390
|
+
|
|
391
|
+
let squaringParameters: SquaringParameters[] = []
|
|
392
|
+
squaring.data = square.createComponentData(squaringComponents, notations, methods, imports);
|
|
393
|
+
let content = fromAscii(data.list[0].array).split('\n');
|
|
394
|
+
for(let listItem of content){
|
|
395
|
+
let dataRow = fromString(listItem);
|
|
396
|
+
|
|
397
|
+
if(dataRow.length &&
|
|
398
|
+
!byteMapStartWith(dataRow, commentSeparation.bitMap) &&
|
|
399
|
+
!(dataRow.length == 1 && dataRow[0] == 32)) {
|
|
400
|
+
|
|
401
|
+
///class declaration => public class App {
|
|
402
|
+
if(isArrayEqual(classDeclartionSeparator.bitMap, trimWhiteSpaceFromLeft(dataRow).slice(0, classDeclartionSeparator.bitMap.length))){
|
|
403
|
+
let name = splitArray(dataRow, 32)[2];
|
|
404
|
+
squaring.name = fromAscii(name);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
///using statement
|
|
409
|
+
if(byteMapStartWith(dataRow, using.bitMap)){
|
|
410
|
+
let array = splitArray(dataRow, 32); let value;
|
|
411
|
+
let property = square.createComponentProperty(fromAscii(array[1]), fromAscii(array[0]), value, value == null || value == undefined ? true : false);
|
|
412
|
+
|
|
413
|
+
let usingStatements = splitArray(dataRow, 32);
|
|
414
|
+
let using = atPosition(usingStatements, 0);
|
|
415
|
+
let from = atPosition(usingStatements, 1);
|
|
416
|
+
|
|
417
|
+
squaringParameters = [...squaringParameters, {
|
|
418
|
+
name: fromAscii(using),
|
|
419
|
+
path: fromAscii(from),
|
|
420
|
+
parameters: [fromAscii(using), fromAscii(from)],
|
|
421
|
+
version: "1.0.0"
|
|
422
|
+
} as SquaringParameters]
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
/// imports => import Test from './test';
|
|
427
|
+
if(isArrayEqual(importTypeSeparator.bitMap, trimWhiteSpaceFromLeft(dataRow).slice(0, importTypeSeparator.bitMap.length))){
|
|
428
|
+
let notation = splitArray(dataRow, 32);
|
|
429
|
+
// Remove all single quotes and semicolons from the import path
|
|
430
|
+
let cleanedPath = fromAscii(notation[3]).replace(/[\';]/g, "");
|
|
431
|
+
let notationProperty = square.createImportProperty(fromAscii(notation[1]), fromAscii(notation[0]), fromAscii(notation[1]), cleanedPath);
|
|
432
|
+
squaring.data.imports[0].properties.push(notationProperty);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/// Component<T> =>
|
|
436
|
+
|
|
437
|
+
if(isArrayEqual(componentTypeSeparator.bitMap, trimWhiteSpaceFromLeft(dataRow).slice(0, componentTypeSeparator.bitMap.length))){
|
|
438
|
+
let notation = splitArray(dataRow, 32);
|
|
439
|
+
let type = fromAscii(splitArray(notation[0], 60)[1].slice(0, -1));
|
|
440
|
+
|
|
441
|
+
let propertyCodeName = removeArrayExclamationMark(notation[1], propertyCloseSeparator.bitMap);
|
|
442
|
+
|
|
443
|
+
let notationProperty = square.createComponentProperty(fromAscii(propertyCodeName), type, null, true);
|
|
444
|
+
squaring.data.components[0].properties.push(notationProperty);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
//// Event<Type> =>
|
|
448
|
+
|
|
449
|
+
if(isArrayEqual(eventTypeSeparator.bitMap, trimWhiteSpaceFromLeft(dataRow).slice(0, eventTypeSeparator.bitMap.length))){
|
|
450
|
+
let notation = splitArray(dataRow, 32);
|
|
451
|
+
let type = fromAscii(splitArray(notation[0], 60)[1].slice(0, -1));
|
|
452
|
+
|
|
453
|
+
let propertyCodeName = removeArrayExclamationMark(notation[1], propertyCloseSeparator.bitMap);
|
|
454
|
+
|
|
455
|
+
let notationProperty = square.createComponentProperty(fromAscii(propertyCodeName), type, null, true);
|
|
456
|
+
squaring.data.components[0].properties.push(notationProperty);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
////Notation<boolean> notation;
|
|
460
|
+
|
|
461
|
+
if(isArrayEqual(NotationTypeSeparator.bitMap, trimWhiteSpaceFromLeft(dataRow).slice(0, NotationTypeSeparator.bitMap.length))){
|
|
462
|
+
let notation = splitArray(dataRow, 32);
|
|
463
|
+
let type = fromAscii(splitArray(notation[0], 60)[1].slice(0, -1));
|
|
464
|
+
|
|
465
|
+
let propertyCodeName = removeArrayExclamationMark(notation[1], propertyCloseSeparator.bitMap);
|
|
466
|
+
|
|
467
|
+
let notationProperty = square.createComponentProperty(fromAscii(propertyCodeName), type, null, true);
|
|
468
|
+
squaring.data.notations[0].properties.push(notationProperty);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
///dataType string title = "";
|
|
472
|
+
for(let tbm of typeBitMap){
|
|
473
|
+
if(byteMapStartWith(trimWhiteSpaceFromLeft(dataRow), tbm.code)){
|
|
474
|
+
let array = splitArray(dataRow, 32); let value;
|
|
475
|
+
if(array.length == 4){
|
|
476
|
+
value = fromAscii(removeArrayExclamationMark(array[3], propertyCloseSeparator.bitMap));
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
let property = square.createComponentProperty(fromAscii(array[1]), fromAscii(array[0]), value, value == null || value == undefined ? true : false);
|
|
480
|
+
squaring.data.components[0].properties.push(property);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
///methodType override void beforeInit()
|
|
485
|
+
let currentRow = new CurrentRow();
|
|
486
|
+
for(let mts of methodReturnTypeBitMap){
|
|
487
|
+
if(byteMapStartWith(trimWhiteSpaceFromLeft(dataRow), mts.code) && !currentRow.begin){
|
|
488
|
+
let array = splitArray(dataRow, 32);
|
|
489
|
+
let name = fromAscii(array[2]).replace(/[^a-zA-Z]/g, '');
|
|
490
|
+
let returnType = fromAscii(array[1]);
|
|
491
|
+
let method = square.createSquareMethods(name.replace('()', ''), returnType, null, [], returnType);
|
|
492
|
+
squaring.data.methods.push(method);
|
|
493
|
+
|
|
494
|
+
currentRow.begin = true;
|
|
495
|
+
currentRow.current = currentRow.out;
|
|
496
|
+
currentRow.currentData = dataRow;
|
|
497
|
+
}else if(currentRow.begin &&
|
|
498
|
+
currentRow.current == currentRow.out &&
|
|
499
|
+
!byteMapStartWith(trimWhiteSpaceFromLeft(dataRow), mts.code), !byteMapStartWith(trimWhiteSpaceFromLeft(dataRow), [125]) &&
|
|
500
|
+
!equal(dataRow, currentRow.currentData) &&
|
|
501
|
+
!startsWithMultipleByteMap(dataRow, methodReturnTypeBitMap)){
|
|
502
|
+
currentRow.lastDataBody = currentRow.currentDataBody;
|
|
503
|
+
currentRow.currentDataBody = dataRow;
|
|
504
|
+
|
|
505
|
+
if(!equal(currentRow.lastDataBody, currentRow.currentDataBody) || currentRow.lastDataBody.length == 0){
|
|
506
|
+
let method = findLast(squaring.data.methods);
|
|
507
|
+
method.body.push(fromAscii(dataRow));
|
|
508
|
+
method.body.push(newRow.name);
|
|
509
|
+
}
|
|
510
|
+
}else{
|
|
511
|
+
currentRow.begin = false;
|
|
512
|
+
currentRow.out = currentRow.out++;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
let contentFile = new ContentFile();
|
|
520
|
+
contentFile.contentFile.push(`import { Component } from './Component'`);
|
|
521
|
+
contentFile.contentFile.push(newRow.name);
|
|
522
|
+
for(let item of squaring.data.imports){
|
|
523
|
+
for(let property of item.properties){
|
|
524
|
+
contentFile.contentFile.push(`import ${property.name} from './index.js'`);
|
|
525
|
+
contentFile.contentFile.push(newRow.name);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
for(let item of squaring.data.squaringReferences){
|
|
530
|
+
for(let parameters of item.squaringParameters){
|
|
531
|
+
contentFile.contentFile.push(`import ${parameters.name} from ${parameters.path}`);
|
|
532
|
+
contentFile.contentFile.push(newRow.name);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
contentFile.contentFile.push(newRow.name);
|
|
537
|
+
contentFile.contentFile.push(newRow.name);
|
|
538
|
+
contentFile.contentFile.push(`export default class ${squaring.name} extends Component {`);
|
|
539
|
+
contentFile.contentFile.push(newRow.name);
|
|
540
|
+
|
|
541
|
+
for(let item of squaring.data.components){
|
|
542
|
+
for(let property of item.properties){
|
|
543
|
+
contentFile.contentFile.push(newTab.name);
|
|
544
|
+
contentFile.contentFile.push(`${property.name}${property.nullable ? nullable.name: empty.name}: ${property.type}`);
|
|
545
|
+
contentFile = setProperty(property, contentFile);
|
|
546
|
+
contentFile.contentFile.push(`${fromAscii(propertyCloseSeparator.bitMap)}`);
|
|
547
|
+
contentFile.contentFile.push(newRow.name);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
for(let item of squaring.data.notations){
|
|
552
|
+
for(let property of item.properties){
|
|
553
|
+
contentFile.contentFile.push(newTab.name);
|
|
554
|
+
contentFile.contentFile.push(`${property.name}${property.nullable ? nullable.name: empty.name}: ${property.type}`);
|
|
555
|
+
contentFile = setProperty(property, contentFile);
|
|
556
|
+
contentFile.contentFile.push(`${fromAscii(propertyCloseSeparator.bitMap)}`);
|
|
557
|
+
contentFile.contentFile.push(newRow.name);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
for(let item of squaring.data.methods){
|
|
562
|
+
if(item.name){
|
|
563
|
+
contentFile.contentFile.push(newTab.name);
|
|
564
|
+
contentFile.contentFile.push(`\t${item.name}`);
|
|
565
|
+
if(item.parameters.length){
|
|
566
|
+
for(let parameter of item.parameters){
|
|
567
|
+
contentFile.contentFile.push(newTab.name);
|
|
568
|
+
contentFile.contentFile.push(`(${parameter.name}: ${parameter.type}) `);
|
|
569
|
+
contentFile.contentFile.push(newRow.name);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
else{
|
|
573
|
+
contentFile.contentFile.push(newTab.name);
|
|
574
|
+
contentFile.contentFile.push('()');
|
|
575
|
+
contentFile.contentFile.push(newRow.name);
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
contentFile.contentFile.push(newTab.name);
|
|
579
|
+
contentFile.contentFile.push(`: ${item.returnType} {`);
|
|
580
|
+
contentFile.contentFile.push(newRow.name);
|
|
581
|
+
if(item.body.length){
|
|
582
|
+
contentFile.contentFile.push(newTab.name);
|
|
583
|
+
for(let bd of item.body){
|
|
584
|
+
contentFile.contentFile.push(`${bd}`);
|
|
585
|
+
}
|
|
586
|
+
contentFile.contentFile.push(`${newRow.name}`);
|
|
587
|
+
}
|
|
588
|
+
contentFile.contentFile.push(newTab.name);
|
|
589
|
+
contentFile.contentFile.push(`}`);
|
|
590
|
+
contentFile.contentFile.push(newRow.name);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
contentFile.contentFile.push(newRow.name);
|
|
595
|
+
contentFile.contentFile.push(`}`);
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
setCurrentSquaring([...getCurrentSquaring(), squaring])
|
|
599
|
+
return createFromString(contentFile);
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
export const componentType = (number: number[]) => {
|
|
604
|
+
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
export const eventType = (number: number[]) => {
|
|
608
|
+
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
export const notationType = (number: number[]) => {
|
|
612
|
+
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
export const fitRowSeparator = (number: number, lastNumber: number) => {
|
|
616
|
+
let rows = rowSeparation.bitMap;
|
|
617
|
+
|
|
618
|
+
for(let row of rows){
|
|
619
|
+
if(number == row[1]){
|
|
620
|
+
if(row[0] == lastNumber){
|
|
621
|
+
return true;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
return false;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
export const translateDataType = (number: number[]) => {
|
|
630
|
+
let data: DataList = new DataList();
|
|
631
|
+
|
|
632
|
+
let i = 0;
|
|
633
|
+
for(let num of number){
|
|
634
|
+
if(num == 10){ //// newrow
|
|
635
|
+
i++;
|
|
636
|
+
}else{
|
|
637
|
+
data.list[i].array = [...data.list[i].array, num];
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
for(let array of data.list){ ///// check dataType, check methodType
|
|
642
|
+
for(let data of array.array){
|
|
643
|
+
if(data != 32){
|
|
644
|
+
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
export const dataType = (number: number[]) => {
|
|
651
|
+
let data: DataList = new DataList();
|
|
652
|
+
|
|
653
|
+
let i = 0;
|
|
654
|
+
for(let num of number){
|
|
655
|
+
if(num == 32){
|
|
656
|
+
i++;
|
|
657
|
+
}
|
|
658
|
+
else if(!data.list!.length){
|
|
659
|
+
data.list[i] = new DataListType();
|
|
660
|
+
data.list[i].array = [num];
|
|
661
|
+
}
|
|
662
|
+
else{
|
|
663
|
+
if(data.list[i] == undefined){
|
|
664
|
+
data.list[i] = new DataListType();
|
|
665
|
+
}
|
|
666
|
+
data.list[i].array = [...data.list[i].array, num];
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
for (let page of data.list) {
|
|
670
|
+
if (page === undefined) continue;
|
|
671
|
+
|
|
672
|
+
for (let tbm of typeBitMap) {
|
|
673
|
+
const same =
|
|
674
|
+
tbm.code.length === page.array.length &&
|
|
675
|
+
tbm.code.every((v, i) => v === page.array[i]);
|
|
676
|
+
|
|
677
|
+
if (same) {
|
|
678
|
+
// remove / handle match
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
let change = data.list[0];
|
|
683
|
+
data.list[0] = data.list[1];
|
|
684
|
+
data.list[1] = change;
|
|
685
|
+
|
|
686
|
+
let result = [] as number[];
|
|
687
|
+
|
|
688
|
+
for(let i = 0; i < data.list.length; i++){
|
|
689
|
+
if(i == 0){
|
|
690
|
+
result = [...result, 58]; //// ts : translate
|
|
691
|
+
}else{
|
|
692
|
+
|
|
693
|
+
result = [...result, ...data.list[i].array];
|
|
694
|
+
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
if(i !== data.list.length){
|
|
698
|
+
result = [...result, 32]; //// divider
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
return result;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
export const methodType = (number: number[]) => {
|
|
706
|
+
let data: DataList = new DataList();
|
|
707
|
+
|
|
708
|
+
let i = 0;
|
|
709
|
+
for(let num of number){
|
|
710
|
+
if(num == 32){
|
|
711
|
+
i++;
|
|
712
|
+
}
|
|
713
|
+
else if(num == methodTypeSeparator.bitMap[1]){
|
|
714
|
+
if(methodTypeSeparator.bitMap[0] == data.list[i].array[data.list[i].array.length - 1]){
|
|
715
|
+
i++;
|
|
716
|
+
data.list[i] = new DataListType();
|
|
717
|
+
data.list[i].array = [...data.list[i].array, num];/// separator between joined
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
else{
|
|
721
|
+
data.list[i] = new DataListType();
|
|
722
|
+
data.list[i].array = [...data.list[i].array, num];
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
if(data.list.length < 4){
|
|
727
|
+
console.log("warn" + data.list.length)
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
let change = data.list[1];
|
|
731
|
+
data.list[1] = data.list[2];
|
|
732
|
+
data.list[2] = change;
|
|
733
|
+
|
|
734
|
+
let result = [] as number[];
|
|
735
|
+
|
|
736
|
+
for(let i = 0; i < data.list.length; i++){
|
|
737
|
+
if(i == 1){
|
|
738
|
+
result = [...result, ...data.list[i].array, 58]; //// ts : translate
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
result = [...result, ...data.list[i].array];
|
|
742
|
+
|
|
743
|
+
if(i !== data.list.length){
|
|
744
|
+
result = [...result, 32]; //// divider
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
return result;
|
|
749
|
+
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
export const equal = (number: number[], number2: number[]) => {
|
|
754
|
+
for(let i = 0; i < number.length; i++){
|
|
755
|
+
if(number[i] != number2[i]){
|
|
756
|
+
return false;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
return true;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
export const fromPageToString = (number: number[]) => {
|
|
764
|
+
let result = "";
|
|
765
|
+
for(let num of number){
|
|
766
|
+
result = result + asciiTable.ascii.find(x=> x.code == num)?.char;
|
|
767
|
+
}
|
|
768
|
+
return result;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
export const createPage = (number: { arrays: number[] }[]) => {
|
|
772
|
+
let result = "";
|
|
773
|
+
let tab = newTab.bitMap;
|
|
774
|
+
let row = newRow.bitMap;
|
|
775
|
+
|
|
776
|
+
try{
|
|
777
|
+
for(let i = 0; i < number.length; i++){
|
|
778
|
+
let filePart = number[i].arrays;
|
|
779
|
+
if(isArrayEqual(tab, filePart)){
|
|
780
|
+
result = result + newTab.name.replace(/[']/g, '\t');
|
|
781
|
+
continue;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
if(isArrayEqual(row, filePart)){
|
|
785
|
+
result = result + newRow.name.replace(/[']/g, '\t');
|
|
786
|
+
continue;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
result = result + fromAscii(filePart);
|
|
790
|
+
}
|
|
791
|
+
}catch(ex){
|
|
792
|
+
console.log(ex);
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
return result;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
export const createFromString = (contentFile: ContentFile) => {
|
|
799
|
+
let result: { arrays: number[] }[] = [];
|
|
800
|
+
let tab = newTab.name.split('');
|
|
801
|
+
let row = newRow.name.split('');
|
|
802
|
+
|
|
803
|
+
try{
|
|
804
|
+
for(let i = 0; i < contentFile.contentFile.length; i++){
|
|
805
|
+
let filePart = contentFile.contentFile[i];
|
|
806
|
+
let fileExclamation = filePart.split('');
|
|
807
|
+
|
|
808
|
+
if(isListEqual(fileExclamation, tab)){
|
|
809
|
+
result = [...result, { arrays: newTab.bitMap }];
|
|
810
|
+
continue;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
if(isListEqual(fileExclamation, row)){
|
|
814
|
+
result = [...result, { arrays: newRow.bitMap }];
|
|
815
|
+
continue;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
result = [...result, { arrays: fromString(filePart) }];
|
|
819
|
+
}
|
|
820
|
+
}catch(ex){
|
|
821
|
+
console.log("Error message"+ex);
|
|
822
|
+
}
|
|
823
|
+
return result;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
export const fromPage = (array: string) => {
|
|
827
|
+
let result: number[] = [];
|
|
828
|
+
|
|
829
|
+
for(let i = 0; i < array.length; i++){
|
|
830
|
+
let number = asciiTable.ascii.find(x=> x.char == array[i])?.code;
|
|
831
|
+
|
|
832
|
+
if(number == undefined)
|
|
833
|
+
console.log("warn, code number not found!");
|
|
834
|
+
|
|
835
|
+
result = [...result, number!];
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
return result;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
export const nestedComponents = (number: number[], currentFile: string = 'App.elen') => {
|
|
842
|
+
let content = fromAscii(number);
|
|
843
|
+
let roots = extractComponentTree(content);
|
|
844
|
+
|
|
845
|
+
const sourceBytes = fs.existsSync(currentFile)
|
|
846
|
+
? Array.from(fs.readFileSync(currentFile))
|
|
847
|
+
: number;
|
|
848
|
+
|
|
849
|
+
const result: Array<{
|
|
850
|
+
tree?: any[];
|
|
851
|
+
filepaths?: string[];
|
|
852
|
+
component: string;
|
|
853
|
+
valid?: boolean;
|
|
854
|
+
errors?: string[];
|
|
855
|
+
}> = [];
|
|
856
|
+
|
|
857
|
+
for(let root of roots){
|
|
858
|
+
try{
|
|
859
|
+
result.push(validateTemplate(sourceBytes, currentFile));
|
|
860
|
+
}catch(ex){
|
|
861
|
+
console.log(ex);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
return result;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
export function fromAscii(arr: number[]): string {
|
|
869
|
+
return String.fromCharCode(...arr);
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
export function fromString(text: string): number[] {
|
|
873
|
+
let result: number[] = [];
|
|
874
|
+
for(let i = 0; i < text.length; i++){
|
|
875
|
+
let code = asciiTable.ascii.find(x=> x.char == text[i])?.code;
|
|
876
|
+
result = [...result, code!];
|
|
877
|
+
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
let copyResult: number[] = [];
|
|
881
|
+
|
|
882
|
+
for(let num of result){
|
|
883
|
+
if(num != undefined){
|
|
884
|
+
copyResult = [...copyResult, num];
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
return copyResult;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
// extract all component tags in order (including nested)
|
|
892
|
+
function extractComponentTree(content: string) {
|
|
893
|
+
|
|
894
|
+
const tagRegex = /<\/?([A-Z][A-Za-z0-9_]*)\b/g;
|
|
895
|
+
|
|
896
|
+
const stack: any[] = [];
|
|
897
|
+
const roots: any[] = [];
|
|
898
|
+
|
|
899
|
+
let match;
|
|
900
|
+
|
|
901
|
+
while ((match = tagRegex.exec(content)) !== null) {
|
|
902
|
+
|
|
903
|
+
const name = match[1];
|
|
904
|
+
const isClosing = match[0][1] === "/";
|
|
905
|
+
|
|
906
|
+
if (!isClosing) {
|
|
907
|
+
const node = {
|
|
908
|
+
name,
|
|
909
|
+
children: []
|
|
910
|
+
};
|
|
911
|
+
|
|
912
|
+
if (stack.length > 0) {
|
|
913
|
+
stack[stack.length - 1].children.push(node);
|
|
914
|
+
} else {
|
|
915
|
+
roots.push(node);
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
stack.push(node);
|
|
919
|
+
} else {
|
|
920
|
+
// pop until matching tag
|
|
921
|
+
let i = stack.length - 1;
|
|
922
|
+
while (i >= 0) {
|
|
923
|
+
if (stack[i].name === name) {
|
|
924
|
+
stack.splice(i);
|
|
925
|
+
break;
|
|
926
|
+
}
|
|
927
|
+
i--;
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
return roots;
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
function validateTemplate(contentArray: number[], currentFile: string) {
|
|
936
|
+
|
|
937
|
+
const content = fromAscii(contentArray);
|
|
938
|
+
|
|
939
|
+
const importRegex =
|
|
940
|
+
/import\s+([A-Za-z0-9_]+)\s+from\s+['"]([^'"]+)['"]/g;
|
|
941
|
+
|
|
942
|
+
const componentRegex =
|
|
943
|
+
/@component\s+([A-Za-z0-9_]+)/g;
|
|
944
|
+
|
|
945
|
+
const imports = new Map<string, string>();
|
|
946
|
+
const declared = new Set<string>();
|
|
947
|
+
|
|
948
|
+
let match;
|
|
949
|
+
|
|
950
|
+
// imports
|
|
951
|
+
while ((match = importRegex.exec(content)) !== null) {
|
|
952
|
+
const name = match[1];
|
|
953
|
+
const importPath = match[2];
|
|
954
|
+
|
|
955
|
+
imports.set(
|
|
956
|
+
name,
|
|
957
|
+
path.resolve(path.dirname(currentFile), importPath)
|
|
958
|
+
);
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
// @component declarations
|
|
962
|
+
while ((match = componentRegex.exec(content)) !== null) {
|
|
963
|
+
declared.add(match[1]);
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
const tree = extractComponentTree(content);
|
|
967
|
+
|
|
968
|
+
const errors: string[] = [];
|
|
969
|
+
const filepaths: string[] = [];
|
|
970
|
+
let component: string = '';
|
|
971
|
+
|
|
972
|
+
function walk(node: any) {
|
|
973
|
+
|
|
974
|
+
const name = node.name;
|
|
975
|
+
component = name;
|
|
976
|
+
|
|
977
|
+
if (!imports.has(name)) {
|
|
978
|
+
errors.push(`${name} is not imported`);
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
if (!declared.has(name)) {
|
|
982
|
+
errors.push(`${name} missing @component`);
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
const importPath = imports.get(name);
|
|
986
|
+
|
|
987
|
+
if (importPath) {
|
|
988
|
+
const filePath = importPath.endsWith('.elen') ? importPath : importPath + ".elen";
|
|
989
|
+
filepaths.push(filePath);
|
|
990
|
+
|
|
991
|
+
if (!fs.existsSync(filePath)) {
|
|
992
|
+
errors.push(`${name} file not found: ${filePath}`);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
for (const child of node.children) {
|
|
997
|
+
walk(child);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
for (const root of tree) {
|
|
1002
|
+
walk(root);
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
return {
|
|
1006
|
+
tree,
|
|
1007
|
+
filepaths,
|
|
1008
|
+
component,
|
|
1009
|
+
valid: errors.length === 0,
|
|
1010
|
+
errors
|
|
1011
|
+
};
|
|
1012
|
+
}
|