-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect result when using nested case expressions #67
Comments
Good find. |
In my fork I wrote some code that seems to work fine in this situation. caseExpression : OpTable -> Parser s Expression
caseExpression ops =
let
binding =
lazy <| \() ->
(,)
<$> (wsAndComments *> expression ops)
<*> (symbol "->" *> expression ops)
in
lazy <| \() ->
withLocation (\location ->
Case <$> (symbol "case" *> expression ops) <* symbol "of" <*> many
( lookAhead (wsAndComments *>
(primitive (\state inputStream ->
(state, inputStream, Ok (location.column <= (currentLocation inputStream).column))
)))
|> andThen (\isIndented ->
case isIndented of
True -> wsAndComments *> binding
False -> spaces_ *> binding
)
)
) results in FunctionDeclaration
(Function "foo" []
(Case (Variable ["pattern"])
([ (Variable ["A"], Integer 1)
, (Variable ["B"], Case (Variable ["variable"])
([ (Variable ["C"],Integer 2)
, (Variable ["_"],Integer 3)
]
)
)
, (Variable ["_"],Integer 4)]))) You would need to fit it into your code as it uses The idea is to remember what was the first column of It won't work with tabs and spaces mixed! Still it is enough for the scope of core code I test on. Hope it helps! |
Hi! I noticed an incorrect AST when parsing something along the likes of
Which results in an AST like the following
I expect the first case expression to have 3 patterns (A, B and _ ) and the nested one under B to have 2 (C and _ ), but they respectively have 2 ((A, B) and (C, _ and _ ).
The text was updated successfully, but these errors were encountered: