1
1
mirror of https://github.com/github/semantic.git synced 2024-12-11 08:45:48 +03:00

Move toAST & anaM down.

This commit is contained in:
Rob Rix 2017-05-15 15:38:31 -04:00
parent f6dc76b8ec
commit 36465bfad6

View File

@ -72,17 +72,6 @@ parseRubyToTerm source = do
Just a -> pure (Just a)
_ -> traverse_ (putStrLn . ($ "") . A.showError source) errors >> pure Nothing
toAST :: Enum grammar => Node -> IO (A.RoseF (A.Node grammar) Node)
toAST node@Node{..} = do
let count = fromIntegral nodeChildCount
children <- allocaArray count $ \ childNodesPtr -> do
_ <- with nodeTSNode (\ nodePtr -> ts_node_copy_child_nodes nullPtr nodePtr childNodesPtr (fromIntegral count))
peekArray count childNodesPtr
pure $ A.RoseF (toEnum (fromIntegral nodeSymbol) :. nodeRange node :. nodeSpan node :. Nil) children
anaM :: (Corecursive t, Monad m, Traversable (Base t)) => (a -> m (Base t a)) -> a -> m t
anaM g = a where a = pure . embed <=< traverse a <=< g
-- | Parse Python to a list of Terms, printing any assignment errors to stdout. Intended for use in ghci, e.g.:
--
-- > Command.Files.readFile "/Users/rob/Desktop/test.rb" >>= parsePythonToTerm . source
@ -106,6 +95,17 @@ parsePythonToTerm source = do
Just a -> pure (Just a)
_ -> traverse_ (putStrLn . ($ "") . A.showError source) errors >> pure Nothing
toAST :: Enum grammar => Node -> IO (A.RoseF (A.Node grammar) Node)
toAST node@Node{..} = do
let count = fromIntegral nodeChildCount
children <- allocaArray count $ \ childNodesPtr -> do
_ <- with nodeTSNode (\ nodePtr -> ts_node_copy_child_nodes nullPtr nodePtr childNodesPtr (fromIntegral count))
peekArray count childNodesPtr
pure $ A.RoseF (toEnum (fromIntegral nodeSymbol) :. nodeRange node :. nodeSpan node :. Nil) children
anaM :: (Corecursive t, Monad m, Traversable (Base t)) => (a -> m (Base t a)) -> a -> m t
anaM g = a where a = pure . embed <=< traverse a <=< g
-- | Return a parser for a tree sitter language & document.
documentToTerm :: Language -> Ptr Document -> Parser (Syntax.Syntax Text) (Record DefaultFields)
documentToTerm language document SourceBlob{..} = do