Mercurial > repos > public > sbplib_julia
diff src/SbpOperators/readoperator.jl @ 831:760c11e81fd4 operator_storage_array_of_table
Introduce parse_tuple and parse_scalar and replace all external calls to parse_rational
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 12 Jan 2022 15:32:58 +0100 |
parents | 21ab60cc0a5c |
children | fc2ac236dd73 |
line wrap: on
line diff
--- a/src/SbpOperators/readoperator.jl Wed Jan 12 14:59:03 2022 +0100 +++ b/src/SbpOperators/readoperator.jl Wed Jan 12 15:32:58 2022 +0100 @@ -4,7 +4,8 @@ export get_stencil_set export parse_stencil -export parse_rational +export parse_scalar +export parse_tuple export sbp_operators_path @@ -32,6 +33,7 @@ # Parsing as rationals is intentional, allows preserving exactness, which can be lowered using converts or promotions later. # TODO: readoperator.jl file name? # TODO: Remove references to toml for dict-input arguments +# TODO: Documetning the format: Allows representing rationals as strings """ read_stencil_set(fn; filters) @@ -109,6 +111,22 @@ end end + +function parse_scalar(toml) + try + return parse_rational(toml) + catch e + throw(ArgumentError("must be a number or a string representing a number.")) + end +end + +function parse_tuple(toml) + if !(toml isa Array) + throw(ArgumentError("argument must be an array")) + end + return Tuple(parse_scalar.(toml)) +end + function parse_rational(toml) if toml isa String expr = Meta.parse(replace(toml, "/"=>"//"))