mirror of
https://github.com/github/semantic.git
synced 2024-12-26 08:25:19 +03:00
Print out a scope graph
Co-Authored-By: Patrick Thomson <patrickt@users.noreply.github.com>
This commit is contained in:
parent
6ff8abbe41
commit
1a94c25d32
@ -2,15 +2,21 @@
|
|||||||
module Main (main) where
|
module Main (main) where
|
||||||
|
|
||||||
import qualified Data.ByteString as ByteString
|
import qualified Data.ByteString as ByteString
|
||||||
import Language.Python.ScopeGraph
|
import qualified Data.ScopeGraph as ScopeGraph
|
||||||
|
import qualified Data.ScopeGraph as ScopeGraph
|
||||||
|
import qualified Language.Python ()
|
||||||
import qualified TreeSitter.Python.AST as Py
|
import qualified TreeSitter.Python.AST as Py
|
||||||
import qualified TreeSitter.Python as TSP
|
import qualified TreeSitter.Python as TSP
|
||||||
import qualified TreeSitter.Unmarshal as TS
|
import qualified TreeSitter.Unmarshal as TS
|
||||||
|
import qualified Source.Source as Source
|
||||||
import Source.Span
|
import Source.Span
|
||||||
import Source.Range
|
import Source.Range
|
||||||
|
import Source.Loc
|
||||||
|
import System.Exit (die)
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
file <- ByteString.readFile "semantic-python/test/fixtures/1-01-empty-module.py"
|
file <- ByteString.readFile "semantic-python/test/fixtures/1-01-empty-module.py"
|
||||||
tree <- TS.parseByteString @Py.Module @(Range, Span) TSP.tree_sitter_python file
|
tree <- TS.parseByteString @Py.Module @Loc TSP.tree_sitter_python file
|
||||||
print (show tree)
|
pyModule <- either die pure tree
|
||||||
|
print =<< (ScopeGraph.runScopeGraph (Source.fromUTF8 file) pyModule)
|
||||||
|
@ -23,11 +23,18 @@ data Node a = Node
|
|||||||
instance Eq (Node a) where
|
instance Eq (Node a) where
|
||||||
(==) = (==) `on` ident
|
(==) = (==) `on` ident
|
||||||
|
|
||||||
data ScopeGraph a = ScopeGraph (Graph (Node a))
|
instance Show a => Show (Node a) where
|
||||||
|
-- TODO: This is dropping ident field in Node
|
||||||
|
show = show . contents
|
||||||
|
|
||||||
|
|
||||||
|
newtype ScopeGraph a = ScopeGraph (Graph (Node a))
|
||||||
|
deriving (Show)
|
||||||
|
|
||||||
data Info = Ref Text
|
data Info = Ref Text
|
||||||
| Scope
|
| Scope
|
||||||
| Root
|
| Root
|
||||||
|
deriving (Show)
|
||||||
|
|
||||||
type SGM =
|
type SGM =
|
||||||
( ReaderC (ScopeGraph Info)
|
( ReaderC (ScopeGraph Info)
|
||||||
|
Loading…
Reference in New Issue
Block a user