Elm Exactly
Results / elm-parser /

ParserAdvancedSequenceTest

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
`Parser.Advanced.sequence` parses a bracketed, comma-separated list of integers.

The sequence starts with `"["`, ends with `"]"`, separates items with `","`,
allows `spaces` around them and forbids a trailing separator. Run on
`"[1,2,3]"`, it returns `Ok [1,2,3]`, the items in input order.

Among what is not tested: whitespace inside the brackets, an empty list, and
the `Optional` and `Mandatory` trailing modes.

Results

elm-0.19.1

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

elm-0.19.2

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

elm-0.19.3

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

lamdera-1.5.0

passran in 90 ms
Output
list: 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/ParserAdvancedSequenceTest] in its title.

Source

The -- CHECK: lines give the expected output.

module ParserAdvancedSequenceTest exposing (main)
{-| `Parser.Advanced.sequence` parses a bracketed, comma-separated list of integers.
The sequence starts with `"["`, ends with `"]"`, separates items with `","`,
allows `spaces` around them and forbids a trailing separator. Run on
`"[1,2,3]"`, it returns `Ok [1,2,3]`, the items in input order.
Among what is not tested: whitespace inside the brackets, an empty list, and
the `Optional` and `Mandatory` trailing modes.
-}
-- CHECK: list: Ok [1,2,3]
import Html exposing (text)
import Parser.Advanced as PA exposing (Trailing(..))
type Prob
= ExpectedStart
| ExpectedEnd
| ExpectedSep
| ExpectedInt
intList : PA.Parser c Prob (List Int)
intList =
PA.sequence
{ start = PA.Token "[" ExpectedStart
, separator = PA.Token "," ExpectedSep
, end = PA.Token "]" ExpectedEnd
, spaces = PA.spaces
, item = PA.int ExpectedInt ExpectedInt
, trailing = Forbidden
}
main =
let
result = PA.run intList "[1,2,3]"
_ = Debug.log "list" result
in
text "done"