mirror of
https://github.com/github/semantic.git
synced 2025-01-03 04:51:57 +03:00
Extract & generalize toAST.
This commit is contained in:
parent
c2cc74a33c
commit
8f35aa4d14
@ -64,13 +64,6 @@ parseRubyToAST source = do
|
||||
|
||||
ts_document_free document
|
||||
pure ast
|
||||
where toAST :: Node -> IO (A.RoseF (A.Node Ruby.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
|
||||
|
||||
-- | Parse Ruby to a list of Terms, printing any assignment errors to stdout. Intended for use in ghci, e.g.:
|
||||
--
|
||||
@ -84,6 +77,14 @@ parseRubyToTerm source = do
|
||||
_ -> 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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user