MCPcopy Create free account
hub / github.com/cogentcore/core / FindToken

Method FindToken

parse/parser/state.go:195–216  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

193// Only matches when depth is same as at reg.St start at the start of the search.
194// All positions in token indexes.
195func (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!

Callers 3

MatchTokenMethod · 0.80
MatchExcludeMethod · 0.80
DoRulesMethod · 0.80

Calls 7

MatchLexMethod · 0.95
ValidTokenPosMethod · 0.80
IsLessMethod · 0.80
LexAtMethod · 0.80
NextTokenPosMethod · 0.80
CatMethod · 0.45
SubCatMethod · 0.45

Tested by

no test coverage detected