on master help sign in
Better indent parser
commit2d4ddd35456c36e4b2c8a9206da5bb712b17acfc authorDevine Lu Linvega <aliceffekt@gmail.com> dateMon 29 Jul 2019, 13:30 (7 years ago) parent03d9cc6
1 file changed+5−5
scripts/indental.js+5−5
scripts/indental.js+5−5
@@ -4,8 +4,7 @@ function indental (data, Type) {
44 function formatLine (line) {
55 const a = []
66 const h = {}
7− for (const id in line.children) {
8− const child = line.children[id]
7+ for (const child of line.children) {
98 if (child.key) {
109 if (h[child.key]) { console.warn(`Redefined key: ${child.key}.`) }
1110 h[child.key] = child.value
@@ -32,15 +31,14 @@ function indental (data, Type) {
3231 }
3332
3433 function skipLine (line) {
35− return line.trim() !== '' && line.substr(0, 1) !== ';'
34+ return line.trim() !== '' && line.substr(0, 1) !== ';' && line.trim().slice(-1) !== '`'
3635 }
3736
3837 const lines = data.split('\n').filter(skipLine).map(makeLine)
3938
4039 // Assoc
4140 const stack = {}
42− for (const id in lines) {
43− const line = lines[id]
41+ for (const line of lines) {
4442 const target = stack[line.indent - 2]
4543 if (target) { target.children.push(line) }
4644 stack[line.indent] = line
@@ -57,3 +55,5 @@ function indental (data, Type) {
5755 }
5856 return h
5957}
58+
59+module.exports = indental