mirror of
https://github.com/github/semantic.git
synced 2024-12-24 23:42:31 +03:00
24 lines
735 B
Haskell
24 lines
735 B
Haskell
module Parsers where
|
|
|
|
import Diff
|
|
import Range
|
|
import Parser
|
|
import Syntax
|
|
import Term
|
|
import TreeSitter
|
|
import Control.Comonad.Cofree
|
|
|
|
parserForType :: String -> Parser
|
|
parserForType mediaType = maybe lineByLineParser parseTreeSitterFile $ languageForType mediaType
|
|
|
|
lineByLineParser :: Parser
|
|
lineByLineParser input = return . root . Indexed $ case foldl annotateLeaves ([], 0) lines of
|
|
(leaves, _) -> leaves
|
|
where
|
|
lines = Prelude.lines input
|
|
root syntax = Info (Range 0 $ length input) mempty :< syntax
|
|
leaf charIndex line = Info (Range charIndex $ charIndex + length line) mempty :< Leaf line
|
|
annotateLeaves (accum, charIndex) line =
|
|
(accum ++ [ leaf charIndex line ]
|
|
, charIndex + length line + 1)
|