on master help sign in
Better indent parser
2d4ddd3Devine Lu Linvega
scripts/indental.js+5−5
@@ -4,8 +4,7 @@ function indental (data, Type) {
4 function formatLine (line) {
4 function formatLine (line) {
5 const a = []
5 const a = []
6 const h = {}
6 const h = {}
7− for (const id in line.children) {
7+ for (const child of line.children) {
8− const child = line.children[id]
9 if (child.key) {
8 if (child.key) {
10 if (h[child.key]) { console.warn(`Redefined key: ${child.key}.`) }
9 if (h[child.key]) { console.warn(`Redefined key: ${child.key}.`) }
11 h[child.key] = child.value
10 h[child.key] = child.value
@@ -32,15 +31,14 @@ function indental (data, Type) {
32 }
31 }
33
32
34 function skipLine (line) {
33 function skipLine (line) {
35− return line.trim() !== '' && line.substr(0, 1) !== ';'
34+ return line.trim() !== '' && line.substr(0, 1) !== ';' && line.trim().slice(-1) !== '`'
36 }
35 }
37
36
38 const lines = data.split('\n').filter(skipLine).map(makeLine)
37 const lines = data.split('\n').filter(skipLine).map(makeLine)
39
38
40 // Assoc
39 // Assoc
41 const stack = {}
40 const stack = {}
42− for (const id in lines) {
41+ for (const line of lines) {
43− const line = lines[id]
44 const target = stack[line.indent - 2]
42 const target = stack[line.indent - 2]
45 if (target) { target.children.push(line) }
43 if (target) { target.children.push(line) }
46 stack[line.indent] = line
44 stack[line.indent] = line
@@ -57,3 +55,5 @@ function indental (data, Type) {
57 }
55 }
58 return h
56 return h
59}
57}
58+
59+module.exports = indental