1
1
mirror of https://github.com/github/semantic.git synced 2024-12-30 10:27:45 +03:00

runParser takes a Blob.

This commit is contained in:
Rob Rix 2017-07-19 14:47:07 -04:00
parent 6dd56e5bd9
commit 97c8b90c83
2 changed files with 12 additions and 11 deletions

View File

@ -11,6 +11,7 @@ module Parser
) where ) where
import qualified CMark import qualified CMark
import Data.Blob
import Data.Functor.Foldable hiding (fold, Nil) import Data.Functor.Foldable hiding (fold, Nil)
import Data.Record import Data.Record
import Data.Source as Source import Data.Source as Source
@ -72,19 +73,19 @@ pythonParser = AssignmentParser (ASTParser tree_sitter_python) headF Python.assi
markdownParser :: Parser Markdown.Term markdownParser :: Parser Markdown.Term
markdownParser = AssignmentParser MarkdownParser (\ (node@Node{..} :< _) -> node { nodeSymbol = toGrammar nodeSymbol }) Markdown.assignment markdownParser = AssignmentParser MarkdownParser (\ (node@Node{..} :< _) -> node { nodeSymbol = toGrammar nodeSymbol }) Markdown.assignment
runParser :: Parser term -> Source -> IO term runParser :: Parser term -> Blob -> IO term
runParser parser = case parser of runParser parser = case parser of
ASTParser language -> parseToAST language ASTParser language -> parseToAST language . blobSource
AssignmentParser parser by assignment -> \ source -> do AssignmentParser parser by assignment -> \ blob -> do
ast <- runParser parser source ast <- runParser parser blob
case assignBy by assignment source ast of case assignBy by assignment (blobSource blob) ast of
Left err -> do Left err -> do
printError source err printError (blobSource blob) err
pure (errorTerm source) pure (errorTerm (blobSource blob))
Right term -> pure term Right term -> pure term
TreeSitterParser language tslanguage -> treeSitterParser language tslanguage TreeSitterParser language tslanguage -> treeSitterParser language tslanguage . blobSource
MarkdownParser -> pure . cmarkParser MarkdownParser -> pure . cmarkParser . blobSource
LineByLineParser -> pure . lineByLineParser LineByLineParser -> pure . lineByLineParser . blobSource
errorTerm :: Syntax.Error :< fs => Source -> Term (Union fs) (Record Location) errorTerm :: Syntax.Error :< fs => Source -> Term (Union fs) (Record Location)
errorTerm source = cofree ((totalRange source :. totalSpan source :. Nil) :< inj (Syntax.Error [])) errorTerm source = cofree ((totalRange source :. totalSpan source :. Nil) :< inj (Syntax.Error []))

View File

@ -80,7 +80,7 @@ distributeFoldMap toTask inputs = fmap fold (distribute (fmap toTask inputs))
-- | Execute a 'Task', yielding its result value in 'IO'. -- | Execute a 'Task', yielding its result value in 'IO'.
runTask :: Task a -> IO a runTask :: Task a -> IO a
runTask = iterFreerA $ \ task yield -> case task of runTask = iterFreerA $ \ task yield -> case task of
Parse parser blob -> runParser parser (blobSource blob) >>= yield Parse parser blob -> runParser parser blob >>= yield
Decorate algebra term -> yield (decoratorWithAlgebra algebra term) Decorate algebra term -> yield (decoratorWithAlgebra algebra term)
Diff differ terms -> yield (differ terms) Diff differ terms -> yield (differ terms)
Render renderer input -> yield (renderer input) Render renderer input -> yield (renderer input)