-
Notifications
You must be signed in to change notification settings - Fork 14
/
transformers.js
41 lines (29 loc) · 1.04 KB
/
transformers.js
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
export function stringToObjects (string) {
if(typeof string !== 'string' && string instanceof String === false) return string;
let transformed = [];
for (let symbol of string) transformed.push({symbol});
return transformed;
}
// TODO: continue here
export function normalizeSuccessorArrays () {
}
// transform p to {successor: p}
// if applicable also transform strings into array of {symbol: String} objects
// TODO: make more modular! dont have forceObjects in here
function normalizeProductionRightSide (p, forceObjects) {
if(p.hasOwnProperty('successors')) {
for (var i = 0; i < p.successors.length; i++) {
p.successors[i] = normalizeProductionRightSide(p.successors[i], forceObjects);
}
} else if(p.hasOwnProperty('successor') === false){
p = { successor: p };
}
if(forceObjects && p.hasOwnProperty('successor')) {
p.successor = stringToObjects(p.successor);
}
return p;
}
export function normalizeProduction (p, forceObjects) {
p[1] = normalizeProductionRightSide(p[1], forceObjects);
return p;
}