Transformations to any result_type

CombinedParsers.TransformationType
Transformation(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_typeFunction
result_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.mapFunction
map(index::IndexAt, p::CombinedParser, a...)
map(constant, p::CombinedParser, a...)

Parser matching p, transforming ps parsing results to getindex(x,index) or constant.

See also: get, deepmap

map(f::Function, p::CombinedParser, a...)

Parser matching p, transforming parsing results (x) with function f(x,a...).

See also: get, deepmap

map(T::Type, p::CombinedParser, a...)

Parser matching p, transforming ps parsing result with constructor T(x,a...).

See also: get, deepmap

CombinedParsers.deepmapFunction
deepmap(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._deepmapFunction
_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
end
CombinedParsers.dodeepmapFunction
dodeepmap(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.:!Function
MatchedSubSequence(x)
(!)(x::CombinedParser)
(!)(x::CombinedParser{<:Any,<:AbstractString})

Parser Base.map transformation getting

  • either the matched SubString
  • or an InternedStrings.interned copy thereof iif result_type<:AbstractString already.

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
Warn

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).
  • get function currently missing
CombinedParsers.MatchedSubSequenceType
MatchedSubSequence(x)
(!)(x::CombinedParser)
(!)(x::CombinedParser{<:Any,<:AbstractString})

Parser Base.map transformation getting

  • either the matched SubString
  • or an InternedStrings.interned copy thereof iif result_type<:AbstractString already.

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
Warn

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).
  • get function currently missing
CombinedParsers.MatchRangeType
MatchRange(p::CombinedParser)

Construct a Base.mapTransformation{UnitRange{Int}} resulting in p when calling get fast, Succeed iif p succeeds, if so results in sequence match index UnitRange. Transformation does not evaluate get(parser.transform,...).

CombinedParsers.ConstantType
map_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 
::Symbol
Note

If the Pair key is a symbol, a NamedParser is created.

julia> parser(:constant => "constant" | "fixed")
|🗄 Either |> with_name(:constant)
├─ constant 
└─ fixed 
::SubString{String}
CombinedParsers.IndexAtType

Struct for fast access to an index of a Transformation.

julia> using CombinedParsers.Regexp

julia> p = re"(?:a|b*)."[1]
🗄 Sequence[1]
├─ |🗄 Either
│  ├─ a 
│  └─ b*  |> Repeat
└─ [^\n] ValueNotIn
::Union{Char, Vector{Char}}

See also getindex, Sequence.

CombinedParsers.infer_result_typeFunction
infer_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.