diff --git a/src/Language/Ruby/Syntax.hs b/src/Language/Ruby/Syntax.hs index c0a3c582f..07edd9c2e 100644 --- a/src/Language/Ruby/Syntax.hs +++ b/src/Language/Ruby/Syntax.hs @@ -51,12 +51,16 @@ type Syntax = '[ , Statement.Alias , Statement.Assignment , Statement.Break + , Statement.Catch , Statement.Continue + , Statement.Else + , Statement.Finally , Statement.ForEach , Statement.If , Statement.Return , Statement.ScopeEntry , Statement.ScopeExit + , Statement.Try , Statement.Undef , Statement.While , Statement.Yield @@ -82,7 +86,7 @@ topLevelStatement = handleError $ <|> statement statement :: Assignment -statement = handleError $ +statement = -- handleError $ comment <|> undef <|> alias @@ -115,6 +119,7 @@ statement = handleError $ <|> methodCall <|> call <|> subscript + <|> begin where mk s construct = makeTerm <$> symbol s <*> children ((construct .) . fromMaybe <$> emptyTerm <*> optional (symbol ArgumentList *> children statement)) statements :: Assignment @@ -268,8 +273,18 @@ methodCall = makeTerm <$> symbol MethodCall <*> children (Expression.Call <$> na call :: Assignment call = makeTerm <$> symbol Call <*> children (Expression.MemberAccess <$> statement <*> statement) --- begin :: Assignment --- begin = makeTerm <$> symbol Begin <*> children (Statement.Try) +-- TODO: Multiple rescue clauses not quite working +begin :: Assignment +begin = makeTerm <$> symbol Begin <*> children (Statement.Try <$> many statement <*> many elseRescueEnsure) + where + elseRescueEnsure = + makeTerm <$> symbol Else <*> children (Statement.Else <$> emptyTerm <*> statements) + <|> makeTerm <$> symbol Ensure <*> children (Statement.Finally <$> statements) + <|> makeTerm <$> symbol Rescue <*> children (Statement.Catch <$> (makeTerm <$> location <*> many exception) <*> statements) + exception = + makeTerm <$> symbol Exceptions <*> children (many identifier) + <|> makeTerm <$> symbol ExceptionVariable <*> children (many identifier) + assignment' :: Assignment assignment'