This repository was archived by the owner on Apr 1, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
semantic-analysis/src/Analysis/Syntax Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,9 @@ l >>> r = T.Term (l :>> r)
93
93
noop :: T. Term Python v
94
94
noop = T. Term Noop
95
95
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
+
96
99
97
100
-- Parsing
98
101
@@ -101,13 +104,20 @@ parse path = do
101
104
src <- readFile path
102
105
case parseModule src (takeBaseName path) of
103
106
Left err -> fail (show err)
104
- Right (Py. Module ss, _) -> foldr (>>>) noop <$> traverse statement ss
107
+ Right (Py. Module ss, _) -> suite ss
105
108
where
106
109
statement :: Py. Statement annot -> IO (T. Term Python Name )
107
110
statement = \ case
108
111
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
109
113
_ -> 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"
110
118
ident :: Py. Ident annot -> String
111
119
ident (Py. Ident s _) = s
112
120
importItem :: Py. ImportItem annot -> IO (NonEmpty Text )
113
121
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