Throw error if a quantifier is quantified eg. 'a**'; throw error if start of character range is greater than the end eg. '[b-a]'
This commit is contained in:
@@ -469,6 +469,10 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) {
|
||||
outQueue = append(outQueue, newPostfixNode(to_append))
|
||||
topStack, _ = peek(opStack)
|
||||
}
|
||||
outQueueFinalElement, _ := peek(outQueue)
|
||||
if (c == '*' && outQueueFinalElement.nodetype == KLEENE) || (c == '+' && outQueueFinalElement.nodetype == PLUS) { // You cannot apply a quantifier to a quantifier in this way
|
||||
return nil, fmt.Errorf("illegal use of token '%c'", c)
|
||||
}
|
||||
opStack = append(opStack, c)
|
||||
}
|
||||
}
|
||||
@@ -654,6 +658,9 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) {
|
||||
// We have established that they both have a length of 1
|
||||
startRangeRune := startRangePostfixNode.contents[0]
|
||||
endRangeRune := endRangePostfixNode.contents[0]
|
||||
if startRangeRune > endRangeRune {
|
||||
return nil, fmt.Errorf("character range syntax is [a-b], not [b-a]")
|
||||
}
|
||||
chars = append(chars, newPostfixCharNode(genRange(startRangeRune, endRangeRune+1)...))
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user