|
|
@ -46,6 +46,23 @@ func shuntingYard(re string) []postfixNode {
|
|
|
|
if re_runes[i] == '[' && (i == 0 || re_runes[i-1] != '\\') { // We do not touch things inside brackets, unless they are escaped
|
|
|
|
if re_runes[i] == '[' && (i == 0 || re_runes[i-1] != '\\') { // We do not touch things inside brackets, unless they are escaped
|
|
|
|
for re_runes[i] != ']' {
|
|
|
|
for re_runes[i] != ']' {
|
|
|
|
i++ // Skip all characters inside brackets
|
|
|
|
i++ // Skip all characters inside brackets
|
|
|
|
|
|
|
|
// TODO: Check for escaped characters
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check ahead for character range
|
|
|
|
|
|
|
|
if i < len(re_runes)-2 && re_runes[i+1] == '-' {
|
|
|
|
|
|
|
|
rangeStart := re_runes[i]
|
|
|
|
|
|
|
|
rangeEnd := re_runes[i+2]
|
|
|
|
|
|
|
|
if int(rangeEnd) < int(rangeStart) {
|
|
|
|
|
|
|
|
panic("Range is out of order.")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for i := rangeStart; i <= rangeEnd; i++ {
|
|
|
|
|
|
|
|
re_postfix = append(re_postfix, i)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i += 2 // Skip start and hyphen (end will automatically be skipped on next iteration of loop)
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
re_postfix = append(re_postfix, re_runes[i])
|
|
|
|
re_postfix = append(re_postfix, re_runes[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
continue
|
|
|
@ -74,6 +91,7 @@ func shuntingYard(re string) []postfixNode {
|
|
|
|
ii. current character has greater priority than top of opStack
|
|
|
|
ii. current character has greater priority than top of opStack
|
|
|
|
3. If current character is '(', push to opStack
|
|
|
|
3. If current character is '(', push to opStack
|
|
|
|
4. If current character is ')', pop from opStack (and append to outQueue) until '(' is found. Discard parantheses.
|
|
|
|
4. If current character is ')', pop from opStack (and append to outQueue) until '(' is found. Discard parantheses.
|
|
|
|
|
|
|
|
5. If current character is '[', find all the characters until ']', then create a postfixNode containing all these contents. Add this node to outQueue.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
c := re_postfix[i]
|
|
|
|
c := re_postfix[i]
|
|
|
|
if isAlphaNum(c) {
|
|
|
|
if isAlphaNum(c) {
|
|
|
@ -88,6 +106,10 @@ func shuntingYard(re string) []postfixNode {
|
|
|
|
// outQueue = append(outQueue, re_postfix[i+1])
|
|
|
|
// outQueue = append(outQueue, re_postfix[i+1])
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if c == '.' { // Dot metacharacter - represents 'any' character, but I am only adding Unicode 0020-007E
|
|
|
|
|
|
|
|
outQueue = append(outQueue, newPostfixNode(dotCharacters()...))
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
if isOperator(c) {
|
|
|
|
if isOperator(c) {
|
|
|
|
if len(opStack) == 0 {
|
|
|
|
if len(opStack) == 0 {
|
|
|
|
opStack = append(opStack, c)
|
|
|
|
opStack = append(opStack, c)
|
|
|
|