-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.js
49 lines (47 loc) · 1.22 KB
/
main.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
42
43
44
45
46
47
48
49
const parser = require("./agg_pipeline.js")
const fs = require("fs")
function cleanWhiteSpace(s) {
var ret = ''
var inDString = false
var inSString = false
for (var i = 0, len = s.length; i < len; i++) {
var ch = s.charAt(i)
if (ch === '\\') {
ret += ch
i++
ret += s.charAt(i)
continue
}
if (inDString) {
if (ch === '"') {
inDString = false
}
ret += ch
} else if (inSString) {
if (ch === "'") {
inSString = false
}
ret += ch
} else {
if (ch === '"') {
inDString = true
ret += ch
} else if (ch === "'") {
inSString = true
ret += ch
} else if (ch === ' ' || ch === "\t" || ch === "\n" || ch === "\r") {
continue
} else {
ret += ch
}
}
}
return ret
}
if (process.argv.length < 3) {
console.log("Must pass a file to parse")
} else {
var input = cleanWhiteSpace(fs.readFileSync(process.argv[2]).toString())
var output = parser.parse(input)
console.log(JSON.stringify(output, null, 4))
}