Inspired by email-parser code , we try a different approach to Parse Wiki-Style Links.
textWithoutLink code
textWithoutLink : Parser String textWithoutLink = chompUntil "[" |> getChompedString -- |> andThen checkLink
Chompers
Test case
module MainSpec exposing (suite) import Expect import Main exposing (result) import Test exposing (..) suite : Test suite = describe "textWithoutLink" [ test "should chompUntil [ |> getChompedString |> andThen checkLink if internal or external" <| \() -> let expected = Ok "Federated Wiki" actual = result in Expect.equal actual expected ]
Main.elm code
result : Result (List Parser.DeadEnd) String result = let str = "This is an Internal Link: Federated Wiki" in Parser.run textWithoutLink str
main code
main : Html.Html msg main = case result of Ok value -> Html.text ("Parsed value: " ++ value) Err error -> Html.text ("Parse error: " ++ Debug.toString error)
~
Error Handling in Elm discourse
type alias Error = { position : Int , message : String }
where the Type Annotation of result is
result : Result Error String
instead of
result : Result (List Parser.DeadEnd) String