1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301 | 1
1
1
1
1
1
1
1
1
1
257
209
54
12
42
155
48
45
3
1
1
68
68
68
68
68
68
1
1
20
192
192
192
192
38
192
192
192
192
192
244
244
42
42
12
12
157
157
128
157
68
68
68
157
22
22
22
22
22
22
53
22
22
22
22
8
8
8
8
8
8
8
3
3
3
3
3
3
192
192
192
192
8
8
8
192
3
3
192
192
1
1
107
107
107
107
107
107
107
107
337
337
19
19
1
19
107
101
124
124
124
11
1
11
2
9
7
2
107
107
107
1
106
21
85
3
82
1
20
20
20
107
107
107
107
107
107
107
42
42
42
2
2
2
2
2
1
2
2
40
21
107
107
42
8
8
34
107
16
107
44
63
24
63
63
63
63
63
1
1
1
1
1
| var optionsParser = require("../utils/optionsParser");
var Iterator = optionsParser.Iterator;
var parser = require("../parser");
var sanitizer = require("./sanitizer");
var GraphModule = require("../../common/graph");
var Boundary = GraphModule.Boundary;
var Graph = GraphModule.Graph;
var Connection = GraphModule.Connection;
var FileComponent = GraphModule.FileComponent;
function typeOf(arg) {
if (typeof arg === 'string' && arg.length > 0) {
if (arg[0] === '-' && arg.length > 1) {
if (arg[1] === '-') {
return 'longOption';
} else
return 'shortOptions';
} else {
return 'string';
}
} else if (arg instanceof Array) {
return arg[0];
} else
return 'string';
}
exports.typeOf = typeOf;
/*getComponentById = function(visualData, id){
var i$, ref$, len$, x;
for (i$ = 0, len$ = (ref$ = visualData.components).length; i$ < len$; ++i$) {
x = ref$[i$];
if (x.id === id) {
return x;
}
}
return null;
};*/
/**
Adds a file component to the
*/
function addFileComponent(componentData, connections, filename, id) {
var newComponent = new FileComponent(filename);
newComponent.id = id;
var inputPort = "file" + (componentData.files.length);
connections.push(new Connection(newComponent, 'output', componentData, inputPort));
componentData.files.push(filename);
return newComponent;
}
exports.addFileComponent = addFileComponent;
;
/*var commonNodeParsing = {
string: function(options){
return addFileComponent(options, options.iterator.current);
},
shortOptions: function(options){
return addFileComponent(options, options.iterator.current);
},
longOption: function(options){
return addFileComponent(options, options.iterator.current);
}
};*/
/**
Algorthm commonly used to parse commands
*/
function commonParseCommand(optionsParserData, defaultComponentData, argNodeParsing) {
return function (argsNode, parser, tracker, previousCommand) {
var stdoutRedirection, stderrRedirection, argNode, newComponent, inputPort, subresult, ref$, y;
var componentData = defaultComponentData();
var boundaries = [];
if (previousCommand) {
boundaries.push(previousCommand[0]);
}
var result = new Graph();
result.components = [componentData];
result.firstMainComponent = componentData;
var iter = new Iterator(argsNode);
while (iter.hasNext()) {
var argNode = iter.next();
switch (exports.typeOf(argNode)) {
case 'shortOptions':
optionsParser.parseShortOptions(optionsParserData, componentData, iter);
break;
case 'longOption':
optionsParser.parseLongOptions(optionsParserData, componentData, iter);
break;
case 'string':
var addfile = true;
if (argNodeParsing && argNodeParsing.string) {
addfile = argNodeParsing.string(componentData, argNode) == "continue";
}
if (addfile) {
newComponent = exports.addFileComponent(componentData, result.connections, argNode, tracker.id++);
result.components.push(newComponent);
boundaries.push(Boundary.createFromComponent(newComponent));
}
break;
case 'inFromProcess':
subresult = parser.parseAST(argNode[1], tracker);
boundaries.push(Boundary.createFromComponents(subresult.components));
result.expand(subresult);
inputPort = "file" + componentData.files.length;
var subComponents = subresult.components;
for (var i = subComponents.length - 1; i >= 0; i--) {
if (subComponents[i].id == tracker.id - 1) {
result.connections.push(new Connection(subComponents[i], 'output', componentData, inputPort));
break;
}
}
componentData.files.push(["pipe", tracker.id - 1]);
break;
case 'outToFile':
newComponent = new FileComponent(argNode[1]);
newComponent.id = tracker.id;
result.connections.push(new Connection(componentData, 'output', newComponent, 'input'));
tracker.id++;
result.components.push(newComponent);
stdoutRedirection = newComponent;
break;
case 'errToFile':
newComponent = new FileComponent(argNode[1]);
newComponent.id = tracker.id;
result.connections.push(new Connection(componentData, 'error', newComponent, 'input'));
tracker.id++;
result.components.push(newComponent);
stderrRedirection = newComponent;
}
}
var bbox = Boundary.arrangeLayout(boundaries);
componentData.position = bbox[1];
componentData.id = tracker.id;
if (stdoutRedirection) {
var position = stdoutRedirection.position;
position.x = bbox[1].x + 400;
position.y = bbox[1].y;
}
if (stderrRedirection) {
y = stdoutRedirection ? 100 : 0;
stderrRedirection.position = {
x: bbox[1].x + 400,
y: bbox[1].y + y
};
}
//result.connections = result.connections.concat(connections.toConnectionList());
tracker.id++;
return [bbox[0], result];
};
}
exports.commonParseCommand = commonParseCommand;
;
function parseFlagsAndSelectors(component, options) {
var key, selectors, value, flag, flags, that, val;
var flagOptions = options.flagOptions;
var selectorOptions = options.selectorOptions;
var sFlags = [];
var lFlags = [];
var resultSFlags;
var resultLFlags;
for (key in flags = component.flags) {
value = flags[key];
if (value) {
flag = flagOptions[key];
/* istanbul ignore if */ Iif (!flag) {
throw [key, "doesn't exist in ", flagOptions].join('');
} else
sFlags.push(flag);
}
}
if (component.selectors) {
for (key in selectors = component.selectors) {
value = selectors[key];
var optionValue = selectorOptions[key][value.name];
if (optionValue != null) {
/* istanbul ignore if */ Iif (!optionValue) {
throw [key, ".", value, "doesn't exist in ", selectorOptions].join('');
} else if (value.type == "numeric parameter") {
lFlags.push("-" + optionValue + value.value);
} else if (optionValue[0] !== '-') {
sFlags.push(optionValue);
} else {
lFlags.push(optionValue);
}
}
}
}
var containsSFlags = sFlags.length > 0;
var containsLFlags = lFlags.length > 0;
if (containsSFlags && containsLFlags) {
return "-" + sFlags.join('') + " " + lFlags.join(' ');
} else if (containsSFlags) {
return "-" + sFlags.join('');
} else if (containsLFlags) {
return lFlags.join(' ');
} else
return "";
}
;
/**
Algorthm commonly used to parse components
the parsing of the flags and selectos are on a different function "parseFlagsAndSelectors"
*/
function commonParseComponent(flagOptions, selectorOptions, parameterOptions, beforeJoin) {
var options;
options = {
flagOptions: flagOptions,
selectorOptions: selectorOptions,
parameterOptions: parameterOptions
};
return function (component, visualData, componentIndex, mapOfParsedComponents) {
var exec = [component.exec];
var flags = parseFlagsAndSelectors(component, options);
var parameters = [];
var Componentparameters = component.parameters;
var result;
mapOfParsedComponents[component.id] = true;
for (var key in Componentparameters) {
var value = Componentparameters[key];
var option = parameterOptions[key];
if (option && value) {
var parameterOption = parameterOptions[key];
Iif (parameterOption[0] == "-") {
result = parameterOption;
} else {
result = "-" + parameterOption;
}
var sanitizedVal = sanitizer.sanitizeArgument(value);
if (parameterOption[0] == "-" || sanitizer.sanitizedWithSingleQuotes(sanitizedVal)) {
result += " ";
}
result += sanitizedVal;
parameters.push(result);
} else if (value) {
parameters.push(sanitizer.sanitizeArgument(value));
}
}
console.log(":::parameters:::", parameters);
var files = !component.files ? [] : component.files.map(function (file) {
if (file instanceof Array) {
var subCommand = parser.parseVisualDatafromComponent(componentIndex.components[file[1]], visualData, componentIndex, mapOfParsedComponents);
return "<(" + subCommand + ")";
} else
return sanitizer.sanitizeArgument(file);
});
if (parameters.length > 0) {
parameters = parameters.join(' ');
}
if (beforeJoin) {
return beforeJoin(component, exec, flags, files, parameters);
} else {
if (flags) {
exec = exec.concat(flags);
}
Eif (parameters) {
exec = exec.concat(parameters);
}
Eif (files) {
exec = exec.concat(files);
}
return exec.join(' ');
}
};
}
exports.commonParseComponent = commonParseComponent;
;
exports.select = optionsParser.select;
exports.sameAs = optionsParser.sameAs;
exports.switchOn = optionsParser.switchOn;
exports.select = optionsParser.select;
|