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

Method CompileExcl

parse/parser/rule.go:443–512  ·  view source on GitHub ↗

CompileExcl compiles exclusionary rules starting at given point currently only working for single-token matching rule

(ps *State, rs []string, rist int)

Source from the content-addressed store, hash-verified

441// CompileExcl compiles exclusionary rules starting at given point
442// currently only working for single-token matching rule
443func (pr *Rule) CompileExcl(ps *State, rs []string, rist int) bool {
444 valid := true
445 nr := len(rs)
446 var ktok token.KeyToken
447
448 ktoki := -1
449 for ri := 0; ri < rist; ri++ {
450 rr := &pr.Rules[ri]
451 if !rr.IsToken() {
452 continue
453 }
454 ktok = rr.Token
455 ktoki = ri
456 break
457 }
458
459 if ktoki < 0 {
460 ps.Error(lexer.PosZero, "CompileExcl: no token found for matching exclusion rules", pr)
461 return false
462 }
463
464 pr.ExclRev = make(RuleList, nr-rist)
465 ki := -1
466 for ri := rist; ri < nr; ri++ {
467 rn := strings.TrimSpace(rs[ri])
468 rr := &pr.ExclRev[ri-rist]
469 if rn[0] == '?' {
470 rr.Opt = true
471 }
472 tokst := strings.Index(rn, "'")
473 if tokst < 0 {
474 continue // pure optional
475 }
476 if !rr.Opt {
477 rr.Match = true // all tokens match by default
478 }
479 sz := len(rn)
480 if rn[0] == '+' {
481 td, _ := strconv.ParseInt(rn[1:tokst], 10, 64)
482 rr.Token.Depth = int(td)
483 }
484 tn := rn[tokst+1 : sz-1]
485 if len(tn) > 4 && tn[:4] == "key:" {
486 rr.Token.Token = token.Keyword
487 rr.Token.Key = tn[4:]
488 } else {
489 if pmt, has := token.OpPunctMap[tn]; has {
490 rr.Token.Token = pmt
491 } else {
492 err := rr.Token.Token.SetString(tn)
493 if err != nil {
494 ps.Error(lexer.PosZero, fmt.Sprintf("CompileExcl: token convert error: %v", err.Error()), pr)
495 valid = false
496 }
497 }
498 }
499 if rr.Token.Equal(ktok) {
500 ki = ri

Callers 1

CompileMethod · 0.95

Calls 5

IsTokenMethod · 0.80
EqualMethod · 0.80
ErrorMethod · 0.65
SetStringMethod · 0.65
IndexMethod · 0.45

Tested by

no test coverage detected