forked from robrobbins/specford
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiter_cli.js
More file actions
37 lines (30 loc) · 758 Bytes
/
iter_cli.js
File metadata and controls
37 lines (30 loc) · 758 Bytes
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
var fs = require('fs'),
util = require('util'),
L = require('./src/lexer'),
I = require('./src/iterator'),
l = new L(),
wrapLvl = 0,
indent, code, tokens, i, instructions, unwrap;
unwrap = function(arry) {
arry.forEach(function(item) {
if(item.indented) indent = item.indented;
if(Array.isArray(item)) {
unwrap(item);
} else {
console.log(printLvl() + item);
}
});
};
printLvl = function(item) {
var i, a = ['> '];
for(i = indent; i > 0; i--) {
a.unshift('-');
}
return a.join('');
};
code = fs.readFileSync('specs/' + process.argv[2], 'utf8');
tokens = l.tokenize(code);
i = new I();
instructions = i.makeInstructionSet(tokens);
// unwrap the nested queries and show them
unwrap(instructions);