mirror of
https://github.com/github/semantic.git
synced 2024-12-01 09:15:01 +03:00
Clean and retain elseClause for If statements that are not If statements
This commit is contained in:
parent
649155c784
commit
62db2939f8
@ -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)]
|
||||
|
Loading…
Reference in New Issue
Block a user