Updated CONCAT to be a metacharacter instead of just a tilde, and renamed it to avoid exporting

This commit is contained in:
2025-01-30 10:34:03 -05:00
parent 93474c5159
commit e01ef48cbc
3 changed files with 14 additions and 14 deletions

View File

@@ -18,7 +18,7 @@ type Reg struct {
numGroups int
}
const CONCAT rune = '~'
const concatRune rune = 0xF0001
// Flags for shuntingYard - control its behavior
type ReFlag int
@@ -31,7 +31,7 @@ const (
)
func isOperator(c rune) bool {
if c == '+' || c == '?' || c == '*' || c == '|' || c == CONCAT {
if c == '+' || c == '?' || c == '*' || c == '|' || c == concatRune {
return true
}
return false
@@ -39,7 +39,7 @@ func isOperator(c rune) bool {
/* priority returns the priority of the given operator */
func priority(op rune) int {
precedence := []rune{'|', CONCAT, '+', '*', '?'}
precedence := []rune{'|', concatRune, '+', '*', '?'}
return slices.Index(precedence, op)
}
@@ -320,7 +320,7 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) {
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)-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, CONCAT)
re_postfix = append(re_postfix, concatRune)
}
}
}