alternate returns the regexpInfo for x|y given x and y.
(x, y regexpInfo)
| 598 | |
| 599 | // alternate returns the regexpInfo for x|y given x and y. |
| 600 | func alternate(x, y regexpInfo) (out regexpInfo) { |
| 601 | //println("alternate", x.String(), "...", y.String()) |
| 602 | //defer func() { println("->", out.String()) }() |
| 603 | var xy regexpInfo |
| 604 | if x.exact.have() && y.exact.have() { |
| 605 | xy.exact = x.exact.union(y.exact, false) |
| 606 | } else if x.exact.have() { |
| 607 | xy.prefix = x.exact.union(y.prefix, false) |
| 608 | xy.suffix = x.exact.union(y.suffix, true) |
| 609 | x.addExact() |
| 610 | } else if y.exact.have() { |
| 611 | xy.prefix = x.prefix.union(y.exact, false) |
| 612 | xy.suffix = x.suffix.union(y.exact.copy(), true) |
| 613 | y.addExact() |
| 614 | } else { |
| 615 | xy.prefix = x.prefix.union(y.prefix, false) |
| 616 | xy.suffix = x.suffix.union(y.suffix, true) |
| 617 | } |
| 618 | xy.canEmpty = x.canEmpty || y.canEmpty |
| 619 | xy.match = x.match.or(y.match) |
| 620 | |
| 621 | xy.simplify(false) |
| 622 | return xy |
| 623 | } |
| 624 | |
| 625 | // addExact adds to the match query the trigrams for matching info.exact. |
| 626 | func (info *regexpInfo) addExact() { |