diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2021-02-20 17:36:16 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2021-02-20 17:36:16 +0900 |
commit | 9357758697305753a68b541b42452a8cb13eebe2 (patch) | |
tree | bc10befd50c9a0fd1c5ccc894e1e18cfbbdacb33 /compiler/parser.go | |
parent | Fix computation of last positions (diff) | |
download | tre-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.go | 12 |
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 { |