Skip to content

Commit

Permalink
Merge commit 'refs/pullreqs/8' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
gkappler committed Aug 19, 2020
2 parents 1ba207c + 43beb4a commit 6fb562a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/CombinedParsers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1368,9 +1368,10 @@ end
export Repeat_stop, Repeat_until
"""
Repeat_stop(p,stop)
Repeat_stop(p,stop; min=0, max=Repeat_max)
Repeat `p` until `stop` (`NegativeLookahead`), not matching `stop`.
Sets cursor **before** `stop`.
Sets cursor **before** `stop`. Tries `min:max` times
Returns results of `p`.
```jldoctest
Expand All @@ -1389,13 +1390,13 @@ julia> parse(p,"acbX")
See also [`NegativeLookahead`](@ref)
"""
Repeat_stop(p,stop) =
Repeat(map(IndexAt(2),Sequence(NegativeLookahead(parser(stop)),parser(p))))
Repeat_stop(p,stop; min=0, max=Repeat_max) =
Repeat(map(IndexAt(2),Sequence(NegativeLookahead(parser(stop)),parser(p)));min=min,max=max)

@deprecate rep_stop(a...;kw...) Repeat_stop(a...;kw...)

"""
Repeat_until(p,until, with_until=false;wrap=identity)
Repeat_until(p,until, with_until=false; wrap=identity, min=0, max=Repeat_max)
Repeat `p` until `stop` (with [`Repeat_stop`](@ref)).
and set point **after** `stop`.
Expand Down Expand Up @@ -1424,11 +1425,11 @@ julia> parse(Repeat_until(AnyChar(),'b';wrap=JoinSubstring),"acbX")
See also [`NegativeLookahead`](@ref)
"""
Repeat_until(p,until, with_until=false;wrap=identity) =
Repeat_until(p,until, with_until=false;wrap=identity,min=0,max=Repeat_max) =
if with_until
Sequence(map(wrap,Atomic(Repeat_stop(p,until))), until)
Sequence(map(wrap,Atomic(Repeat_stop(p,until;min=min,max=max))), until)
else
map(IndexAt(1),Sequence(map(wrap,Atomic(Repeat_stop(p,until))), until))
map(IndexAt(1),Sequence(map(wrap,Atomic(Repeat_stop(p,until;min=min,max=max))), until))
end

@deprecate rep_until(p,until) Repeat_until(p,until)
Expand Down
11 changes: 11 additions & 0 deletions test/test-parser.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CombinedParsers.Regexp
import CombinedParsers.Regexp: word, non_word
import CombinedParsers.Regexp: newline, inline, whitespace_maybe, whitespace_horizontal
import CombinedParsers.Regexp: Repeat_max

@testset "CombinedParsers" begin
@testset "CharIn" begin
Expand Down Expand Up @@ -42,6 +43,16 @@ end
@test parse(Sequence("(", Repeat_until(!!Either(word,non_word), ")")),
"(balanced parenthesis)") ==
("(",["balanced", " ", "parenthesis"])
# Test if strings bigger than Repeat_max can be parsed using max optional ArgumentError
new_Repeat_max = Repeat_max+10;
dat = 'a'^(new_Repeat_max)*'b';
@test String(parse(Repeat_until('a','b';max=new_Repeat_max), dat))==dat[1:end-1]
end

@testset "Repeat_stop" begin
new_Repeat_max = Repeat_max+10;
dat = 'a'^(new_Repeat_max)*'b';
@test String(parse(Repeat_stop('a','b';max=new_Repeat_max), dat))==dat[1:end-1]
end
end

Expand Down

0 comments on commit 6fb562a

Please sign in to comment.