mirror of
https://github.com/github/semantic.git
synced 2024-11-24 08:54:07 +03:00
Add a specific Data.Abstract.Path with path/module name helpers
This commit is contained in:
parent
197c8d8506
commit
0904796674
@ -51,6 +51,7 @@ library
|
||||
, Data.Abstract.Live
|
||||
, Data.Abstract.ModuleTable
|
||||
, Data.Abstract.Number
|
||||
, Data.Abstract.Path
|
||||
, Data.Abstract.Type
|
||||
, Data.Abstract.Value
|
||||
-- General datatype definitions & generic algorithms
|
||||
|
@ -5,9 +5,7 @@ import Prologue
|
||||
import Data.Term
|
||||
import Data.ByteString (intercalate)
|
||||
import qualified Data.List.NonEmpty as NonEmpty
|
||||
import qualified Data.ByteString.Char8 as BC
|
||||
import qualified Data.ByteString as B
|
||||
import Data.Char (ord)
|
||||
import Data.Abstract.Path
|
||||
|
||||
-- | The type of variable names.
|
||||
type Name = NonEmpty ByteString
|
||||
@ -24,24 +22,6 @@ qualifiedName = NonEmpty.fromList
|
||||
pathToQualifiedName :: ByteString -> Name
|
||||
pathToQualifiedName = qualifiedName . splitOnPathSeparator
|
||||
|
||||
-- | Split a 'ByteString' path on `/`, stripping quotes and any `./` prefix.
|
||||
splitOnPathSeparator :: ByteString -> [ByteString]
|
||||
splitOnPathSeparator = splitOnPathSeparator' id
|
||||
|
||||
splitOnPathSeparator' :: (ByteString -> ByteString) -> ByteString -> [ByteString]
|
||||
splitOnPathSeparator' f = BC.split '/' . f . dropRelativePrefix . stripQuotes
|
||||
|
||||
stripQuotes :: ByteString -> ByteString
|
||||
stripQuotes = B.filter (/= fromIntegral (ord '\"'))
|
||||
|
||||
dropRelativePrefix :: ByteString -> ByteString
|
||||
dropRelativePrefix = BC.dropWhile (== '/') . BC.dropWhile (== '.')
|
||||
|
||||
dropExtension :: ByteString -> ByteString
|
||||
dropExtension path = case BC.split '.' path of
|
||||
[] -> path
|
||||
xs -> BC.intercalate "." (Prelude.init xs)
|
||||
|
||||
-- | User friendly 'ByteString' of a qualified 'Name'.
|
||||
friendlyName :: Name -> ByteString
|
||||
friendlyName xs = intercalate "." (NonEmpty.toList xs)
|
||||
|
24
src/Data/Abstract/Path.hs
Normal file
24
src/Data/Abstract/Path.hs
Normal file
@ -0,0 +1,24 @@
|
||||
module Data.Abstract.Path where
|
||||
|
||||
import Prologue
|
||||
import qualified Data.ByteString.Char8 as BC
|
||||
import qualified Data.ByteString as B
|
||||
import Data.Char (ord)
|
||||
|
||||
-- | Split a 'ByteString' path on `/`, stripping quotes and any `./` prefix.
|
||||
splitOnPathSeparator :: ByteString -> [ByteString]
|
||||
splitOnPathSeparator = splitOnPathSeparator' id
|
||||
|
||||
splitOnPathSeparator' :: (ByteString -> ByteString) -> ByteString -> [ByteString]
|
||||
splitOnPathSeparator' f = BC.split '/' . f . dropRelativePrefix . stripQuotes
|
||||
|
||||
stripQuotes :: ByteString -> ByteString
|
||||
stripQuotes = B.filter (/= fromIntegral (ord '\"'))
|
||||
|
||||
dropRelativePrefix :: ByteString -> ByteString
|
||||
dropRelativePrefix = BC.dropWhile (== '/') . BC.dropWhile (== '.')
|
||||
|
||||
dropExtension :: ByteString -> ByteString
|
||||
dropExtension path = case BC.split '.' path of
|
||||
[] -> path
|
||||
xs -> BC.intercalate "." (Prelude.init xs)
|
@ -8,6 +8,7 @@ module Language.Go.Assignment
|
||||
|
||||
import Assigning.Assignment hiding (Assignment, Error)
|
||||
import Data.Abstract.FreeVariables
|
||||
import Data.Abstract.Path
|
||||
import Data.Record
|
||||
import Data.Syntax (contextualize, emptyTerm, parseError, handleError, infixContext, makeTerm, makeTerm', makeTerm'', makeTerm1)
|
||||
import Language.Go.Grammar as Grammar
|
||||
|
@ -5,6 +5,7 @@ import Control.Monad (unless)
|
||||
import Control.Abstract.Value (MonadValue)
|
||||
import Data.Abstract.Environment
|
||||
import Data.Abstract.Evaluatable
|
||||
import Data.Abstract.Path
|
||||
import Data.Abstract.Value (LocationFor)
|
||||
import Diffing.Algorithm
|
||||
import Prelude hiding (fail)
|
||||
|
Loading…
Reference in New Issue
Block a user