This repository was archived by the owner on Apr 1, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
semantic-analysis/src/Analysis/Syntax Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -93,6 +93,9 @@ l >>> r = T.Term (l :>> r)
9393noop :: T. Term Python v
9494noop = T. Term Noop
9595
96+ iff :: T. Term Python v -> T. Term Python v -> T. Term Python v -> T. Term Python v
97+ iff c t e = T. Term (Iff c t e)
98+
9699
97100-- Parsing
98101
@@ -101,13 +104,20 @@ parse path = do
101104 src <- readFile path
102105 case parseModule src (takeBaseName path) of
103106 Left err -> fail (show err)
104- Right (Py. Module ss, _) -> foldr (>>>) noop <$> traverse statement ss
107+ Right (Py. Module ss, _) -> suite ss
105108 where
106109 statement :: Py. Statement annot -> IO (T. Term Python Name )
107110 statement = \ case
108111 Py. Import is _ -> foldr ((>>>) . T. Term . Import ) noop <$> traverse importItem is
112+ Py. Conditional cs e _ -> foldr (\ (c, t) e -> iff <$> expr c <*> suite t <*> e) (suite e) cs
109113 _ -> fail " cannot ingest this Python statement"
114+ expr :: Py. Expr annot -> IO (T. Term Python Name )
115+ expr = \ case
116+ Py. Var v _ -> pure (T. Var (name (pack (ident v))))
117+ _ -> fail " cannot ingest this Python expression"
110118 ident :: Py. Ident annot -> String
111119 ident (Py. Ident s _) = s
112120 importItem :: Py. ImportItem annot -> IO (NonEmpty Text )
113121 importItem Py. ImportItem { Py. import_item_name = ns } = maybe (fail " " ) pure (nonEmpty (map (pack . ident) ns)) -- FIXME: "as" names
122+ suite :: [Py. Statement annot ] -> IO (T. Term Python Name )
123+ suite ss = foldr (>>>) noop <$> traverse statement ss
You can’t perform that action at this time.
0 commit comments