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

Method Match

parse/parser/rule.go:745–816  ·  view source on GitHub ↗

Match attempts to match the rule, returns true if it matches, and the match positions, along with any update to the scope

(ps *State, parAST *AST, scope lexer.Reg, depth int, optMap lexer.TokenMap)

Source from the content-addressed store, hash-verified

743// Match attempts to match the rule, returns true if it matches, and the
744// match positions, along with any update to the scope
745func (pr *Rule) Match(ps *State, parAST *AST, scope lexer.Reg, depth int, optMap lexer.TokenMap) (bool, lexer.Reg, Matches) {
746 if pr.Off {
747 return false, scope, nil
748 }
749
750 if depth > DepthLimit {
751 ps.Error(scope.St, "depth limit exceeded -- parser rules error -- look for recursive cases", pr)
752 return false, scope, nil
753 }
754
755 if ps.IsNonMatch(scope, pr) {
756 return false, scope, nil
757 }
758
759 if pr.StackMatch != "" {
760 if ps.Stack.Top() != pr.StackMatch {
761 return false, scope, nil
762 }
763 }
764
765 // mprf := profile.Start("Match")
766 // defer mprf.End()
767 // Note: uncomment the following to see which rules are taking the most
768 // time -- very helpful for focusing effort on optimizing those rules.
769 // prf := profile.Start(pr.Nm)
770 // defer prf.End()
771
772 nr := len(pr.Rules)
773 if pr.tokenMatchGroup || nr == 0 { // Group
774 return pr.MatchGroup(ps, parAST, scope, depth, optMap)
775 }
776
777 // prf := profile.Start("IsMatch")
778 if mst, match := ps.IsMatch(pr, scope); match {
779 // prf.End()
780 return true, scope, mst.Regs
781 }
782 // prf.End()
783
784 var mpos Matches
785 match := false
786
787 if pr.noTokens {
788 match, mpos = pr.MatchNoToks(ps, parAST, scope, depth, optMap)
789 } else if pr.onlyTokens {
790 match, mpos = pr.MatchOnlyToks(ps, parAST, scope, depth, optMap)
791 } else {
792 match, mpos = pr.MatchMixed(ps, parAST, scope, depth, optMap)
793 }
794 if !match {
795 ps.AddNonMatch(scope, pr)
796 return false, scope, nil
797 }
798
799 if len(pr.ExclFwd) > 0 || len(pr.ExclRev) > 0 {
800 ktpos := mpos[pr.ExclKeyIndex]
801 if pr.MatchExclude(ps, scope, ktpos, depth, optMap) {
802 if ps.Trace.On {

Callers 9

ParseRulesMethod · 0.95
EosDetectPosMethod · 0.45
MatchMixedMethod · 0.45
MatchNoToksMethod · 0.45
MatchGroupMethod · 0.45
FindKindMethod · 0.45
FindKindScopedMethod · 0.45
FindContainsRegionMethod · 0.45
InitMethod · 0.45

Calls 13

MatchGroupMethod · 0.95
MatchNoToksMethod · 0.95
MatchOnlyToksMethod · 0.95
MatchMixedMethod · 0.95
MatchExcludeMethod · 0.95
StartEndMethod · 0.95
IsNonMatchMethod · 0.80
AddNonMatchMethod · 0.80
AddMatchMethod · 0.80
ErrorMethod · 0.65
TopMethod · 0.45
IsMatchMethod · 0.45

Tested by

no test coverage detected