returnnil,fmt.Errorf("opening bracket without closing bracket")
returnnil,fmt.Errorf("opening bracket without closing bracket")
}
}
forre_runes[i]!=RBRACKET||i==0||re_runes[i-1]=='\\'{// Skip all characters inside _unescaped_ brackets (we are _not_ at a closing bracket, or if we are, the previous character is a backslash)
forre_runes[i]!=rbracketRune||i==0||re_runes[i-1]=='\\'{// Skip all characters inside _unescaped_ brackets (we are _not_ at a closing bracket, or if we are, the previous character is a backslash)
// 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.
// 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.
ifi>=len(re_runes){
ifi>=len(re_runes){
returnnil,fmt.Errorf("opening bracket without closing bracket")
returnnil,fmt.Errorf("opening bracket without closing bracket")
}
}
ifre_runes[i]==LBRACKET&&re_runes[i+1]==':'{// POSIX character class
ifre_runes[i]==lbracketRune&&re_runes[i+1]==':'{// POSIX character class
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_runes[i]=='-'&&(i>0&&re_runes[i-1]!='\\')&&(i<len(re_runes)-1&&re_runes[i+1]!=rbracketRune){// 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
re_runes[i]=CHAR_RANGE
re_runes[i]=CHAR_RANGE
}
}
toAppend=append(toAppend,re_runes[i])
toAppend=append(toAppend,re_runes[i])
i++
i++
}
}
// Add in the RBRACKET
// Add in the RBRACKET
toAppend=append(toAppend,RBRACKET)
toAppend=append(toAppend,rbracketRune)
re_postfix=append(re_postfix,toAppend...)
re_postfix=append(re_postfix,toAppend...)
}
}
ifi<len(re_runes)&&re_runes[i]=='{'&&(i>0&&re_runes[i-1]!='\\'){// We don't touch things inside braces, either
ifi<len(re_runes)&&re_runes[i]=='{'&&(i>0&&re_runes[i-1]!='\\'){// We don't touch things inside braces, either
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
ifre_postfix[i]==lbracketRune&&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
// will prevent it from running, as the outer if-statement will have evaluated to true.
// 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.
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.
switchre_postfix[i]{
switchre_postfix[i]{
caseLBRACKET:
caselbracketRune:
chars=append(chars,newPostfixCharNode('['))
chars=append(chars,newPostfixCharNode('['))
caseRBRACKET:
caserbracketRune:
chars=append(chars,newPostfixCharNode(']'))
chars=append(chars,newPostfixCharNode(']'))
default:
default:
returnnil,fmt.Errorf("error parsing high-range unicode value in character class")
returnnil,fmt.Errorf("error parsing high-range unicode value in character class")