I have been converting a a time parser from using RegEx to the elm-tools/parser. It is working now but is about 30% slower than the RegEx version.
Should I expect the Parser to be on par with RegEx?
I do suspect the parser I created could be written to be more efficient. Take the below example which handles seconds. It has a smell, but I am not sure how to make it better.
If seconds are not present, then the default is 0. Seconds can appear as “:00”, “:00.00…”, or “:00,00…” (the comma makes it a bit more difficult)
seconds : Parser Float
seconds =
oneOf
[ succeed
(\seconds ms ->
(toString seconds ++ "." ++ ms)
|> String.toFloat
|> Result.withDefault 0.0
)
|. symbol ":"
|= twoInts
|= oneOf
[ succeed identity
|. oneOf [ symbol ".", symbol "," ]
|= manyInts
, succeed "0"
]
, succeed 0
]
Thanks!
Full source