i++// Skip all characters inside _unescaped_ brackets (we are _not_ at a closing bracket, or if we are, the previous character is a backslash)
i++// Skip all characters inside _unescaped_ brackets (we are _not_ at a closing bracket, or if we are, the previous character is a backslash)
// TODO: Check for escaped characters
// Make sure we haven't exceeded the length of the string. If we did, then the regex doesn't actually have a closing bracket and we should throw an error.
ifre_runes[i]=='-'&&i>0&&re_runes[i-1]!='\\'{// Unescaped hyphen - replace with CHAR_RANGE. This metacharacter will be used later on to construct the range
ifi>=len(re_runes){
returnnil,fmt.Errorf("Opening bracket without closing bracket.")
}
ifre_runes[i]=='-'&&(i>0&&re_runes[i-1]!='\\')&&(i<len(re_runes)-1&&re_runes[i+1]!=']'){// 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