Skip to content

Commit

Permalink
[FORMAT] Handle more corner cases
Browse files Browse the repository at this point in the history
  • Loading branch information
PeyTy committed Jun 21, 2024
1 parent 4c68f39 commit 1bf5a68
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions source/server/format.hexa
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ fun autoFormatWholeFile(file: String): String {
var tabStack = ['']
var tabCase = [false]
var depth = 0
let assignOp = [Token.Add, Token.Multiply, Token.Subtract]

fun updateTab() {
tabs = tabStack.slice(0, depth + 1).join('')
Expand Down Expand Up @@ -89,15 +90,40 @@ fun autoFormatWholeFile(file: String): String {
result.push(tabs)
shouldSpace = false
}

lastLine = line

if
// TODO #if
// TODO @dec
// TODO (\nargs\n)
// TODO if\nconds\n{}
lastToken == Token.Eof or
lastToken == Token.Dot or
token == Token.Dot or

(token == Token.Assign and assignOp.includes(lastToken)) or

lastToken == Token.CallOpen or
token == Token.CallOpen or
(
token == Token.CallOpen and
(
lastToken != Token.KIf and
lastToken != Token.Assign
)
) or
token == Token.CallClose or

lastToken == Token.IndexOpen or
(
token == Token.IndexOpen and
(
lastToken == Token.Identifier or
lastToken == Token.IndexClose
)
) or
token == Token.IndexClose or

token == Token.KNot or
token == Token.Comma or
token == Token.Colon
Expand All @@ -110,7 +136,12 @@ fun autoFormatWholeFile(file: String): String {
}

// TODO preserve string double/single quotes as Meta
result.push(Token.stringify(token, tokens.value[i]))
switch token {
case LogicalAnd: result.push('and')
case LogicalOr: result.push('or')
case _: result.push(Token.stringify(token, tokens.value[i]))
}

lastToken = token

switch token {
Expand All @@ -119,6 +150,8 @@ fun autoFormatWholeFile(file: String): String {
case BlockClose:
case KCase:
appendTab()
case KIf:
// TODO appendTab()
}
}

Expand Down

0 comments on commit 1bf5a68

Please sign in to comment.