Elm Exactly
Results / elm-parser /

ParserSequenceTest

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
Checks `Parser.sequence` with forbidden and with optional trailing separators.

With `Forbidden`, `"[1, 2, 3]"` (spaces after the commas) gives
`Ok [1,2,3]`. With `Optional`, `"[1,2,]"` gives `Ok [1,2]`.

Among what is not tested: rejection of a trailing separator under `Forbidden`,
and the `Mandatory` setting.

Results

elm-0.19.1

passran in 45 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
items: Ok [1,2,3]
trailing_ok: Ok [1,2]

elm-0.19.2

passran in 83 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
items: Ok [1,2,3]
trailing_ok: Ok [1,2]

elm-0.19.3

passran in 52 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
trailing_ok: Ok [1,2]
items: Ok [1,2,3]

lamdera-1.5.0

passran in 81 ms
Output
trailing_ok: Ok [1,2]
items: Ok [1,2,3]

Discussions

Discuss this test·Search the discussions on GitHub

Discussions are on GitHub; one about this test has [t:elm-parser/ParserSequenceTest] in its title.

Source

The -- CHECK: lines give the expected output.

module ParserSequenceTest exposing (main)
{-| Checks `Parser.sequence` with forbidden and with optional trailing separators.
With `Forbidden`, `"[1, 2, 3]"` (spaces after the commas) gives
`Ok [1,2,3]`. With `Optional`, `"[1,2,]"` gives `Ok [1,2]`.
Among what is not tested: rejection of a trailing separator under `Forbidden`,
and the `Mandatory` setting.
-}
-- CHECK: items: Ok [1,2,3]
-- CHECK: trailing_ok: Ok [1,2]
import Html exposing (text)
import Parser exposing (Trailing(..))
intList : Parser.Parser (List Int)
intList =
Parser.sequence
{ start = "["
, separator = ","
, end = "]"
, spaces = Parser.spaces
, item = Parser.int
, trailing = Forbidden
}
intListTrailing : Parser.Parser (List Int)
intListTrailing =
Parser.sequence
{ start = "["
, separator = ","
, end = "]"
, spaces = Parser.spaces
, item = Parser.int
, trailing = Optional
}
main =
let
r1 = Parser.run intList "[1, 2, 3]"
_ = Debug.log "items" r1
r2 = Parser.run intListTrailing "[1,2,]"
_ = Debug.log "trailing_ok" r2
in
text "done"