You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not exactly sure what is going on, or what is being accepted, but here is an example of Parser.int eating input starting with the letter e (although it doesn't succeed, it needs to be backtracked in order for a following parser to succeed).
moduleMainexposing (main)
importBrowserimportHtmlexposing (Html, br, button, div, text)
importParserexposing (..)
importSet{-| An Ellie example showing some parsing madness-}type Expr=IntInt|FuncStringStringmain =
div
[][ text "This is what we expect: ", run expr """a("arg")"""|>Debug.toString |> text
, br [][], text "And this: ", run expr """b("something")"""|>Debug.toString |> text
, br [][], text "And this too: ", run expr """myFuncName("stuff")"""|>Debug.toString |> text
, br [][], br [][], text "But, if the function name start with an `e`:", run expr """e("what the devil?")"""|>Debug.toString |> text
, br [][], text "Another example:", run expr """exerciseScoreToInt("blahblah")"""|>Debug.toString |> text
, br [][], br [][], text "This doesn't happen with any other letter, and if you take away the `int` parse then it works."]expr:ParserExprexpr =
oneOf
[ backtrackable int |> map Int, func
]func:ParserExprfunc =
succeed Func|= backtrackable
(variable
{ start =Char.isLower
, inner =Char.isAlphaNum
, reserved =Set.empty
})|. backtrackable (symbol "(")|. symbol "\""|= getChompedString (chompWhile (\c -> c /='"'))|. symbol "\""|. symbol ")"|. end
The text was updated successfully, but these errors were encountered:
mdevlamynck [5:59 PM]
Well actually, it's a bit tricky. The parser is correct in that it does not accept things like e10 as valid Int. But before failing it advances in the input. Since it's not backtrackable by default, your oneOf does not try the other possibilities. (edited)
ccapndave [6:00 PM]
Hmm
I see
mdevlamynck [6:01 PM]
So it's more the fact that int is acts as backtrackable with certain input that is weird.
ccapndave [6:01 PM]
At the very least there should be docs about it
No-one is going to add backtrackable just in case
I'm not exactly sure what is going on, or what is being accepted, but here is an example of
Parser.int
eating input starting with the lettere
(although it doesn't succeed, it needs to be backtracked in order for a following parser to succeed).https://ellie-app.com/4cD7gfngmNVa1
The text was updated successfully, but these errors were encountered: