diff --git a/compile.go b/compile.go index 7a6669b..907bb19 100644 --- a/compile.go +++ b/compile.go @@ -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)...)) }