Skip to content

Commit

Permalink
Reverse: fix SubString, ncodeunits, regex_string, revert(::MappingPar…
Browse files Browse the repository at this point in the history
…ser)
  • Loading branch information
gkappler committed Aug 4, 2020
1 parent 4bd7a5d commit 366d42b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/caseless.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ end
_iterate(parser.parser, MappedChars(parser.f,sequence), till,posi,after,state)
end

revert(x::MappingParser) = MappingParser(x.f,x.parser)

deepmap_parser(f::Function,mem::AbstractDict,x::MappingParser,a...;kw...) =
get!(mem,x) do
## construct replacement, e.g. if P <: WrappedParser
Expand Down
6 changes: 4 additions & 2 deletions src/reverse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ reverse_index(x::Reverse,i) =
reverse_index(x::AbstractString,i) =
i

Base.SubString(x::Reverse,start,stop) =
SubString(x.x, reverse_index(x,stop), reverse_index(x,start))
Base.SubString(x::Reverse,start::Int,stop::Int) =
SubString(x.x, reverse_index(x, stop), reverse_index(x, start))

function set_capture(sequence::Reverse, index::Int, x)
@warn "check"
set_capture(sequence.x,index,x)
end

regex_string(x::Reverse) = regex_escape(x.x)
Base.ncodeunits(x::Reverse) = ncodeunits(x.x)
Base.firstindex(x::Reverse) = 1
Base.lastindex(x::Reverse) = x.lastindex
Base.getindex(x::Reverse,is::UnitRange) = getindex(x.x,reverse_index(x,is.stop):reverse_index(x,is.start))
Expand Down

0 comments on commit 366d42b

Please sign in to comment.