mirror of
https://github.com/github/semantic.git
synced 2024-12-22 22:31:36 +03:00
Handle merge conflicts
This commit is contained in:
parent
9e9e48bdc2
commit
5b52870b35
30
src/Parse.hs
30
src/Parse.hs
@ -23,7 +23,12 @@ import TreeSitter
|
||||
import Text.Parser.TreeSitter.Language
|
||||
import Renderer.JSON()
|
||||
|
||||
data ParseJSON f a = ParseJSON { category :: Text, range :: Range, syntax :: Syntax f a, sourceText :: SourceText } deriving (Show, Generic, ToJSON, Functor)
|
||||
data ParseJSON f a =
|
||||
ParseJSON
|
||||
{ category :: Text
|
||||
, range :: Range
|
||||
, sourceText :: SourceText
|
||||
} deriving (Show, Generic, ToJSON, Functor)
|
||||
|
||||
run :: Arguments -> IO ()
|
||||
run Arguments{..} = do
|
||||
@ -31,25 +36,20 @@ run Arguments{..} = do
|
||||
|
||||
let sourceBlobs = Source.SourceBlob <$> sources <*> pure mempty <*> filePaths <*> pure (Just Source.defaultPlainBlob)
|
||||
let parsers = parserWithSource <$> filePaths
|
||||
let parsersAndBlobs = zip parsers sourceBlobs
|
||||
|
||||
terms <- traverse (uncurry folder) parsersAndBlobs
|
||||
terms <- zipWithM (\parser sourceBlob -> parser sourceBlob) parsers sourceBlobs
|
||||
|
||||
traverse_ (\ (parseJSON :< annotation) -> putStrLn . encodePretty $ parseJSON) (runCofree <$> terms)
|
||||
let termsWithParseJSON = (cata algebra <$> terms)
|
||||
|
||||
traverse_ (\ (annotation :< syntax) -> putStrLn annotation) (head $ runCofree <$> termsWithParseJSON)
|
||||
|
||||
pure ()
|
||||
where
|
||||
folder parser sourceBlob = do
|
||||
term <- parser sourceBlob
|
||||
pure $ (ana coalgebra :: (HasField fields Range, HasField fields Category, HasField fields SourceText) => Cofree (Syntax f) (Record fields) -> Cofree (ParseJSON f) (Record fields)) term
|
||||
where
|
||||
coalgebra term =
|
||||
case runCofree term of
|
||||
(annotation :< syntax) -> annotation :< ParseJSON category' range' syntax sourceText'
|
||||
where
|
||||
category' = toS $ Info.category annotation
|
||||
range' = characterRange annotation
|
||||
sourceText' = Info.sourceText annotation
|
||||
algebra term = case term of
|
||||
(annotation :< syntax) -> cofree $ encodePretty (ParseJSON category' range' sourceText') :< syntax
|
||||
where category' = toS $ Info.category annotation
|
||||
range' = characterRange annotation
|
||||
sourceText' = Info.sourceText annotation
|
||||
|
||||
-- | Return a parser that decorates with the cost of a term and its children.
|
||||
parserWithCost :: FilePath -> Parser (Syntax Text) (Record '[Cost, Range, Category, SourceSpan])
|
||||
|
2
vendor/tree-sitter-parsers
vendored
2
vendor/tree-sitter-parsers
vendored
@ -1 +1 @@
|
||||
Subproject commit cd7e07714802c61aa2dbf3850440f3c83cfcf45e
|
||||
Subproject commit de7bfb99606c9b5151d9e877d43c73cd9d0a44e9
|
Loading…
Reference in New Issue
Block a user