Skip to content

Commit 87700f2

Browse files
committed
[Prettify] Tabs
1 parent 786b7f1 commit 87700f2

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

source/server/prettify.hexa

+30-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@
1717
/// Preserves user personal style to some degree
1818
// TODO ^
1919
class Prettify {
20+
var tabs = ''
21+
22+
@inline fun pushTab() {
23+
tabs += '\t'
24+
}
25+
26+
@inline fun popTab() {
27+
tabs = tabs.substring(0, tabs.length - 1)
28+
}
29+
2030
new () {
2131
// Initializes state for nested blocks indentation
2232
}
@@ -47,7 +57,11 @@ class Prettify {
4757
// TODO remove `:` here!
4858
case Block(el):
4959
// TODO depth!
50-
return `{\n\t` + el.map(e => this.stringify(e)).join('\n\t') + `\n}`
60+
pushTab()
61+
let body = `{\n` + tabs + el.map(e => this.stringify(e)).join('\n' + tabs)
62+
popTab()
63+
64+
return body + `\n` + tabs + `}`
5165

5266
/// `if condition[0], ...condition[n] { then } [else { otherwise }]`
5367
case If(condition, then, otherwise, ternary):
@@ -119,7 +133,13 @@ class Prettify {
119133
/// `external class t extends extend implements implement { fields }`
120134
// TODO IDE: hover over `(className)` in the pattern itself must show its type
121135
case Class(className, extend, implement, fields, external, kind):
122-
return 'class ' + NodeType.stringify(className) + ' ' + (extend ? 'extends ' + extend : '') + (implement.length > 0 ? 'implements ' + implement : '') + ' {\n' + fields.map(f => this.stringify(f)).join('\n') + '\n}'
136+
let head = 'class ' + NodeType.stringify(className) + ' ' + (extend ? 'extends ' + extend : '') + (implement.length > 0 ? 'implements ' + implement : '')
137+
138+
pushTab()
139+
let body = '{\n' + tabs + fields.map(f => this.stringify(f)).join('\n' + tabs) + '\n}'
140+
popTab()
141+
142+
return head + body
123143

124144
/// var name T { get { return x } set (v) {} }
125145
// TODO .Var, .Function, .Function
@@ -143,8 +163,14 @@ class Prettify {
143163
/// case cases[n]: conditions[n]
144164
/// }
145165
case Switch(inputs , expressions , guards , patterns ):
146-
return 'switch ' + [for i in inputs.length this.stringify(inputs[i])].join(', ') + ' {\n' +
147-
[for i in patterns.length 'case ' + this.stringify(expressions[i]) + ': ' + this.stringify(patterns[i])].join('\n') + '\n}'
166+
let head = 'switch ' + inputs.map(i => this.stringify(i)).join(', ') + ' {\n'
167+
168+
pushTab()
169+
let body =
170+
[for i in patterns.length tabs + 'case ' + this.stringify(expressions[i]) + ': ' + this.stringify(patterns[i])].join('\n')
171+
popTab()
172+
173+
return head + body + '\n' + tabs + '}'
148174

149175
/// module path[0].path[1].r..path[n] { el }
150176
case Module(path , el ):

0 commit comments

Comments
 (0)