diff options
Diffstat (limited to 'main/parse.go')
-rw-r--r-- | main/parse.go | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/main/parse.go b/main/parse.go index a9bd4b5..6cc20ea 100644 --- a/main/parse.go +++ b/main/parse.go @@ -27,7 +27,7 @@ func parseRegex(l *RuneReader, minPower int) RegexAST { switch r { case eof: return nil - case ')', '*', '-', '|': + case ')', '*', '-', '|', '?', '!': l.rewind() return nil case '(': @@ -54,6 +54,10 @@ func parseRegex(l *RuneReader, minPower int) RegexAST { lhs = RegexASTMaximise{lhs} case r == '-' && minPower <= 4: lhs = RegexASTMinimise{lhs} + case r == '!' && minPower <= 4: + lhs = RegexASTTry{lhs} + case r == '?' && minPower <= 4: + lhs = RegexASTMaybe{lhs} case r == '|' && minPower <= 2: rhs := parseRegex(l, 3) if rhs == nil { @@ -79,7 +83,7 @@ func parseSubex(l *RuneReader, minPower int) SubexAST { if !l.accept(")") { panic("Missing matching )") } - case ')', '*', '-', '|': + case ')', '*', '-', '|', '!', '?', ';': l.rewind() return nil case '$': @@ -113,16 +117,29 @@ func parseSubex(l *RuneReader, minPower int) SubexAST { } r := l.next() switch { - case r == '*' && minPower <= 4: + case r == '*' && minPower <= 8: lhs = SubexASTMaximise{lhs} - case r == '-' && minPower <= 4: + case r == '-' && minPower <= 8: lhs = SubexASTMinimise{lhs} - case r == '|' && minPower <= 2: - rhs := parseSubex(l, 3) + case r == '!' && minPower <= 8: + lhs = SubexASTTry{lhs} + case r == '?' && minPower <= 8: + lhs = SubexASTMaybe{lhs} + case r == '|' && minPower <= 4: + rhs := parseSubex(l, 5) if rhs == nil { panic("Missing subex after |") } lhs = SubexASTOr{lhs, rhs} + case r == ';' && minPower <= 2: + rhs := parseSubex(l, 3) + if rhs == nil { + panic("Missing subex after ;") + } + lhs = SubexASTJoin{ + content: lhs, + delimiter: rhs, + } default: l.rewind() break loop |