mirror of
https://github.com/github/semantic.git
synced 2024-12-25 07:55:12 +03:00
Compile IfStatement.
This commit is contained in:
parent
c3184f0354
commit
c4351553cb
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user