Transformations to any result_type
CombinedParsers.Transformation — TypeTransformation(T::Type, parser)
Transformation{T}(transform, parser) where {T}
Base.map(f::Function, Tc::Type, p::CombinedParser, a...)
Base.map(f::Function, p::CombinedParser, a...)Parser transforming result of a wrapped parser. a... is passed as additional arguments to f (at front .
If parser isa NamedParser, transformation is done within the wrapped parser (i.e. name applies to result-transforming parser).
CombinedParsers.result_type — Functionresult_type(x::CombinedParser)returns the result type of a parser.
The result type is a CombinedParser type parameter. Most of the time it is type-inferred within constructors by infer_result_type.
Base.map — FunctionCombinedParsers.deepmap — Functiondeepmap(f, parser, predicate, a...; kw...)Substitute all sub_parsers with Base.map(f,sub_parser, a...; kw...) iif dodeepmap(parser, predicate); otherwise keep sub_parser
julia> p = re"(a+)b+"
🗄 Sequence |> regular expression combinator with 1 capturing groups
├─ (a+) |> Repeat |> Capture 1
└─ b+ |> Repeat
::Tuple{Vector{Char}, Vector{Char}}
julia> p("aaabb")
(['a', 'a', 'a'], ['b', 'b'])
julia> deepmap(MatchedSubSequence, p, Capture)("aaabb")
("aaa", ['b', 'b'])
julia> deepmap(length, p, re"b+")("abb")
(['a'], 2)Implementation is an example when the a custom leaf _deepmap method is useful and sufficient for deepmap_parser.
CombinedParsers._deepmap — Function_deepmap(parser, predicate, f, a...; kw...)Implementation example when the a custom leaf _deepmap method is useful and sufficient for deepmap_parser.
if dodeepmap(parser, predicate)
map(f,parser, a...; kw...)
else
parser
endCombinedParsers.dodeepmap — Functiondodeepmap(parser, predicate)parser == predicate. Specialize for custom predicate type.
dodeepmap(parser, predicate::Type)sub_parser isa predicate
dodeepmap(parser, predicate::Function)predicate(sub_parser)
dodeepmap(parser::NamedParser, predicate::Symbol)sub_parser.name == predicate
String match results
Base.:! — FunctionMatchedSubSequence(x)
(!)(x::CombinedParser)
(!)(x::CombinedParser{<:Any,<:AbstractString})Parser Base.map transformation getting
- either the matched
SubString - or an
InternedStrings.interned copy thereof iifresult_type<:AbstractStringalready.
Transformation does not evaluate get(parser.transform,...).
julia> Repeat(AnyChar())
.* AnyValue |> Repeat
::Vector{Char}
julia> !Repeat(AnyChar())
.* AnyValue |> Repeat |> !
::SubString{String}
julia> !!Repeat(AnyChar())
.* AnyValue |> Repeat |> ! |> map(intern)
::String
MatchedSubSequence currently only support SubString, extension to Vector views requires minor effort.
map(MatchedSubSequence(), SubArray{Int,1}, parser)constructor is required (currently no sequence type is known at construction).getfunction currently missing
CombinedParsers.MatchedSubSequence — TypeMatchedSubSequence(x)
(!)(x::CombinedParser)
(!)(x::CombinedParser{<:Any,<:AbstractString})Parser Base.map transformation getting
- either the matched
SubString - or an
InternedStrings.interned copy thereof iifresult_type<:AbstractStringalready.
Transformation does not evaluate get(parser.transform,...).
julia> Repeat(AnyChar())
.* AnyValue |> Repeat
::Vector{Char}
julia> !Repeat(AnyChar())
.* AnyValue |> Repeat |> !
::SubString{String}
julia> !!Repeat(AnyChar())
.* AnyValue |> Repeat |> ! |> map(intern)
::String
MatchedSubSequence currently only support SubString, extension to Vector views requires minor effort.
map(MatchedSubSequence(), SubArray{Int,1}, parser)constructor is required (currently no sequence type is known at construction).getfunction currently missing
CombinedParsers.MatchRange — TypeCombinedParsers.Constant — Typemap_constant(constant, p::CombinedParser)
parser((p,constant)::Pair)Construct a Base.map Transformation{<:Constant} resulting in p when calling get fast, instead of computing result from state, if parser(p) matches.
julia> parser("constant" | "fixed" => :constant)
|🗄 Either => :constant
├─ constant
└─ fixed
::SymbolIf the Pair key is a symbol, a NamedParser is created.
julia> parser(:constant => "constant" | "fixed")
|🗄 Either |> with_name(:constant)
├─ constant
└─ fixed
::SubString{String}CombinedParsers.IndexAt — TypeCombinedParsers.infer_result_type — Functioninfer_result_type(f::Function,Tc::Type,p::CombinedParser,onerror::AbstractString,ts::Type...; throw_empty_union=true)Used by Parser Transformations to infer result type of a parser. Throws error if type inference fails, if throwemptyunion=true.