1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 08:54:07 +03:00

Add Data.Loc.fromTSSpan.

We'll probably change this so that Unmarshal can do this for us, but
this implementation will suffice for now.
This commit is contained in:
Patrick Thomson 2019-09-18 11:50:38 -04:00
parent 3d488ec7e7
commit 60fa4c82ab
2 changed files with 18 additions and 10 deletions

View File

@ -51,6 +51,7 @@ library
, semigroupoids ^>= 5.3
, text ^>= 1.2.3.1
, transformers ^>= 0.5.6
, tree-sitter == 0.3.0.0
, trifecta ^>= 2
, unordered-containers ^>= 0.2.10
hs-source-dirs: src

View File

@ -1,7 +1,9 @@
{-# LANGUAGE FlexibleInstances, GeneralizedNewtypeDeriving, MultiParamTypeClasses, OverloadedStrings, RecordWildCards, TypeOperators, UndecidableInstances #-}
{-# LANGUAGE FlexibleInstances, GeneralizedNewtypeDeriving, MultiParamTypeClasses, OverloadedStrings, RecordWildCards,
TypeOperators, UndecidableInstances #-}
module Data.Loc
( Loc(..)
, interactive
, fromTSSpan
, Span(..)
, emptySpan
, Pos(..)
@ -20,6 +22,7 @@ import Data.Text (Text, pack)
import Data.Text.Prettyprint.Doc (Pretty (..))
import GHC.Stack
import Prelude hiding (fail)
import qualified TreeSitter.Span as TreeSitter
data Loc = Loc
{ locPath :: !Text
@ -27,6 +30,10 @@ data Loc = Loc
}
deriving (Eq, Ord, Show)
fromTSSpan :: TreeSitter.Span -> Loc
fromTSSpan (TreeSitter.Span (TreeSitter.Pos a b) (TreeSitter.Pos c d))
= Loc mempty (Span (Pos a b) (Pos c d))
interactive :: Loc
interactive = Loc "<interactive>" emptySpan