1
1
mirror of https://github.com/github/semantic.git synced 2024-11-28 18:23:44 +03:00

Clean and retain elseClause for If statements that are not If statements

This commit is contained in:
Rick Winfrey 2016-10-13 12:34:48 -05:00
parent 649155c784
commit 62db2939f8

View File

@ -163,16 +163,8 @@ toVarDecl child = cofree $ setCategory (extract child) VarDecl :< S.VarDecl chil
-- | and satisfies arbitrarily long else-if clauses.
toElseIf :: (HasField fields Category) => Term (S.Syntax Text) (Record fields) -> Term (S.Syntax Text) (Record fields)
toElseIf child = case unwrap child of
-- Base case, this stops the recursive toElseIf calls.
S.If expr thenClause [] -> cofree $ setCategory (extract child) If :< S.If expr thenClause []
-- For each If term, determine if the else clause contains another If term.
-- For each nested If term, recursively construct If Syntaxes until the else clause
-- is empty, or the else clause is not a nested If term.
S.If expr thenClause elseClause -> case unwrap . head $ elseClause of
S.If{} -> cofree $ setCategory (extract child) If :< S.If expr thenClause (toElseIf <$> elseClause)
_ -> cofree $ setCategory (extract child) If :< S.If expr thenClause []
-- This is bottom, to satisfy exhuastive pattern matching.
_ -> cofree $ setCategory (extract child) If :< S.If child child []
S.If expr thenClause elseClause -> cofree $ setCategory (extract child) If :< S.If expr thenClause (toElseIf <$> elseClause)
_ -> child
toTuple :: Term (S.Syntax Text) (Record fields) -> [Term (S.Syntax Text) (Record fields)]
toTuple child | S.Indexed [key,value] <- unwrap child = [cofree (extract child :< S.Pair key value)]