MatchExclude looks for matches of exclusion tokens -- if found, they exclude this rule return is true if exclude matches and rule should be excluded
(ps *State, scope lexer.Reg, ktpos lexer.Reg, depth int, optMap lexer.TokenMap)
| 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 |
| 1110 | func (pr *Rule) MatchExclude(ps *State, scope lexer.Reg, ktpos lexer.Reg, depth int, optMap lexer.TokenMap) bool { |
| 1111 | nf := len(pr.ExclFwd) |
| 1112 | nr := len(pr.ExclRev) |
| 1113 | scstlx := ps.Src.LexAt(scope.St) // scope starting lex |
| 1114 | scstDepth := scstlx.Token.Depth |
| 1115 | if nf > 0 { |
| 1116 | cp, ok := ps.Src.NextTokenPos(ktpos.St) |
| 1117 | if !ok { |
| 1118 | return false |
| 1119 | } |
| 1120 | prevAny := false |
| 1121 | for ri := 0; ri < nf; ri++ { |
| 1122 | rr := pr.ExclFwd[ri] |
| 1123 | kt := rr.Token |
| 1124 | kt.Depth += scstDepth // always use starting scope depth |
| 1125 | if kt.Token == token.None { |
| 1126 | prevAny = true // wild card |
| 1127 | continue |
| 1128 | } |
| 1129 | if prevAny { |
| 1130 | creg := scope |
| 1131 | creg.St = cp |
| 1132 | pos, ok := ps.FindToken(kt, creg) |
| 1133 | if !ok { |
| 1134 | return false |
| 1135 | } |
| 1136 | cp = pos |
| 1137 | } else { |
| 1138 | if !ps.MatchToken(kt, cp) { |
| 1139 | if !rr.Opt { |
| 1140 | return false |
| 1141 | } |
| 1142 | lx := ps.Src.LexAt(cp) |
| 1143 | if lx.Token.Depth != kt.Depth { |
| 1144 | break |
| 1145 | } |
| 1146 | // ok, keep going -- no info.. |
| 1147 | } |
| 1148 | } |
| 1149 | cp, ok = ps.Src.NextTokenPos(cp) |
| 1150 | if !ok && ri < nf-1 { |
| 1151 | return false |
| 1152 | } |
| 1153 | if scope.Ed == cp || scope.Ed.IsLess(cp) { // out of scope -- if non-opt left, nomatch |
| 1154 | ri++ |
| 1155 | for ; ri < nf; ri++ { |
| 1156 | rr := pr.ExclFwd[ri] |
| 1157 | if !rr.Opt { |
| 1158 | return false |
| 1159 | } |
| 1160 | } |
| 1161 | break |
| 1162 | } |
| 1163 | prevAny = false |
| 1164 | } |
| 1165 | } |
| 1166 | if nr > 0 { |
| 1167 | cp, ok := ps.Src.PrevTokenPos(ktpos.St) |
no test coverage detected