diff options
Diffstat (limited to 'main')
| -rw-r--r-- | main/main.go | 36 | 
1 files changed, 34 insertions, 2 deletions
diff --git a/main/main.go b/main/main.go index 7bb5152..08514ab 100644 --- a/main/main.go +++ b/main/main.go @@ -95,7 +95,7 @@ func parseRegex(l *RuneReader, minPower int) RegexAST {  	switch r {  		case eof:  			return nil -		case ')', '*', '-': +		case ')', '*', '-', '|':  			l.rewind()  			return nil  		case '(': @@ -122,6 +122,12 @@ func parseRegex(l *RuneReader, minPower int) RegexAST {  				lhs = RegexASTMaximise{lhs}  			case r == '-' && minPower <= 4:  				lhs = RegexASTMinimise{lhs} +			case r == '|' && minPower <= 2: +				rhs := parseRegex(l, 3) +				if rhs == nil { +					panic("Missing regex after |") +				} +				lhs = RegexASTOr{lhs, rhs}  			default:  				l.rewind()  				break loop @@ -141,7 +147,7 @@ func parseSubex(l *RuneReader, minPower int) TransducerAST {  			if !l.accept(")") {  				panic("Missing matching )")  			} -		case ')', '*', '-': +		case ')', '*', '-', '|':  			l.rewind()  			return nil  		case '$': @@ -179,6 +185,12 @@ func parseSubex(l *RuneReader, minPower int) TransducerAST {  				lhs = TransducerASTMaximise{lhs}  			case r == '-' && minPower <= 4:  				lhs = TransducerASTMinimise{lhs} +			case r == '|' && minPower <= 2: +				rhs := parseSubex(l, 3) +				if rhs == nil { +					panic("Missing subex after |") +				} +				lhs = TransducerASTOr{lhs, rhs}  			default:  				l.rewind()  				break loop @@ -290,6 +302,16 @@ func (ast RegexASTConcat) String() string {  	return fmt.Sprintf("Concat{%v, %v}", ast.first, ast.second)  } +type RegexASTOr struct { +	first, second RegexAST +} +func (ast RegexASTOr) compileWith(next RegexState) RegexState { +	return RegexGroupState{ +		ast.first.compileWith(next), +		ast.second.compileWith(next), +	} +} +  type RegexASTMaximise struct {  	content RegexAST  } @@ -470,6 +492,16 @@ func (ast TransducerASTStore) String() string {  	return fmt.Sprintf("$%c(%v)", ast.slot, ast.match)  } +type TransducerASTOr struct { +	first, second TransducerAST +} +func (ast TransducerASTOr) compileWithNext(next TransducerState) TransducerState { +	return TransducerGroupState { +		ast.first.compileWithNext(next), +		ast.second.compileWithNext(next), +	} +} +  type TransducerASTMaximise struct {  	content TransducerAST  }  | 
