From 5563a70568a645c959d798598ea5c3e66c224d16 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Mon, 3 Feb 2025 21:59:41 -0500 Subject: [PATCH] Reverse the order in which I pop states for alternation, because this messes with the left branch-right branch thing --- regex/compile.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/regex/compile.go b/regex/compile.go index b40c371..1068966 100644 --- a/regex/compile.go +++ b/regex/compile.go @@ -1059,8 +1059,8 @@ func thompson(re []postfixNode) (Reg, error) { // '|a' // '^a|' // '^|a' - s1, err1 := pop(&nfa) - s2, err2 := pop(&nfa) + s2, err1 := pop(&nfa) + s1, err2 := pop(&nfa) if err2 != nil || (s2.groupBegin && len(s2.transitions) == 0) { // Doesn't exist, or its just an LPAREN if err2 == nil { // Roundabout way of saying that this node existed, but it was an LPAREN, so we append it back nfa = append(nfa, s2)