From 366d42b5a5a609801feba7fec9eb71e6e32fff99 Mon Sep 17 00:00:00 2001 From: Gregor Kappler Date: Tue, 4 Aug 2020 17:50:21 +0200 Subject: [PATCH] Reverse: fix SubString, ncodeunits, regex_string, revert(::MappingParser) --- src/caseless.jl | 2 ++ src/reverse.jl | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/caseless.jl b/src/caseless.jl index b3765e2..150007f 100644 --- a/src/caseless.jl +++ b/src/caseless.jl @@ -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 diff --git a/src/reverse.jl b/src/reverse.jl index 9f070cf..a79e343 100644 --- a/src/reverse.jl +++ b/src/reverse.jl @@ -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))