Updated references to constants
This commit is contained in:
@@ -171,7 +171,7 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) {
|
|||||||
}
|
}
|
||||||
re_runes = append(re_runes, []rune(regex)...)
|
re_runes = append(re_runes, []rune(regex)...)
|
||||||
} else if c == '(' && i < len(re_runes_orig)-2 && re_runes_orig[i+1] == '?' && re_runes_orig[i+2] == ':' {
|
} else if c == '(' && i < len(re_runes_orig)-2 && re_runes_orig[i+1] == '?' && re_runes_orig[i+2] == ':' {
|
||||||
re_runes = append(re_runes, NONCAPLPAREN_CHAR)
|
re_runes = append(re_runes, nonCapLparenRune)
|
||||||
i += 2
|
i += 2
|
||||||
} else if c == '\\' && i < len(re_runes_orig)-1 && re_runes_orig[i+1] == '\\' { // Escaped backslash
|
} else if c == '\\' && i < len(re_runes_orig)-1 && re_runes_orig[i+1] == '\\' { // Escaped backslash
|
||||||
re_runes = append(re_runes, escBackslashRune)
|
re_runes = append(re_runes, escBackslashRune)
|
||||||
@@ -254,7 +254,7 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) {
|
|||||||
re_postfix = append(re_postfix, re_runes[i]) // Append closing brace
|
re_postfix = append(re_postfix, re_runes[i]) // Append closing brace
|
||||||
}
|
}
|
||||||
if i < len(re_runes)-3 && string(re_runes[i+1:i+4]) == "(?:" { // Non-capturing lparen
|
if i < len(re_runes)-3 && string(re_runes[i+1:i+4]) == "(?:" { // Non-capturing lparen
|
||||||
re_postfix = append(re_postfix, NONCAPLPAREN_CHAR)
|
re_postfix = append(re_postfix, nonCapLparenRune)
|
||||||
i += 3
|
i += 3
|
||||||
}
|
}
|
||||||
if i < len(re_runes) && re_runes[i] == '\\' { // Something is being escaped (I don't add the backslash to re_postfix, because it was already added earlier)
|
if i < len(re_runes) && re_runes[i] == '\\' { // Something is being escaped (I don't add the backslash to re_postfix, because it was already added earlier)
|
||||||
@@ -303,7 +303,7 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) {
|
|||||||
if i >= len(re_runes) {
|
if i >= len(re_runes) {
|
||||||
return nil, fmt.Errorf("unclosed lookaround")
|
return nil, fmt.Errorf("unclosed lookaround")
|
||||||
}
|
}
|
||||||
if re_runes[i] == '(' || re_runes[i] == NONCAPLPAREN_CHAR {
|
if re_runes[i] == '(' || re_runes[i] == nonCapLparenRune {
|
||||||
numOpenParens++
|
numOpenParens++
|
||||||
}
|
}
|
||||||
if re_runes[i] == ')' {
|
if re_runes[i] == ')' {
|
||||||
@@ -317,7 +317,7 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) {
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if i < len(re_runes) && (re_runes[i] != '(' && re_runes[i] != NONCAPLPAREN_CHAR && re_runes[i] != '|' && re_runes[i] != '\\') || (i > 0 && re_runes[i-1] == '\\') { // Every character should be concatenated if it is escaped
|
if i < len(re_runes) && (re_runes[i] != '(' && re_runes[i] != nonCapLparenRune && re_runes[i] != '|' && re_runes[i] != '\\') || (i > 0 && re_runes[i-1] == '\\') { // Every character should be concatenated if it is escaped
|
||||||
if i < len(re_runes)-1 {
|
if i < len(re_runes)-1 {
|
||||||
if re_runes[i+1] != '|' && re_runes[i+1] != '*' && re_runes[i+1] != '+' && re_runes[i+1] != '?' && re_runes[i+1] != ')' && re_runes[i+1] != '{' {
|
if re_runes[i+1] != '|' && re_runes[i+1] != '*' && re_runes[i+1] != '+' && re_runes[i+1] != '?' && re_runes[i+1] != ')' && re_runes[i+1] != '{' {
|
||||||
re_postfix = append(re_postfix, concatRune)
|
re_postfix = append(re_postfix, concatRune)
|
||||||
@@ -433,7 +433,7 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) {
|
|||||||
if i >= len(re_postfix) {
|
if i >= len(re_postfix) {
|
||||||
return nil, fmt.Errorf("unclosed lookaround")
|
return nil, fmt.Errorf("unclosed lookaround")
|
||||||
}
|
}
|
||||||
if re_postfix[i] == '(' || re_postfix[i] == NONCAPLPAREN_CHAR {
|
if re_postfix[i] == '(' || re_postfix[i] == nonCapLparenRune {
|
||||||
numOpenParens++
|
numOpenParens++
|
||||||
}
|
}
|
||||||
if re_postfix[i] == ')' {
|
if re_postfix[i] == ')' {
|
||||||
@@ -757,7 +757,7 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) {
|
|||||||
outQueue[idx].startReps = startRangeNum
|
outQueue[idx].startReps = startRangeNum
|
||||||
outQueue[idx].endReps = endRangeNum
|
outQueue[idx].endReps = endRangeNum
|
||||||
}
|
}
|
||||||
if c == '(' || c == NONCAPLPAREN_CHAR {
|
if c == '(' || c == nonCapLparenRune {
|
||||||
opStack = append(opStack, c)
|
opStack = append(opStack, c)
|
||||||
if c == '(' { // We only push _capturing_ group parentheses to outQueue
|
if c == '(' { // We only push _capturing_ group parentheses to outQueue
|
||||||
outQueue = append(outQueue, newPostfixNode(c))
|
outQueue = append(outQueue, newPostfixNode(c))
|
||||||
|
@@ -99,13 +99,13 @@ func range2regex(start int, end int) (string, error) {
|
|||||||
// Last range - tmp to rangeEnd
|
// Last range - tmp to rangeEnd
|
||||||
ranges = append(ranges, numRange{tmp, rangeEnd})
|
ranges = append(ranges, numRange{tmp, rangeEnd})
|
||||||
|
|
||||||
regex := string(NONCAPLPAREN_CHAR)
|
regex := string(nonCapLparenRune)
|
||||||
// Generate the regex
|
// Generate the regex
|
||||||
for i, rg := range ranges {
|
for i, rg := range ranges {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
regex += "|"
|
regex += "|"
|
||||||
}
|
}
|
||||||
regex += string(NONCAPLPAREN_CHAR)
|
regex += string(nonCapLparenRune)
|
||||||
startSlc := intToSlc(rg.start)
|
startSlc := intToSlc(rg.start)
|
||||||
endSlc := intToSlc(rg.end)
|
endSlc := intToSlc(rg.end)
|
||||||
if len(startSlc) != len(endSlc) {
|
if len(startSlc) != len(endSlc) {
|
||||||
@@ -115,7 +115,7 @@ func range2regex(start int, end int) (string, error) {
|
|||||||
if startSlc[i] == endSlc[i] {
|
if startSlc[i] == endSlc[i] {
|
||||||
regex += string(rune(startSlc[i] + 48)) // '0' is ascii value 48, 1 is 49 etc. To convert the digit to its character form, we can just add 48.
|
regex += string(rune(startSlc[i] + 48)) // '0' is ascii value 48, 1 is 49 etc. To convert the digit to its character form, we can just add 48.
|
||||||
} else {
|
} else {
|
||||||
regex += fmt.Sprintf("%c%c-%c%c", LBRACKET, rune(startSlc[i]+48), rune(endSlc[i]+48), RBRACKET)
|
regex += fmt.Sprintf("%c%c-%c%c", lbracketRune, rune(startSlc[i]+48), rune(endSlc[i]+48), RBRACKET)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
regex += ")"
|
regex += ")"
|
||||||
|
Reference in New Issue
Block a user