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

Rename runCofree to unTerm.

This commit is contained in:
Rob Rix 2017-09-08 16:46:35 +01:00
parent f2cd05d5fc
commit 185818d8bd
8 changed files with 15 additions and 16 deletions

View File

@ -17,8 +17,8 @@ error "Avoid return" =
error "use pure" = free . Pure ==> pure
error "use wrap" = free . Free ==> wrap
error "use extract" = headF . runCofree ==> extract
error "use unwrap" = tailF . runCofree ==> unwrap
error "use extract" = headF . unTerm ==> extract
error "use unwrap" = tailF . unTerm ==> unwrap
error "avoid head" = head
where note = "head is partial; consider using Data.Maybe.listToMaybe"

View File

@ -59,7 +59,7 @@ alignPatch sources patch = case patch of
(alignSyntax' that (snd sources) term2)
where getRange = byteRange . extract
alignSyntax' :: (forall a. Identity a -> Join These a) -> Source -> Term f (Record fields) -> [Join These (Term [] (Record fields))]
alignSyntax' side source term = hylo (alignSyntax side cofree getRange (Identity source)) runCofree (Identity <$> term)
alignSyntax' side source term = hylo (alignSyntax side cofree getRange (Identity source)) unTerm (Identity <$> term)
this = Join . This . runIdentity
that = Join . That . runIdentity

View File

@ -32,7 +32,7 @@ makeTerm a = makeTerm' a . inj
-- | Lift a union and an annotation into a term, ensuring the annotation encompasses all children.
makeTerm' :: (HasCallStack, Semigroup a, Foldable f) => a -> f (Term f a) -> Term f a
makeTerm' a f = (sconcat (a :| (headF . runCofree <$> toList f)) :< f)
makeTerm' a f = (sconcat (a :| (headF . unTerm <$> toList f)) :< f)
-- | Lift non-empty syntax into a term, injecting the syntax into a union & appending all subterms.annotations to make the new terms annotation.
makeTerm1 :: (HasCallStack, f :< fs, Semigroup a, Apply1 Foldable fs) => f (Term (Union fs) a) -> Term (Union fs) a
@ -41,7 +41,7 @@ makeTerm1 = makeTerm1' . inj
-- | Lift a non-empty union into a term, appending all subterms.annotations to make the new terms annotation.
makeTerm1' :: (HasCallStack, Semigroup a, Foldable f) => f (Term f a) -> Term f a
makeTerm1' f = case toList f of
a : _ -> makeTerm' (headF (runCofree a)) f
a : _ -> makeTerm' (headF (unTerm a)) f
_ -> error "makeTerm1': empty structure"
-- | Construct an empty term at the current position.

View File

@ -292,7 +292,7 @@ withStateCallStack :: Maybe (String, SrcLoc) -> State ast grammar -> (HasCallSta
withStateCallStack callSite state action = withCallStack (freezeCallStack (fromCallSiteList (maybe id (:) callSite (stateCallSites state)))) action
skipTokens :: Symbol grammar => State ast grammar -> State ast grammar
skipTokens state = state { stateNodes = dropWhile ((/= Regular) . symbolType . nodeSymbol . headF . runCofree) (stateNodes state) }
skipTokens state = state { stateNodes = dropWhile ((/= Regular) . symbolType . nodeSymbol . headF . unTerm) (stateNodes state) }
-- | Advances the state past the current (head) node (if any), dropping it off stateNodes, and updating stateOffset & statePos to its end; or else returns the state unchanged.
advanceState :: State ast grammar -> State ast grammar

View File

@ -303,12 +303,12 @@ unitVector d hash = listArray (0, d - 1) ((* invMagnitude) <$> components)
-- | Test the comparability of two root 'Term's in O(1).
canCompareTerms :: ComparabilityRelation f fields -> Term f (Record fields) -> Term f (Record fields) -> Bool
canCompareTerms canCompare = canCompare `on` runCofree
canCompareTerms canCompare = canCompare `on` unTerm
-- | Recursively test the equality of two 'Term's in O(n).
equalTerms :: Eq1 f => ComparabilityRelation f fields -> Term f (Record fields) -> Term f (Record fields) -> Bool
equalTerms canCompare = go
where go a b = canCompareTerms canCompare a b && liftEq go (tailF (runCofree a)) (tailF (runCofree b))
where go a b = canCompareTerms canCompare a b && liftEq go (tailF (unTerm a)) (tailF (unTerm b))
-- | Strips the head annotation off a term annotated with non-empty records.

View File

@ -8,7 +8,7 @@ module Term
, termSize
, alignTermWith
, cofree
, runCofree
, unTerm
, extract
, unwrap
, hoistCofree
@ -41,7 +41,7 @@ type SyntaxTerm fields = Term Syntax (Record fields)
type SyntaxTermF fields = TermF Syntax (Record fields)
instance (NFData (f (Term f a)), NFData a, Functor f) => NFData (Term f a) where
rnf = rnf . runCofree
rnf = rnf . unTerm
instance (NFData a, NFData (f b)) => NFData (TermF f a b) where
rnf (a :<< s) = rnf a `seq` rnf s `seq` ()
@ -73,8 +73,8 @@ alignTermWith compare contrast combine = go
cofree :: TermF f a (Term f a) -> Term f a
cofree (a :<< f) = a :< f
runCofree :: Term f a -> TermF f a (Term f a)
runCofree (a :< f) = a :<< f
unTerm :: Term f a -> TermF f a (Term f a)
unTerm (a :< f) = a :<< f
hoistCofree :: Functor f => (forall a. f a -> g a) -> Term f a -> Term g a
hoistCofree f = go where go (a :< r) = a :< f (fmap go r)
@ -90,7 +90,7 @@ instance Apply1 Pretty1 fs => Pretty1 (Union fs) where
type instance Base (Term f a) = TermF f a
instance Functor f => Recursive (Term f a) where project = runCofree
instance Functor f => Recursive (Term f a) where project = unTerm
instance Functor f => Corecursive (Term f a) where embed = cofree
instance Functor f => Comonad (Term f) where

View File

@ -5,7 +5,6 @@ module TreeSitter
) where
import Category
import qualified Control.Comonad.Trans.Cofree as CofreeF (CofreeF(..))
import Control.Exception
import Control.Monad ((<=<))
import Data.Blob

View File

@ -211,7 +211,7 @@ functionInfo = Range 0 0 :. C.Function :. sourceSpanBetween (0,0) (0,0) :. Nil
-- Filter tiers for terms that we consider "meaniningful" in TOC summaries.
isMeaningfulTerm :: ListableF (Term Syntax) a -> Bool
isMeaningfulTerm a = case runCofree (unListableF a) of
isMeaningfulTerm a = case unTerm (unListableF a) of
(_ :< S.Indexed _) -> False
(_ :< S.Fixed _) -> False
(_ :< S.Commented _ _) -> False
@ -220,7 +220,7 @@ isMeaningfulTerm a = case runCofree (unListableF a) of
-- Filter tiers for terms if the Syntax is a Method or a Function.
isMethodOrFunction :: HasField fields Category => ListableF (Term Syntax) (Record fields) -> Bool
isMethodOrFunction a = case runCofree (unListableF a) of
isMethodOrFunction a = case unTerm (unListableF a) of
(_ :< S.Method{}) -> True
(_ :< S.Function{}) -> True
(a :< _) | getField a == C.Function -> True