Implement PCRE Matching (prefer left-branch) #2
@@ -14,9 +14,10 @@ var notDotChars []rune
|
|||||||
// the startState of the NFA representation of the regex, and the number of capturing
|
// the startState of the NFA representation of the regex, and the number of capturing
|
||||||
// groups in the regex. It also contains the expression string.
|
// groups in the regex. It also contains the expression string.
|
||||||
type Reg struct {
|
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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user