Skip to content

Commit 3edbdd0

Browse files
committed
Stub in parsing.
1 parent 3baf0b4 commit 3edbdd0

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

semantic-analysis/semantic-analysis.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ library
7878
, filepath
7979
, fused-effects ^>= 1.1
8080
, hashable
81+
, language-python
8182
, semantic-source ^>= 0.2
8283
, text ^>= 1.2.3.1
8384
, transformers ^>= 0.5

semantic-analysis/src/Analysis/Syntax/Python.hs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ module Analysis.Syntax.Python
99
-- * Abstract interpretation
1010
, eval0
1111
, eval
12+
-- * Parsing
13+
, parse
1214
) where
1315

1416
import Analysis.Effect.Domain hiding ((:>>>))
@@ -22,7 +24,11 @@ import Control.Effect.Reader
2224
import Data.Function (fix)
2325
import Data.List.NonEmpty (NonEmpty)
2426
import Data.Text (Text)
27+
import qualified Language.Python.Common.AST as Py
28+
import qualified Language.Python.Common.SrcLocation as Py
29+
import Language.Python.Version3.Parser
2530
import Source.Span (Span)
31+
import System.FilePath (takeBaseName)
2632

2733
-- Syntax
2834

@@ -80,3 +86,13 @@ eval eval = \case
8086
Locate s t -> local (setSpan s) (eval t)
8187
where
8288
setSpan s r = r{ refSpan = s }
89+
90+
91+
-- Parsing
92+
93+
parse :: FilePath -> IO (Py.Module Py.SrcSpan)
94+
parse path = do
95+
src <- readFile path
96+
case parseModule src (takeBaseName path) of
97+
Left err -> fail (show err)
98+
Right (m, _) -> pure m

0 commit comments

Comments
 (0)