File tree 1 file changed +9
-2
lines changed 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -471,12 +471,19 @@ func compileOnePass(prog *syntax.Prog) (p *onePassProg) {
471
471
syntax .EmptyOp (prog .Inst [prog .Start ].Arg )& syntax .EmptyBeginText != syntax .EmptyBeginText {
472
472
return nil
473
473
}
474
- // every instruction leading to InstMatch must be EmptyEndText
474
+ hasAlt := false
475
+ for _ , inst := range prog .Inst {
476
+ if inst .Op == syntax .InstAlt || inst .Op == syntax .InstAltMatch {
477
+ hasAlt = true
478
+ }
479
+ }
480
+ // If we have alternates, every instruction leading to InstMatch must be EmptyEndText.
481
+ // Also, any match on empty text must be $.
475
482
for _ , inst := range prog .Inst {
476
483
opOut := prog .Inst [inst .Out ].Op
477
484
switch inst .Op {
478
485
default :
479
- if opOut == syntax .InstMatch {
486
+ if opOut == syntax .InstMatch && hasAlt {
480
487
return nil
481
488
}
482
489
case syntax .InstAlt , syntax .InstAltMatch :
You can’t perform that action at this time.
0 commit comments