Skip to content

Commit 8b23beb

Browse files
committed
[FORMAT] Fix multiline strings
1 parent 472ebb5 commit 8b23beb

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

source/compiler/lexer.hexa

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Tokens {
2323
// TODO var kind: Buffer // let = new.
2424
// Values of an unique lexemes, like integers and strings
2525
var value: [String]
26+
// TODO would be faster for both native and js to store all into array of structures
2627
var meta: [Meta]
2728
var length: Int
2829
var line: [Int]
@@ -94,6 +95,15 @@ class Lexer {
9495
add(t)
9596
}
9697

98+
/// Add parametrized token that can cover multiple lines
99+
@inline fun addMultiline(t: Token, param: String, m: Meta, line: Int, column: Int) {
100+
params[to] = param
101+
meta[to] = m
102+
tokens[to++] = t
103+
lines.push(line)
104+
columns.push(column)
105+
}
106+
97107
@inline fun curPos() {
98108
return position - columnBase - 1
99109
}
@@ -349,6 +359,8 @@ class Lexer {
349359
let p = _8 // Remember, if double/single-quoted
350360
position++
351361
let pos = position
362+
let column = position - columnBase - 1
363+
let line = line // TODO same for /* comments */
352364

353365
// We don't do string \() interpolation here,
354366
// coz pretty printer
@@ -372,9 +384,10 @@ class Lexer {
372384
}
373385

374386
if format {
375-
addMeta(Token.QuotedString, result, p as! Meta)
387+
addMultiline(Token.QuotedString, result, p as! Meta, line, column)
376388
} else {
377-
addWith(Token.QuotedString, result)
389+
addMultiline(Token.QuotedString, result, p as! Meta, line, column)
390+
// TODO short path really needed? addWith(Token.QuotedString, result)
378391
}
379392
position++
380393
continue

source/data/token.hexa

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ enum Meta : #if native UInt8 #else Int #end {
264264
// Float64 -> Float is 64-bit by Default
265265

266266
/// `'`
267+
// TODO `= '"'.meta.charCode`
267268
SingleQuote = 39 // ASCII
268269
/// `"`
269270
DoubleQuote = 34 // ASCII

source/server/format.hexa

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
/// Formatting preserves user personal style
1717
// TODO hexa format cli .hexa .json
18+
// TODO cover in testFormat.hexa
1819
fun autoFormatWholeFile(file: String): String {
1920
let project = new Project()
2021
let content = Buffer.from(file)
@@ -113,8 +114,6 @@ fun autoFormatWholeFile(file: String): String {
113114
shouldSpace = false
114115
}
115116

116-
lastLine = line
117-
118117
if
119118
// `#if`
120119
lastToken == Token.Sharp or
@@ -327,6 +326,15 @@ fun autoFormatWholeFile(file: String): String {
327326
pushTab()
328327
parenthesis = 0
329328
}
329+
330+
lastLastLine = lastLine
331+
lastLine = line
332+
333+
// TODO not typed if let value = tokens.value[i], value.assaDADADADncludes('\n') {
334+
if let value = tokens.value[i], value.includes('\n') {
335+
// TODO String.count('\n')
336+
lastLine += value.split('\n').length - 1
337+
}
330338
}
331339

332340
// TODO (when) use CRLF? or it seems vscode fixes it on its own

0 commit comments

Comments
 (0)