STUDIO HAZE · image
Topaz source
Open by house policy. Topaz is our own language.
Topaz 5.21 · 113 files
topaz/src/printer_text.tpz
Topaz · 2225 B · Original file
1
// Linear source text accumulation used by the language printers.3
import print { 글자합치기 }5
export record 선형원본누적 {6
조각들: Array<string>,7
스칼라길이들: Array<int>,8
끝글들: Array<string>9
}11
export function 선형원본만들기() -> 선형원본누적 {12
선형원본누적 { 조각들: [], 스칼라길이들: [0], 끝글들: [""] }13
}15
export function 선형원본추가(원본: 선형원본누적, 글: string) {16
let 글자들 = 글.scalars()17
if 글자들.length == 0 { return }18
let mut 조각들 = 원본.조각들19
let mut 스칼라길이들 = 원본.스칼라길이들20
let mut 끝글들 = 원본.끝글들21
조각들.push(글)22
스칼라길이들[0] = 스칼라길이들[0] + 글자들.length23
끝글들[0] = 글자들[글자들.length - 1]24
}26
export function 선형원본끝공백제거(원본: 선형원본누적) {27
let mut 조각들 = 원본.조각들28
let mut 스칼라길이들 = 원본.스칼라길이들29
let mut 끝글들 = 원본.끝글들30
let mut 조각번호 = 조각들.length - 131
let mut 지운길이 = 032
let mut 남음 = false33
while 조각번호 >= 0 {34
let 글자들 = 조각들[조각번호].scalars()35
let mut 끝 = 글자들.length36
while 끝 > 0 {37
let 글자 = 글자들[끝 - 1]38
if 글자 != " " && 글자 != "\t" && 글자 != "\n" && 글자 != "\r" { break }39
끝 = 끝 - 140
}41
지운길이 = 지운길이 + 글자들.length - 끝42
if 끝 == 글자들.length {43
끝글들[0] = 글자들[끝 - 1]44
남음 = true45
break46
}47
조각들[조각번호] = if 끝 == 0 { "" } else {48
글자합치기(글자들, 0, 끝)49
}50
if 끝 > 0 {51
끝글들[0] = 글자들[끝 - 1]52
남음 = true53
break54
}55
조각번호 = 조각번호 - 156
}57
스칼라길이들[0] = 스칼라길이들[0] - 지운길이58
if !남음 { 끝글들[0] = "" }59
}61
export function 선형원본길이(원본: 선형원본누적) -> int { 원본.스칼라길이들[0] }63
export function 선형원본줄끝인가(원본: 선형원본누적) -> bool { 원본.끝글들[0] == "\n" }65
export function 선형원본평평하게(원본: 선형원본누적) -> string { 원본.조각들.join("") }SHA256 6e9fc56e390abf398ce6590b954cbf28f4589be882ed35336144d9a386d94e62