Compare commits
3 Commits
d62a429cce
...
e07f27dc78
| Author | SHA1 | Date | |
|---|---|---|---|
| e07f27dc78 | |||
| 65d2317f79 | |||
| a631fc289c |
@@ -45,10 +45,10 @@ type nfaState struct {
|
|||||||
groupBegin bool // Whether or not the node starts a capturing group
|
groupBegin bool // Whether or not the node starts a capturing group
|
||||||
groupEnd bool // Whether or not the node ends a capturing group
|
groupEnd bool // Whether or not the node ends a capturing group
|
||||||
groupNum int // Which capturing group the node starts / ends
|
groupNum int // Which capturing group the node starts / ends
|
||||||
// The following properties depend on the current match - I should think about resetting them for every match.
|
|
||||||
threadGroups []Group // Assuming that a state is part of a 'thread' in the matching process, this array stores the indices of capturing groups in the current thread. As matches are found for this state, its groups will be copied over.
|
|
||||||
isBackreference bool // Whether or not current node is backreference
|
isBackreference bool // Whether or not current node is backreference
|
||||||
referredGroup int // If current node is a backreference, the node that it points to
|
referredGroup int // If current node is a backreference, the node that it points to
|
||||||
|
// The following properties depend on the current match - I should think about resetting them for every match.
|
||||||
|
threadGroups []Group // Assuming that a state is part of a 'thread' in the matching process, this array stores the indices of capturing groups in the current thread. As matches are found for this state, its groups will be copied over.
|
||||||
threadBackref int // If current node is a backreference, how many characters to look forward into the referred group
|
threadBackref int // If current node is a backreference, how many characters to look forward into the referred group
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,6 +86,8 @@ func cloneStateHelper(stateToClone *nfaState, cloneMap map[*nfaState]*nfaState)
|
|||||||
groupEnd: stateToClone.groupEnd,
|
groupEnd: stateToClone.groupEnd,
|
||||||
groupBegin: stateToClone.groupBegin,
|
groupBegin: stateToClone.groupBegin,
|
||||||
groupNum: stateToClone.groupNum,
|
groupNum: stateToClone.groupNum,
|
||||||
|
isBackreference: stateToClone.isBackreference,
|
||||||
|
referredGroup: stateToClone.referredGroup,
|
||||||
}
|
}
|
||||||
cloneMap[stateToClone] = clone
|
cloneMap[stateToClone] = clone
|
||||||
for i, s := range stateToClone.output {
|
for i, s := range stateToClone.output {
|
||||||
|
|||||||
@@ -117,6 +117,7 @@ var reTests = []struct {
|
|||||||
{`\d{3,4}`, nil, "ababab555", []Group{{6, 9}}},
|
{`\d{3,4}`, nil, "ababab555", []Group{{6, 9}}},
|
||||||
{`\bpaint\b`, nil, "paints", []Group{}},
|
{`\bpaint\b`, nil, "paints", []Group{}},
|
||||||
{`\b\w{5}\b`, nil, "paint", []Group{{0, 5}}},
|
{`\b\w{5}\b`, nil, "paint", []Group{{0, 5}}},
|
||||||
|
{`\w{}`, nil, "test", nil},
|
||||||
{`[^\w]`, nil, "abcdef1230[]qq';;'", []Group{{10, 11}, {11, 12}, {14, 15}, {15, 16}, {16, 17}, {17, 18}}},
|
{`[^\w]`, nil, "abcdef1230[]qq';;'", []Group{{10, 11}, {11, 12}, {14, 15}, {15, 16}, {16, 17}, {17, 18}}},
|
||||||
{`[^\W]`, nil, "abcdef1230[]qq';;'", []Group{{0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 7}, {7, 8}, {8, 9}, {9, 10}, {12, 13}, {13, 14}}},
|
{`[^\W]`, nil, "abcdef1230[]qq';;'", []Group{{0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 7}, {7, 8}, {8, 9}, {9, 10}, {12, 13}, {13, 14}}},
|
||||||
{`[\[\]]`, nil, "a[b[l]]", []Group{{1, 2}, {3, 4}, {5, 6}, {6, 7}}},
|
{`[\[\]]`, nil, "a[b[l]]", []Group{{1, 2}, {3, 4}, {5, 6}, {6, 7}}},
|
||||||
@@ -547,6 +548,20 @@ var reTests = []struct {
|
|||||||
{`[\p{Greek}\p{Cyrillic}]`, nil, `ΣωШД`, []Group{{0, 1}, {1, 2}, {2, 3}, {3, 4}}},
|
{`[\p{Greek}\p{Cyrillic}]`, nil, `ΣωШД`, []Group{{0, 1}, {1, 2}, {2, 3}, {3, 4}}},
|
||||||
|
|
||||||
{`(?<=\().*?(?=\))`, nil, `(abc)`, []Group{{1, 4}}},
|
{`(?<=\().*?(?=\))`, nil, `(abc)`, []Group{{1, 4}}},
|
||||||
|
|
||||||
|
{`((a|b)\2)`, nil, `aa`, []Group{{0, 2}}},
|
||||||
|
{`((a|b)\2)`, nil, `bb`, []Group{{0, 2}}},
|
||||||
|
{`((a|b)\2)`, nil, `ab`, []Group{}},
|
||||||
|
{`((a|b)\2)`, nil, `ba`, []Group{}},
|
||||||
|
|
||||||
|
{`((a|b)\2){3}`, nil, `aaaaaa`, []Group{{0, 6}}},
|
||||||
|
{`((a|b)\2){3}`, nil, `bbbbbb`, []Group{{0, 6}}},
|
||||||
|
{`((a|b)\2){3}`, nil, `bbaaaa`, []Group{{0, 6}}},
|
||||||
|
{`((a|b)\2){3}`, nil, `aabbaa`, []Group{{0, 6}}},
|
||||||
|
{`((a|b)\2){3}`, nil, `aaaabb`, []Group{{0, 6}}},
|
||||||
|
{`((a|b)\2){3}`, nil, `bbaabb`, []Group{{0, 6}}},
|
||||||
|
{`((a|b)\2){3}`, nil, `baabab`, []Group{}},
|
||||||
|
{`((a|b)\2){3}`, nil, `bbabab`, []Group{}},
|
||||||
}
|
}
|
||||||
|
|
||||||
var groupTests = []struct {
|
var groupTests = []struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user