mirror of
https://github.com/github/semantic.git
synced 2024-12-24 15:35:14 +03:00
Convert lineByLineParser to return text
This commit is contained in:
parent
12df3007f1
commit
e2817db885
@ -7,17 +7,18 @@ import Syntax
|
||||
import Term
|
||||
import TreeSitter
|
||||
import Control.Comonad.Cofree
|
||||
import qualified Data.Text as T
|
||||
|
||||
parserForType :: String -> Parser
|
||||
parserForType :: T.Text -> 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
|
||||
lines = T.lines input
|
||||
root syntax = Info (Range 0 $ T.length input) mempty :< syntax
|
||||
leaf charIndex line = Info (Range charIndex $ charIndex + T.length line) mempty :< Leaf line
|
||||
annotateLeaves (accum, charIndex) line =
|
||||
(accum ++ [ leaf charIndex line ]
|
||||
, charIndex + length line + 1)
|
||||
, charIndex + T.length line + 1)
|
||||
|
Loading…
Reference in New Issue
Block a user