Mercurial > lbo > hg > juliaplay
changeset 35:8208faa6c42f
JSON: Better struct coding
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Fri, 24 Mar 2023 20:04:38 +0100 |
parents | a36e3e66ae3e |
children | 03d20a4dd8f2 |
files | julia/parallel/ParallelProcessing/src/json.jl julia/parallel/ParallelProcessing/src/jsonparser.jl |
diffstat | 2 files changed, 8 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/julia/parallel/ParallelProcessing/src/json.jl Sun Mar 19 20:34:24 2023 +0100 +++ b/julia/parallel/ParallelProcessing/src/json.jl Fri Mar 24 20:04:38 2023 +0100 @@ -9,7 +9,7 @@ """Example for a method that can be derived straight from a struct definition and parses just a struct from a JSON object.""" -function take_struct!(t::Type{Details}, jp::JP)::Union{Nothing,Details} +function take_struct!(::Type{Details}, jp::JP)::Union{Nothing,Details} expect!(jp, '{') || return nothing level::Union{Nothing,String} = nothing
--- a/julia/parallel/ParallelProcessing/src/jsonparser.jl Sun Mar 19 20:34:24 2023 +0100 +++ b/julia/parallel/ParallelProcessing/src/jsonparser.jl Fri Mar 24 20:04:38 2023 +0100 @@ -152,29 +152,27 @@ take_val!(jp) end +function strip_ws!(jp::JP) + while !isend(jp) && isspace(jp.s[jp.pos]) + jp.pos += 1 + end +end + function takewhile!(jp::JP, pred::Function, stripws=true)::Union{Nothing,Tuple{Int,Int}} if stripws strip_ws!(jp) end if !isend(jp) && pred(current(jp)) a = jp.pos - b = a while !isend(jp) && pred(current(jp)) next!(jp) - b += 1 end - (a, b-1) + (a, jp.pos-1) else nothing end end -function strip_ws!(jp::JP) - while !isend(jp) && isspace(jp.s[jp.pos]) - jp.pos += 1 - end -end - function expect!(jp::JP, c::Char)::Bool strip_ws!(jp) if current(jp) == c