Skip to content

Commit e72d215

Browse files
committed
feat(repl): continueLine figures section, constr, bool ops
1 parent 9055812 commit e72d215

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

compiler/llstream.nim

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import
1313
pathutils
14-
14+
import std/strutils
1515
when defined(nimPreviewSlimSystem):
1616
import std/syncio
1717

@@ -86,14 +86,46 @@ const
8686
LineContinuationOprs = {'+', '-', '*', '/', '\\', '<', '>', '!', '?', '^',
8787
'|', '%', '&', '$', '@', '~', ','}
8888
AdditionalLineContinuationOprs = {'#', ':', '='}
89+
LineContinuationTokens = [
90+
"let", "var", "const", "type", # section
91+
"object", "tuple",
92+
"and", "or", "xor",
93+
]
94+
95+
proc endsWith(s, subs: string, endIdx: var int): bool =
96+
endIdx.dec subs.len
97+
result = s.continuesWith(subs, endIdx+1)
98+
99+
proc containsObjectOf(x: string): bool =
100+
const sep = ' '
101+
var idx = x.rfind(sep)
102+
if idx == -1: return
103+
104+
template eatWord(word) =
105+
while x[idx] == sep: idx.dec
106+
result = x.endsWith(word, idx)
107+
if not result: return
108+
109+
eatWord "of"
110+
eatWord "object"
111+
result = true
112+
113+
proc endsWithLineContinuationToken(x: string): bool =
114+
result = false
115+
for tok in LineContinuationTokens:
116+
if x.endsWith(tok):
117+
return true
118+
result = x.containsObjectOf
89119

90120
proc endsWithOpr*(x: string): bool =
91121
result = x.endsWith(LineContinuationOprs)
92122

93123
proc continueLine(line: string, inTripleString: bool): bool {.inline.} =
94124
result = inTripleString or line.len > 0 and (
95125
line[0] == ' ' or
96-
line.endsWith(LineContinuationOprs+AdditionalLineContinuationOprs))
126+
line.endsWith(LineContinuationOprs+AdditionalLineContinuationOprs) or
127+
line.endsWithLineContinuationToken()
128+
)
97129

98130
proc countTriples(s: string): int =
99131
result = 0

0 commit comments

Comments
 (0)