Return an error if a POSIX charclass is specified outside of brackets

master
Aadhavan Srinivasan 6 days ago
parent 3fb9bc1446
commit abc40bf770

@ -481,6 +481,16 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) {
if i >= len(re_postfix) {
return nil, fmt.Errorf("Opening bracket with no closing bracket.")
}
// Check if a POSIX character class was specified ouside a bracket. This is an error.
// Eg. [:digit:] should lead to an error, telling the user that the right syntax is [[:digit:]]
if re_postfix[i] == ':' {
posixClassPresent, _ := getPOSIXClass(re_postfix[i+1:])
if posixClassPresent {
return nil, fmt.Errorf("The syntax for POSIX character classes is [[:digit:]], not [:digit:]")
}
}
var invertMatch bool
if re_postfix[i] == '^' {
invertMatch = true

Loading…
Cancel
Save