FindToken looks for token in given region, returns position where found, false if not. Only matches when depth is same as at reg.St start at the start of the search. All positions in token indexes.
(tkey token.KeyToken, reg lexer.Reg)
| 193 | // Only matches when depth is same as at reg.St start at the start of the search. |
| 194 | // All positions in token indexes. |
| 195 | func (ps *State) FindToken(tkey token.KeyToken, reg lexer.Reg) (lexer.Pos, bool) { |
| 196 | // prf := profile.Start("FindToken") |
| 197 | // defer prf.End() |
| 198 | cp, ok := ps.Src.ValidTokenPos(reg.St) |
| 199 | if !ok { |
| 200 | return cp, false |
| 201 | } |
| 202 | tok := tkey.Token |
| 203 | isCat := tok.Cat() == tok |
| 204 | isSubCat := tok.SubCat() == tok |
| 205 | for cp.IsLess(reg.Ed) { |
| 206 | lx := ps.Src.LexAt(cp) |
| 207 | if ps.MatchLex(lx, tkey, isCat, isSubCat, cp) { |
| 208 | return cp, true |
| 209 | } |
| 210 | cp, ok = ps.Src.NextTokenPos(cp) |
| 211 | if !ok { |
| 212 | return cp, false |
| 213 | } |
| 214 | } |
| 215 | return cp, false |
| 216 | } |
| 217 | |
| 218 | // MatchToken returns true if token matches at given position -- must be |
| 219 | // a valid position! |
no test coverage detected