File tree 2 files changed +12
-2
lines changed 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -465,12 +465,20 @@ func compileOnePass(prog *syntax.Prog) (p *onePassProg) {
465
465
syntax .EmptyOp (prog .Inst [prog .Start ].Arg )& syntax .EmptyBeginText != syntax .EmptyBeginText {
466
466
return nil
467
467
}
468
- // every instruction leading to InstMatch must be EmptyEndText
468
+ hasAlt := false
469
+ for _ , inst := range prog .Inst {
470
+ if inst .Op == syntax .InstAlt || inst .Op == syntax .InstAltMatch {
471
+ hasAlt = true
472
+ break
473
+ }
474
+ }
475
+ // If we have alternates, every instruction leading to InstMatch must be EmptyEndText.
476
+ // Also, any match on empty text must be $.
469
477
for _ , inst := range prog .Inst {
470
478
opOut := prog .Inst [inst .Out ].Op
471
479
switch inst .Op {
472
480
default :
473
- if opOut == syntax .InstMatch {
481
+ if opOut == syntax .InstMatch && hasAlt {
474
482
return nil
475
483
}
476
484
case syntax .InstAlt , syntax .InstAltMatch :
Original file line number Diff line number Diff line change @@ -142,6 +142,7 @@ var onePassTests = []struct {
142
142
{`^(?:(a)|(?:a*))$` , false },
143
143
{`^(?:(?:(?:.(?:$))?))$` , true },
144
144
{`^abcd$` , true },
145
+ {`^abcd` , true },
145
146
{`^(?:(?:a{0,})*?)$` , false },
146
147
{`^(?:(?:a+)*)$` , true },
147
148
{`^(?:(?:a|(?:aa)))$` , true },
@@ -154,6 +155,7 @@ var onePassTests = []struct {
154
155
{`^(?:(?:aa)|a)$` , true },
155
156
{`^[a-c]*` , false },
156
157
{`^...$` , true },
158
+ {`^...` , true },
157
159
{`^(?:a|(?:aa))$` , true },
158
160
{`^a((b))c$` , true },
159
161
{`^a.[l-nA-Cg-j]?e$` , true },
You can’t perform that action at this time.
0 commit comments