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

Method MatchGroup

parse/parser/rule.go:1068–1106  ·  view source on GitHub ↗

MatchGroup does matching for Group rules

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

Source from the content-addressed store, hash-verified

1066
1067// MatchGroup does matching for Group rules
1068func (pr *Rule) MatchGroup(ps *State, parAST *AST, scope lexer.Reg, depth int, optMap lexer.TokenMap) (bool, lexer.Reg, Matches) {
1069 // prf := profile.Start("SubMatch")
1070 if mst, match := ps.IsMatch(pr, scope); match {
1071 // prf.End()
1072 return true, scope, mst.Regs
1073 }
1074 // prf.End()
1075 sti := 0
1076 nk := len(pr.Children)
1077 if pr.FirstTokenMap {
1078 stlx := ps.Src.LexAt(scope.St)
1079 if kpr, has := pr.FiTokenMap[stlx.Token.StringKey()]; has {
1080 match, nscope, mpos := kpr.Match(ps, parAST, scope, depth+1, optMap)
1081 if match {
1082 if ps.Trace.On {
1083 ps.Trace.Out(ps, pr, SubMatch, scope.St, scope, parAST, fmt.Sprintf("first token group child: %v", kpr.Name))
1084 }
1085 ps.AddMatch(pr, scope, mpos)
1086 return true, nscope, mpos
1087 }
1088 }
1089 sti = pr.FiTokenElseIndex
1090 }
1091
1092 for i := sti; i < nk; i++ {
1093 kpri := pr.Children[i]
1094 kpr := kpri.(*Rule)
1095 match, nscope, mpos := kpr.Match(ps, parAST, scope, depth+1, optMap)
1096 if match {
1097 if ps.Trace.On {
1098 ps.Trace.Out(ps, pr, SubMatch, scope.St, scope, parAST, fmt.Sprintf("group child: %v", kpr.Name))
1099 }
1100 ps.AddMatch(pr, scope, mpos)
1101 return true, nscope, mpos
1102 }
1103 }
1104 ps.AddNonMatch(scope, pr)
1105 return false, scope, nil
1106}
1107
1108// MatchExclude looks for matches of exclusion tokens -- if found, they exclude this rule
1109// return is true if exclude matches and rule should be excluded

Callers 1

MatchMethod · 0.95

Calls 7

LexAtMethod · 0.80
StringKeyMethod · 0.80
AddMatchMethod · 0.80
AddNonMatchMethod · 0.80
IsMatchMethod · 0.45
MatchMethod · 0.45
OutMethod · 0.45

Tested by

no test coverage detected