1
1
mirror of https://github.com/github/semantic.git synced 2024-12-25 07:55:12 +03:00

Compile IfStatement.

This commit is contained in:
Rob Rix 2019-06-11 12:29:09 -04:00
parent c3184f0354
commit c4351553cb
No known key found for this signature in database
GPG Key ID: F188A01508EA1CF7

View File

@ -1,4 +1,4 @@
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE DefaultSignatures, RecordWildCards #-}
module Language.Python.Core
( compile
) where
@ -24,5 +24,18 @@ instance Compile Py.Module where
compile (Module Nothing) = pure Unit
compile (Module (Just statements)) = block <$> traverse compile statements
instance Compile Py.CompoundStatement
instance Compile Py.CompoundStatement where
compile (IfStatementCompoundStatement statement) = compile statement
compile other = defaultCompile other
instance Compile Py.IfStatement where
compile IfStatement{..} = If <$> compile condition <*> compile consequence <*> case alternative of
Nothing -> pure Unit
Just clauses -> foldr clause (pure Unit) clauses
where clause (Left (ElifClause{..})) rest = If <$> compile condition <*> compile consequence <*> rest
clause (Right (ElseClause body)) _ = compile body
instance Compile Py.Expression
instance Compile Py.Block
instance Compile Py.SimpleStatement