aboutsummaryrefslogtreecommitdiff
path: root/compiler/parser.go
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2021-02-20 17:36:16 +0900
committerRyo Nihei <nihei.dev@gmail.com>2021-02-20 17:36:16 +0900
commit9357758697305753a68b541b42452a8cb13eebe2 (patch)
treebc10befd50c9a0fd1c5ccc894e1e18cfbbdacb33 /compiler/parser.go
parentFix computation of last positions (diff)
downloadtre-9357758697305753a68b541b42452a8cb13eebe2.tar.gz
tre-9357758697305753a68b541b42452a8cb13eebe2.tar.xz
Add + and ? operators
* a+ matches 'a' one or more times. This is equivalent to aa*. * a? matches 'a' zero or one time.
Diffstat (limited to 'compiler/parser.go')
-rw-r--r--compiler/parser.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/compiler/parser.go b/compiler/parser.go
index ede601d..04cd8ad 100644
--- a/compiler/parser.go
+++ b/compiler/parser.go
@@ -144,10 +144,16 @@ func (p *parser) parseConcat() astNode {
func (p *parser) parseRepeat() astNode {
group := p.parseGroup()
- if !p.consume(tokenKindRepeat) {
- return group
+ if p.consume(tokenKindRepeat) {
+ return newRepeatNode(group)
}
- return newRepeatNode(group)
+ if p.consume(tokenKindRepeatOneOrMore) {
+ return newRepeatOneOrMoreNode(group)
+ }
+ if p.consume(tokenKindOption) {
+ return newOptionNode(group)
+ }
+ return group
}
func (p *parser) parseGroup() astNode {