@@ -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
101112proc 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
115124proc 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