mirror of
https://github.com/github/semantic.git
synced 2024-12-22 06:11:49 +03:00
Stub in a function to produce AST for Ruby.
This commit is contained in:
parent
9d6a8b438d
commit
ce075494cf
@ -7,12 +7,14 @@ module TreeSitter
|
||||
import Prologue hiding (Constructor)
|
||||
import Category
|
||||
import Data.Record
|
||||
import qualified Data.Syntax.Assignment as A
|
||||
import Language
|
||||
import qualified Language.C as C
|
||||
import qualified Language.Go as Go
|
||||
import qualified Language.JavaScript as JS
|
||||
import qualified Language.TypeScript as TS
|
||||
import qualified Language.Ruby as Ruby
|
||||
import qualified Language.Ruby.Syntax as Ruby
|
||||
import Parser
|
||||
import Range
|
||||
import Source
|
||||
@ -25,6 +27,7 @@ import qualified Syntax as S
|
||||
import Term
|
||||
import Text.Parser.TreeSitter hiding (Language(..))
|
||||
import qualified Text.Parser.TreeSitter as TS
|
||||
import qualified Text.Parser.TreeSitter.Ruby as Ruby
|
||||
import SourceSpan
|
||||
import Info
|
||||
|
||||
@ -41,6 +44,25 @@ treeSitterParser language grammar blob = do
|
||||
pure term
|
||||
|
||||
|
||||
parseRubyToAST :: Source -> IO (A.AST Ruby.Grammar)
|
||||
parseRubyToAST source = do
|
||||
document <- ts_document_new
|
||||
ts_document_set_language document Ruby.tree_sitter_ruby
|
||||
root <- withCStringLen (toText source) $ \ (source, len) -> do
|
||||
ts_document_set_input_string_with_length document source len
|
||||
ts_document_parse document
|
||||
alloca (\ rootPtr -> do
|
||||
ts_document_root_node_p document rootPtr
|
||||
peek rootPtr)
|
||||
|
||||
ast <- toAST root source
|
||||
|
||||
ts_document_free document
|
||||
pure ast
|
||||
where toAST Node{..} source = do
|
||||
pure $ A.Rose (A.Node (toEnum (fromIntegral nodeSymbol)) "") []
|
||||
|
||||
|
||||
-- | Return a parser for a tree sitter language & document.
|
||||
documentToTerm :: Language -> Ptr Document -> Parser (Syntax.Syntax Text) (Record DefaultFields)
|
||||
documentToTerm language document SourceBlob{..} = do
|
||||
|
Loading…
Reference in New Issue
Block a user