Added field to Reg, denoting if we prefer longest match (POSIX style) or not (perl style)

implementPCREMatchingRules
Aadhavan Srinivasan 4 weeks ago
parent 47f88c817f
commit 9e12f9dcb3

@ -17,6 +17,7 @@ type Reg struct {
start *nfaState start *nfaState
numGroups int numGroups int
str string str string
preferLongest bool
} }
// NumSubexp returns the number of sub-expressions in the given [Reg]. This is equivalent // NumSubexp returns the number of sub-expressions in the given [Reg]. This is equivalent
@ -30,6 +31,10 @@ func (r Reg) String() string {
return r.str return r.str
} }
func (r Reg) Longest() {
r.preferLongest = true
}
const concatRune rune = 0xF0001 const concatRune rune = 0xF0001
// Flags for shuntingYard - control its behavior // Flags for shuntingYard - control its behavior
@ -1135,7 +1140,7 @@ func thompson(re []postfixNode) (Reg, error) {
concatenate(nfa[0], &lastState) concatenate(nfa[0], &lastState)
// The string is empty here, because we add it in Compile() // The string is empty here, because we add it in Compile()
return Reg{nfa[0], numGroups, ""}, nil return Reg{nfa[0], numGroups, "", false}, nil
} }

Loading…
Cancel
Save