1
1
mirror of https://github.com/github/semantic.git synced 2025-01-02 12:23:08 +03:00

First pass at begin, rescue, ensure, else

This commit is contained in:
Timothy Clem 2017-07-06 14:43:49 -07:00
parent 40a2fc6820
commit 5cebfd3b6c

View File

@ -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'