Skip to content

Commit f131101

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

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

compiler/llstream.nim

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,32 +90,41 @@ const
9090
"let", "var", "const", "type", # section
9191
"object", "tuple",
9292
# from ./layouter.oprSet
93-
"div", "mod", "shl", "shr", "in", "not_in", "is",
94-
"is_not", "not", "of", "as", "from", "..", "and", "or", "xor",
95-
]
93+
"div", "mod", "shl", "shr", "in", "notin", "is",
94+
"isnot", "not", "of", "as", "from", "..", "and", "or", "xor",
95+
] # must be all `nimIdentNormalized`-ed
9696

97-
proc endsWith(s, subs: string, endIdx: var int): bool =
97+
proc eqIdent(a, bNormalized: string): bool =
98+
a.nimIdentNormalize == bNormalized
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)