CompileTokMap compiles first token map
(ps *State)
| 416 | |
| 417 | // CompileTokMap compiles first token map |
| 418 | func (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 |