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

Method CompileTokMap

parse/parser/rule.go:418–439  ·  view source on GitHub ↗

CompileTokMap compiles first token map

(ps *State)

Source from the content-addressed store, hash-verified

416
417// CompileTokMap compiles first token map
418func (pr *Rule) CompileTokMap(ps *State) bool {
419 valid := true
420 pr.FiTokenMap = make(map[string]*Rule, len(pr.Children))
421 pr.FiTokenElseIndex = len(pr.Children)
422 for i, kpri := range pr.Children {
423 kpr := kpri.(*Rule)
424 if len(kpr.Rules) == 0 || !kpr.Rules[0].IsToken() {
425 pr.FiTokenElseIndex = i
426 break
427 }
428 fr := kpr.Rules[0]
429 skey := fr.Token.StringKey()
430 if _, has := pr.FiTokenMap[skey]; has {
431 ps.Error(lexer.PosZero, fmt.Sprintf("CompileFirstTokenMap: multiple rules have the same first token: %v -- must be unique -- use a :'tok' group to match that first token and put all the sub-rules as children of that node", fr.Token), pr)
432 pr.FiTokenElseIndex = 0
433 valid = false
434 } else {
435 pr.FiTokenMap[skey] = kpr
436 }
437 }
438 return valid
439}
440
441// CompileExcl compiles exclusionary rules starting at given point
442// currently only working for single-token matching rule

Callers 1

ValidateMethod · 0.95

Calls 3

IsTokenMethod · 0.80
StringKeyMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected