1
1
mirror of https://github.com/github/semantic.git synced 2024-12-21 05:41:54 +03:00

Use the AST synonym.

This commit is contained in:
Rob Rix 2017-07-12 15:40:54 -04:00
parent 00221d421f
commit c4fc6e5c4a
2 changed files with 3 additions and 3 deletions

View File

@ -41,7 +41,7 @@ import TreeSitter
-- | A parser from 'Source' onto some term type.
data Parser term where
-- | A parser producing 'AST' using a 'TS.Language'.
ASTParser :: (Bounded grammar, Enum grammar) => Ptr TS.Language -> Parser (Cofree [] (Record (grammar ': Location)))
ASTParser :: (Bounded grammar, Enum grammar) => Ptr TS.Language -> Parser (AST grammar)
-- | A parser producing an à la carte term given an 'AST'-producing parser and an 'Assignment' onto 'Term's in some syntax type. Assignment errors will result in a top-level 'Syntax.Error' node.
AssignmentParser :: (Enum grammar, Eq grammar, Show grammar, Symbol grammar, Syntax.Error (Error grammar) :< fs, Foldable (Union fs), Functor (Union fs), Recursive ast, Foldable (Base ast))
=> Parser ast -- ^ A parser producing AST.

View File

@ -41,7 +41,7 @@ treeSitterParser language grammar source = bracket ts_document_new ts_document_f
-- | Parse 'Source' with the given 'TS.Language' and return its AST.
parseToAST :: (Bounded grammar, Enum grammar) => Ptr TS.Language -> Source -> IO (Cofree [] (Record (grammar ': A.Location)))
parseToAST :: (Bounded grammar, Enum grammar) => Ptr TS.Language -> Source -> IO (A.AST grammar)
parseToAST language source = bracket ts_document_new ts_document_free $ \ document -> do
ts_document_set_language document language
root <- unsafeUseAsCStringLen (sourceBytes source) $ \ (source, len) -> do
@ -53,7 +53,7 @@ parseToAST language source = bracket ts_document_new ts_document_free $ \ docume
anaM toAST root
toAST :: (Bounded grammar, Enum grammar) => Node -> IO (CofreeF [] (Record (grammar ': A.Location)) Node)
toAST :: (Bounded grammar, Enum grammar) => Node -> IO (Base (A.AST grammar) Node)
toAST node@Node{..} = do
let count = fromIntegral nodeChildCount
children <- allocaArray count $ \ childNodesPtr -> do