From 97c8b90c836a06789d397a1d0d4e9b6de4dd60f8 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 19 Jul 2017 14:47:07 -0400 Subject: [PATCH] runParser takes a Blob. --- src/Parser.hs | 21 +++++++++++---------- src/Semantic/Task.hs | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Parser.hs b/src/Parser.hs index 640fee3ae..4b597b21e 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -11,6 +11,7 @@ module Parser ) where import qualified CMark +import Data.Blob import Data.Functor.Foldable hiding (fold, Nil) import Data.Record import Data.Source as Source @@ -72,19 +73,19 @@ pythonParser = AssignmentParser (ASTParser tree_sitter_python) headF Python.assi markdownParser :: Parser Markdown.Term 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 - ASTParser language -> parseToAST language - AssignmentParser parser by assignment -> \ source -> do - ast <- runParser parser source - case assignBy by assignment source ast of + ASTParser language -> parseToAST language . blobSource + AssignmentParser parser by assignment -> \ blob -> do + ast <- runParser parser blob + case assignBy by assignment (blobSource blob) ast of Left err -> do - printError source err - pure (errorTerm source) + printError (blobSource blob) err + pure (errorTerm (blobSource blob)) Right term -> pure term - TreeSitterParser language tslanguage -> treeSitterParser language tslanguage - MarkdownParser -> pure . cmarkParser - LineByLineParser -> pure . lineByLineParser + TreeSitterParser language tslanguage -> treeSitterParser language tslanguage . blobSource + MarkdownParser -> pure . cmarkParser . blobSource + LineByLineParser -> pure . lineByLineParser . blobSource errorTerm :: Syntax.Error :< fs => Source -> Term (Union fs) (Record Location) errorTerm source = cofree ((totalRange source :. totalSpan source :. Nil) :< inj (Syntax.Error [])) diff --git a/src/Semantic/Task.hs b/src/Semantic/Task.hs index 45600433a..485f3967c 100644 --- a/src/Semantic/Task.hs +++ b/src/Semantic/Task.hs @@ -80,7 +80,7 @@ distributeFoldMap toTask inputs = fmap fold (distribute (fmap toTask inputs)) -- | Execute a 'Task', yielding its result value in 'IO'. runTask :: Task a -> IO a 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) Diff differ terms -> yield (differ terms) Render renderer input -> yield (renderer input)