ParseNotEval
ParseNotEval.ParseNotEval — ModuleCreated in April, 2022 by chifi - an open source software dynasty. by team odd-data This software is MIT-licensed.
ParseNotEval
A module which extends Julia's parse() method to work with a set number of types. This is useful for file readers and recieving types through a request. If you are using this module, it is likely through OddFrames -> OddStructures
Module Composition
- ParseNotEval - High-level API
Base.parse — Methodparse(s::AbstractString) -> ::Any
Binded call for parse(::DataType{Any}, ::AbstractString). Parses string into assumed type. arguments
- T <: DataType; type to parse s into.
- s <: AbstractString; string to be parsed into type T.
example
parse("55")
Int64(55)Base.parse — Methodparse(T::Type{Pair}, s::AbstractArray) -> ::Array{T}
Parses each element inside of of s into type T. Replaces arguments that cannot be casted with missing. arguments
- T <: DataType; type to parse s into.
- s <: AbstractArray; the array to be casted.
example
example_input = ["55", "82", "hello"]
new = parse(Int64, example_input)
new
[55, 82, missing]Base.parse — Methodparse(T::Type{Pair}, s::Pair) -> ::Pair{Symbol, T}
Parses the pair value s[2] into type T. arguments
- T <: DataType; type to parse s into.
- s <: AbstractArray; the array to be casted.
example
example_input::Pair = :A => "5"
new::Pair = parse(Int64, example_input)
new
:A => 5Base.parse — Methodparse(T::Type{Any}, s::AbstractString) -> ::Any
Trys to guess the type of a string implicitly. For a more explicit assumption of type, try passing the type as the first argument. arguments
- T <: DataType; type to parse s into.
- s <: AbstractString; string to be parsed into type T.
example
example_input = "[5, 10, 15, 20]"
my_array::Array{Int64} = parse(Array, example_input)
[5, 10, 15, 20]
example_input = "5"
myint::Int64 = parse(Any, example_input)Base.parse — Methodparse(T::Type{Array}, s::AbstractString) -> ::Array{typeof(parse(Any, s))}
Parses s into type T. arguments
- T <: DataType; type to parse s into.
- s <: AbstractString; string to be parsed into type T.
example
example_input = "[5, 10, 15, 20]"
my_array::Array{Int64} = parse(Array, example_input)
[5, 10, 15, 20]
my_array::Array{Float64} = parse(Float64, my_array)
[5.0, 10.0, 15.0, 20.0]Base.parse — Methodparse(T::Type{DateTime}, s::AbstractString) -> ::DateTime
Parses a date with time, with appropriate formatting, from string to date. Requires '-' and ':' separators be used. arguments
- T <: DataType; type to parse s into.
- s <: AbstractString; string to be parsed into type T.
example
example_input::String = "1999-11-23:8000"
symb::DateTime = parse(DateTime, example_input)
typeof(myint) == DateTime
trueBase.parse — Methodparse(T::Type{Date}, s::AbstractString) -> ::Date
Parses a date, with appropriate formatting, from string to date. Requires '-' separators be used. arguments
- T <: DataType; type to parse s into.
- s <: AbstractString; string to be parsed into type T.
example
example_input::String = "1999-11-23"
symb::Date = parse(Date, example_input)
typeof(myint) == Date
trueBase.parse — Methodparse(T::Type{Dict}, s::AbstractString) -> ::Dict
Parses a dict. Can inclkude any of the following examples of input:
- JSON data; e.g. "{A:5, x:6}"
- Dict data; e.g. "A => [5, 10, 15, 20], B => [5, 10, 15, 20]"
arguments
- T <: DataType; type to parse s into.
- s <: AbstractString; string to be parsed into type T.
example
example_input::String = "{x => [5, 10, 15], y = [5, 8, 7]}"
my_dct::Dict = parse(Dict, example_input)
example_input::String = "{x : [5, 10, 15], y : [5, 8, 7]}"
my_dct::Dict = parse(Dict, example_input)
typeof(myint) == Dict
trueBase.parse — Methodparse(T::Type{Pair}, s::AbstractString) -> ::Pair
Parses a string s into type T. arguments
- T <: DataType; type to parse s into.
- s <: AbstractString; string to be parsed into type T.
example
example_input::String = "x => 5"
symb::Pair = parse(Pair, example_input)
typeof(myint) == Pair
trueBase.parse — Methodparse(T::Type{String}, s::AbstractString) -> ::String
Although parsing a string into a string is not necessary, the reason why the binding exists is so that if dims are parsed by type, they can still have a normal return whenever they are strings. arguments
- T <: DataType; type to parse s into.
- s <: AbstractString; string to be parsed into type T.
example
example_input = "5"
myint::Int64 = parse(String, example_input)
typeof(myint) == String
trueBase.parse — Methodparse(T::Type{Symbol}, s::AbstractString) -> ::Symbol
Parses a symbol, without the colon. It is really a simple binded call to the constructor Symbol(::AbstractString). arguments
- T <: DataType; type to parse s into.
- s <: AbstractString; string to be parsed into type T.
example
example_input::String = "hello"
symb::Symbol = parse(Symbol, example_input)
:hello
typeof(myint) == Symbol
true