From fe1136c54c9d48e214be38272cdc34f1dc1b96ed Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Sun, 24 Nov 2024 15:02:58 -0500 Subject: [PATCH] Fixed bug with parentheses in lookaround regex; fixed bug with reading last line of test string (if it doesn't end in a newline) --- main.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 7cdb3f8..607d261 100644 --- a/main.go +++ b/main.go @@ -156,7 +156,7 @@ func shuntingYard(re string) []postfixNode { */ c := re_postfix[i] if isNormalChar(c) { - if *caseInsensitiveFlag { + if caseInsensitiveFlag != nil && *caseInsensitiveFlag { outQueue = append(outQueue, newPostfixNode(allCases(c)...)) } else { outQueue = append(outQueue, newPostfixNode(c)) @@ -204,9 +204,6 @@ func shuntingYard(re string) []postfixNode { regex += string(re_postfix[i]) i++ } - if regex[len(regex)-1] == ')' { // The closing paren would have also been added. Let's remove that. - regex = regex[:len(regex)-1] - } if len(regex) <= 1 { // Nothing in regex - panic panic("Invalid lookaround. (too short?)") } @@ -574,13 +571,16 @@ func main() { } // Assuming err != nil if err == io.EOF { + if len(temp) > 0 { + test_str += temp // Add the last line (if it is non-empty) + } linesRead = true } else { panic(err) } } test_runes = []rune(test_str) - matchIndices := findAllMatches(startState, []rune(test_runes)) + matchIndices := findAllMatches(startState, test_runes) if *printMatchesFlag { for _, idx := range matchIndices { fmt.Printf("%s\n", idx.toString())