returnnil,fmt.Errorf("Unable to parse what looks like a POSIX character class.")
}
toAppend=append(toAppend,re_runes[i])
i++
}
ifre_runes[i]=='-'&&(i>0&&re_runes[i-1]!='\\')&&(i<len(re_runes)-1&&re_runes[i+1]!=RBRACKET){// Unescaped hyphen, that has some character (not a RBRACKET) after it - This represents a character range, so we replace with CHAR_RANGE. This metacharacter will be used later on to construct the range
ifre_postfix[i]==LBRACKET&&i<len(re_postfix)-8{// Could be the start of a POSIX class - the smallest POSIX class by word-length [[:word:]] takes 8 more characters
nodeToAdd,_=newEscapedNode('w',true)// This isn't going to error, so I suppress it
default:
returnnil,fmt.Errorf("Invalid POSIX character class.")
}
chars=append(chars,nodeToAdd)
i=temp_i+len(posixClass)+2// Skip over the class name, the closing colon and the closing bracket
firstCharAdded=true
continue
}
}
}
// This used to be an else statement - I removed it, because if the previous if-block fails
// (ie. if it didn't actually find a character class), then this block must still execute.
// However, the checks for character classes are nested, so placing this inside an 'else' block
// will prevent it from running, as the outer if-statement will have evaluated to true.
if!firstCharAdded&&re_postfix[i]>0xF0000{// It's a metacharacter that I defined, I'll have to convert it back to the regular character before adding it back, because I haven't added any characters yet. For example, '[[]', the second LBRACKET should be treated like a literal bracket.