codeimage.io

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.
3import print { 글자합치기 }
5export record 선형원본누적 {
6 조각들: Array<string>,
7 스칼라길이들: Array<int>,
8 끝글들: Array<string>
9}
11export function 선형원본만들기() -> 선형원본누적 {
12 선형원본누적 { 조각들: [], 스칼라길이들: [0], 끝글들: [""] }
15export function 선형원본추가(원본: 선형원본누적, 글: string) {
16 let 글자들 = 글.scalars()
17 if 글자들.length == 0 { return }
18 let mut 조각들 = 원본.조각들
19 let mut 스칼라길이들 = 원본.스칼라길이들
20 let mut 끝글들 = 원본.끝글들
21 조각들.push(글)
22 스칼라길이들[0] = 스칼라길이들[0] + 글자들.length
23 끝글들[0] = 글자들[글자들.length - 1]
26export function 선형원본끝공백제거(원본: 선형원본누적) {
27 let mut 조각들 = 원본.조각들
28 let mut 스칼라길이들 = 원본.스칼라길이들
29 let mut 끝글들 = 원본.끝글들
30 let mut 조각번호 = 조각들.length - 1
31 let mut 지운길이 = 0
32 let mut 남음 = false
33 while 조각번호 >= 0 {
34 let 글자들 = 조각들[조각번호].scalars()
35 let mut 끝 = 글자들.length
36 while 끝 > 0 {
37 let 글자 = 글자들[끝 - 1]
38 if 글자 != " " && 글자 != "\t" && 글자 != "\n" && 글자 != "\r" { break }
39 끝 = 끝 - 1
40 }
41 지운길이 = 지운길이 + 글자들.length - 끝
42 if 끝 == 글자들.length {
43 끝글들[0] = 글자들[끝 - 1]
44 남음 = true
45 break
46 }
47 조각들[조각번호] = if 끝 == 0 { "" } else {
48 글자합치기(글자들, 0, 끝)
49 }
50 if 끝 > 0 {
51 끝글들[0] = 글자들[끝 - 1]
52 남음 = true
53 break
54 }
55 조각번호 = 조각번호 - 1
56 }
57 스칼라길이들[0] = 스칼라길이들[0] - 지운길이
58 if !남음 { 끝글들[0] = "" }
61export function 선형원본길이(원본: 선형원본누적) -> int { 원본.스칼라길이들[0] }
63export function 선형원본줄끝인가(원본: 선형원본누적) -> bool { 원본.끝글들[0] == "\n" }
65export function 선형원본평평하게(원본: 선형원본누적) -> string { 원본.조각들.join("") }

SHA256 6e9fc56e390abf398ce6590b954cbf28f4589be882ed35336144d9a386d94e62