Skip to content

Commit 17f3c50

Browse files
committed
fixup(repl): perform nimIdentNormalize for eqIdent
1 parent 69f202c commit 17f3c50

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

compiler/llstream.nim

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,28 +94,37 @@ const
9494
"is_not", "not", "of", "as", "from", "..", "and", "or", "xor",
9595
]
9696

97-
proc endsWith(s, subs: string, endIdx: var int): bool =
97+
proc eqIdent(a, b: string): bool =
98+
a.nimIdentNormalize == b.nimIdentNormalize
99+
100+
proc endsWithIdent(s, subs: string): bool =
101+
let le = subs.len
102+
if le > s.len: return false
103+
s[^le .. ^1].eqIdent subs
104+
105+
proc continuesWithIdent(s, subs: string, start: int): bool =
106+
s.substr(start, start+subs.high).eqIdent subs
107+
108+
proc endsWithIdent(s, subs: string, endIdx: var int): bool =
98109
endIdx.dec subs.len
99-
result = s.continuesWith(subs, endIdx+1)
110+
result = s.continuesWithIdent(subs, endIdx+1)
100111

101112
proc containsObjectOf(x: string): bool =
102113
const sep = ' '
103114
var idx = x.rfind(sep)
104115
if idx == -1: return
105-
106116
template eatWord(word) =
107117
while x[idx] == sep: idx.dec
108-
result = x.endsWith(word, idx)
118+
result = x.endsWithIdent(word, idx)
109119
if not result: return
110-
111120
eatWord "of"
112121
eatWord "object"
113122
result = true
114123

115124
proc endsWithLineContinuationToken(x: string): bool =
116125
result = false
117126
for tok in LineContinuationTokens:
118-
if x.endsWith(tok):
127+
if x.endsWithIdent(tok):
119128
return true
120129
result = x.containsObjectOf
121130

0 commit comments

Comments
 (0)