scratch – Blame information for rev 66
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
66 | office | 1 | function assemble(ast) { |
2 | var result; |
||
3 | |||
4 | if (!ast) { |
||
5 | return ast; |
||
6 | } |
||
7 | |||
8 | if (!ast.constructor || !ast.constructor.name) { |
||
9 | return ast.value; |
||
10 | } |
||
11 | |||
12 | switch (ast.constructor.name){ |
||
13 | case 'String': |
||
14 | result = ast; |
||
15 | break; |
||
16 | case 'YAMLDoc': |
||
17 | result = assemble(ast.value); |
||
18 | break; |
||
19 | case 'YAMLHash': |
||
20 | result = {}; |
||
21 | ast.keys.forEach(function (key){ |
||
22 | result[key.keyName] = assemble(key.value); |
||
23 | }); |
||
24 | break; |
||
25 | case 'YAMLList': |
||
26 | result = []; |
||
27 | ast.items.forEach(function (item){ |
||
28 | result.push(assemble(item)); |
||
29 | }); |
||
30 | break; |
||
31 | default: |
||
32 | result = ast.value; |
||
33 | |||
34 | } |
||
35 | |||
36 | return result; |
||
37 | } |
||
38 | |||
39 | |||
40 | module.exports = assemble; |