Renamed to lambda-phi/parser. It is published under that name, and new versions come out there.
Versions published as davidcavazos/parser still install under that name. 2 versions of 12 come from the new location (see their notes). 10 versions could not be recovered and cannot be installed.
Unavailable. Nobody can download this version any more, with elm or with the Lamdera compiler: github.com/lambda-phi/parser exists but has no tag 2.1.0; Software Heritage has not archived the repo; no fork with tag 2.1.0 found (60 same-name repos checked); no cached copy. Use another version.
Error reporting utilities.
Dumps the error into a human-readable format.
import Parser exposing (Parser, andThen, char, drop, into, parse, spaces, succeed, take)
import Parser.Common exposing (number)
spaces
|> andThen (\_ -> number)
|> parse " abc "
|> Result.mapError (dump "filename.txt")
--> Err
--> [ "[ERROR] filename.txt:1:3: I was expecting a digit [0-9].\n"
--> ++ "I got stuck when I got the character 'a'."
--> , ""
--> , "1| abc "
--> , " ^"
--> ]
type alias Point =
{ x : Float
, y : Float
}
point : Parser Point
point =
into "Point"
(succeed Point
|> drop (char '(')
|> take number
|> drop (char ',')
|> take number
|> drop (char ')')
)
spaces
|> andThen (\_ -> point)
|> parse " (12,) "
|> Result.mapError (dump "filename.txt")
--> Err
--> [ "[ERROR] filename.txt:1:7: I was expecting a digit [0-9].\n"
--> ++ "I got stuck when I got the character ')'."
--> , " in Point at line 1:3"
--> , ""
--> , "1| (12,) "
--> , " ~~~~^"
--> ]
type alias Line =
{ p1 : Point
, p2 : Point
}
line : Parser Line
line =
into "Line"
(succeed Line
|> drop (char '[')
|> take point
|> drop (char ',')
|> take point
|> drop (char ']')
)
spaces
|> andThen (\_ -> line)
|> parse " [(12,34),(56,)] "
|> Result.mapError (dump "filename.txt")
--> Err
--> [ "[ERROR] filename.txt:1:16: I was expecting a digit [0-9].\n"
--> ++ "I got stuck when I got the character ')'."
--> , " in Point at line 1:12"
--> , " in Line at line 1:3"
--> , ""
--> , "1| [(12,34),(56,)] "
--> , " ~~~~^"
--> ]Dumps a snippet of the input text that caused the parser to fail.
import Parser exposing (Parser, andThen, char, drop, into, parse, spaces, succeed, take)
import Parser.Common exposing (number)
type alias Point =
{ x : Float
, y : Float
}
point : Parser Point
point =
into "Point"
(succeed Point
|> drop (char '(')
|> drop spaces
|> take number
|> drop spaces
|> drop (char ',')
|> drop spaces
|> take number
|> drop spaces
|> drop (char ')')
)
spaces
|> andThen (\_ -> point)
|> parse " (12,) "
|> Result.mapError dumpCodeSnippet
--> Err
--> [ "1| (12,) "
--> , " ~~~~^"
--> ]
spaces
|> andThen (\_ -> point)
|> parse
(String.join "\n"
[ " "
, " ( "
, " 12 "
, " , "
, " ) "
, " "
]
)
|> Result.mapError dumpCodeSnippet
--> Err
--> [ "2| ( "
--> , "3| 12 "
--> , "4| , "
--> , "5| ) "
--> , " +~~^"
--> ]
Creates an error message from an
Errordata.