mirror of
https://github.com/github/semantic.git
synced 2024-12-29 18:06:14 +03:00
Merge pull request #1651 from github/fix-hlints
Take a pass at fixing/silencing linter hints.
This commit is contained in:
commit
3315096629
3
HLint.hs
3
HLint.hs
@ -4,6 +4,9 @@ import "hint" HLint.Generalise
|
||||
|
||||
ignore "Use mappend"
|
||||
ignore "Redundant do"
|
||||
-- TODO: investigate whether cost-center analysis is better with lambda-case than it was
|
||||
ignore "Use lambda-case"
|
||||
|
||||
error "generalize ++" = (++) ==> (<>)
|
||||
-- AMP fallout
|
||||
error "generalize mapM" = mapM ==> traverse
|
||||
|
@ -125,4 +125,4 @@ converge f = loop
|
||||
|
||||
-- | Nondeterministically write each of a collection of stores & return their associated results.
|
||||
scatter :: (Alternative m, Foldable t, MonadEvaluator term value m) => t (a, Heap (LocationFor value) value) -> m a
|
||||
scatter = foldMapA (\ (value, heap') -> putHeap heap' *> pure value)
|
||||
scatter = foldMapA (\ (value, heap') -> putHeap heap' $> value)
|
||||
|
@ -6,7 +6,7 @@ module Analysis.Abstract.Evaluating
|
||||
) where
|
||||
|
||||
import Control.Abstract.Evaluator
|
||||
import Control.Monad.Effect hiding (run)
|
||||
import Control.Monad.Effect
|
||||
import Control.Monad.Effect.Fail
|
||||
import Control.Monad.Effect.Reader
|
||||
import Control.Monad.Effect.State
|
||||
|
@ -244,7 +244,7 @@ runAssignment source = \ assignment state -> go assignment state >>= requireExha
|
||||
Children child -> do
|
||||
(a, state') <- go child state { stateNodes = toList f, stateCallSites = maybe id (:) (tracingCallSite t) stateCallSites } >>= requireExhaustive (tracingCallSite t)
|
||||
yield a (advanceState state' { stateNodes = stateNodes, stateCallSites = stateCallSites })
|
||||
Choose choices _ handler | Just choice <- Table.lookup (nodeSymbol node) choices -> (go choice state `catchError` (maybe throwError (flip go state .) handler)) >>= uncurry yield
|
||||
Choose choices _ handler | Just choice <- Table.lookup (nodeSymbol node) choices -> (go choice state `catchError` maybe throwError (flip go state .) handler) >>= uncurry yield
|
||||
_ -> anywhere (Just node)
|
||||
|
||||
anywhere node = case runTracing t of
|
||||
@ -269,7 +269,7 @@ requireExhaustive callSite (a, state) = let state' = skipTokens state in case st
|
||||
Term (In node _) : _ -> Left (withStateCallStack callSite state (nodeError [] node))
|
||||
|
||||
withStateCallStack :: Maybe (String, SrcLoc) -> State ast grammar -> (HasCallStack => a) -> a
|
||||
withStateCallStack callSite state action = withCallStack (freezeCallStack (fromCallSiteList (maybe id (:) callSite (stateCallSites state)))) action
|
||||
withStateCallStack callSite state = withCallStack (freezeCallStack (fromCallSiteList (maybe id (:) callSite (stateCallSites state))))
|
||||
|
||||
skipTokens :: Symbol grammar => State ast grammar -> State ast grammar
|
||||
skipTokens state = state { stateNodes = dropWhile ((/= Regular) . symbolType . nodeSymbol . termAnnotation) (stateNodes state) }
|
||||
@ -376,3 +376,5 @@ instance (Enum grammar, Ix grammar, Show grammar, Show1 ast) => Show1 (Assignmen
|
||||
Fail s -> showsUnaryWith showsPrec "Fail" d s
|
||||
where showChild = liftShowsPrec sp sl
|
||||
showChildren = liftShowList sp sl
|
||||
|
||||
{-# ANN module ("HLint: ignore Avoid return" :: String) #-}
|
||||
|
@ -286,11 +286,11 @@ instance (Alternative m, MonadEnvironment Type m, MonadFail m, MonadFresh m, Mon
|
||||
liftComparison (Concrete _) left right = case (left, right) of
|
||||
(Type.Float, Int) -> pure Bool
|
||||
(Int, Type.Float) -> pure Bool
|
||||
_ -> unify left right *> pure Bool
|
||||
_ -> unify left right $> Bool
|
||||
liftComparison Generalized left right = case (left, right) of
|
||||
(Type.Float, Int) -> pure Int
|
||||
(Int, Type.Float) -> pure Int
|
||||
_ -> unify left right *> pure Int
|
||||
_ -> unify left right $> Bool
|
||||
|
||||
apply op params = do
|
||||
tvar <- fresh
|
||||
|
@ -3,7 +3,7 @@ module Control.Effect where
|
||||
|
||||
import qualified Control.Monad.Effect as Effect
|
||||
import Control.Monad.Effect.Fail
|
||||
import Control.Monad.Effect.Internal hiding (run)
|
||||
import Control.Monad.Effect.Internal
|
||||
import Control.Monad.Effect.NonDetEff
|
||||
import Control.Monad.Effect.Reader
|
||||
import Control.Monad.Effect.State
|
||||
|
@ -1,4 +1,4 @@
|
||||
{-# LANGUAGE GeneralizedNewtypeDeriving, MultiParamTypeClasses, StandaloneDeriving, TypeFamilies #-}
|
||||
{-# LANGUAGE GeneralizedNewtypeDeriving, MultiParamTypeClasses, TypeFamilies #-}
|
||||
module Data.Abstract.Environment
|
||||
( Environment
|
||||
, addresses
|
||||
|
@ -66,7 +66,7 @@ decim = SomeNumber . Decimal
|
||||
-- on two 'Number' values and return a temporarily-indeterminate 'SomeNumber'
|
||||
-- value. At the callsite, we can then unwrap the 'SomeNumber' and handle the
|
||||
-- specific cases.
|
||||
--
|
||||
--
|
||||
-- Promote a function on 'Real' values into one operating on 'Number's.
|
||||
-- You pass things like @+@ and @-@ here.
|
||||
liftReal :: (forall n . Real n => n -> n -> n)
|
||||
@ -94,5 +94,5 @@ liftIntegralFrac _ g (Decimal i) (Decimal j) = decim (g i j)
|
||||
liftedExponent :: Number a -> Number b -> SomeNumber
|
||||
liftedExponent (Integer i) (Integer j) = whole (i ^ j)
|
||||
liftedExponent (Ratio i) (Integer j) = ratio (i ^^ j)
|
||||
liftedExponent i j = decim (fromFloatDigits ((munge i) ** (munge j)))
|
||||
liftedExponent i j = decim (fromFloatDigits (munge i ** munge j))
|
||||
where munge = (toRealFloat . toScientific) :: Number a -> Double
|
||||
|
@ -12,7 +12,7 @@ import Data.Abstract.Number
|
||||
import qualified Data.Abstract.Type as Type
|
||||
import Data.Scientific (Scientific)
|
||||
import Prologue
|
||||
import Prelude hiding (Float, Integer, String, Rational, fail)
|
||||
import Prelude hiding (Float, Integer, String, Rational)
|
||||
import qualified Prelude
|
||||
|
||||
type ValueConstructors
|
||||
|
@ -3,6 +3,7 @@ module Data.Align.Generic where
|
||||
|
||||
import Control.Applicative
|
||||
import Control.Monad
|
||||
import Data.Functor (($>))
|
||||
import Data.List.NonEmpty (NonEmpty(..))
|
||||
import Data.Maybe (fromMaybe)
|
||||
import Data.Proxy
|
||||
@ -52,7 +53,7 @@ instance GAlign Par1 where
|
||||
|
||||
-- | 'GAlign' over non-parameter fields. Only equal values are aligned.
|
||||
instance Eq c => GAlign (K1 i c) where
|
||||
galignWith _ (K1 a) (K1 b) = guard (a == b) *> pure (K1 b)
|
||||
galignWith _ (K1 a) (K1 b) = guard (a == b) $> K1 b
|
||||
|
||||
-- | 'GAlign' over applications over parameters.
|
||||
instance GAlign f => GAlign (Rec1 f) where
|
||||
|
@ -24,7 +24,7 @@ import Data.Bifunctor
|
||||
import Data.Bitraversable
|
||||
import Data.Foldable (asum)
|
||||
import Data.Functor.Classes
|
||||
import Data.Functor.Foldable hiding (fold)
|
||||
import Data.Functor.Foldable
|
||||
import Data.JSON.Fields
|
||||
import Data.Mergeable (Mergeable(sequenceAlt))
|
||||
import Data.Patch
|
||||
|
@ -46,7 +46,7 @@ class GShow1 f where
|
||||
-- | showsPrec function for an application of the type constructor based on showsPrec and showList functions for the argument type.
|
||||
gliftShowsPrec :: GShow1Options -> (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
|
||||
|
||||
data GShow1Options = GShow1Options { optionsUseRecordSyntax :: Bool }
|
||||
newtype GShow1Options = GShow1Options { optionsUseRecordSyntax :: Bool }
|
||||
|
||||
defaultGShow1Options :: GShow1Options
|
||||
defaultGShow1Options = GShow1Options { optionsUseRecordSyntax = False }
|
||||
|
@ -47,7 +47,7 @@ instance Mergeable Maybe where
|
||||
instance Mergeable Identity where merge f = fmap Identity . f . runIdentity
|
||||
|
||||
instance (Apply Functor fs, Apply Mergeable fs) => Mergeable (Union fs) where
|
||||
merge f u = apply' (Proxy :: Proxy Mergeable) (\ reinj g -> reinj <$> merge f g) u
|
||||
merge f = apply' (Proxy :: Proxy Mergeable) (\ reinj g -> reinj <$> merge f g)
|
||||
|
||||
|
||||
-- Generics
|
||||
|
@ -50,7 +50,7 @@ instance {-# OVERLAPPABLE #-} HasField (field ': fields) field where
|
||||
|
||||
|
||||
instance (Show h, Show (Record t)) => Show (Record (h ': t)) where
|
||||
showsPrec n (h :. t) = showParen (n > 0) $ showsPrec 1 h . showString " :. " . showsPrec 0 t
|
||||
showsPrec n (h :. t) = showParen (n > 0) $ showsPrec 1 h . showString " :. " . shows t
|
||||
|
||||
instance Show (Record '[]) where
|
||||
showsPrec _ Nil = showString "Nil"
|
||||
|
@ -5,7 +5,7 @@ import Data.Abstract.Evaluatable
|
||||
import Data.Abstract.Number (liftIntegralFrac, liftReal, liftedExponent)
|
||||
import Data.Fixed
|
||||
import Diffing.Algorithm
|
||||
import Prelude hiding (fail)
|
||||
import Prelude
|
||||
import Prologue hiding (apply)
|
||||
|
||||
-- | Typical prefix function application, like `f(x)` in many languages, or `f x` in Haskell.
|
||||
|
@ -76,7 +76,7 @@ removeUnderscores = B.filter (/= '_')
|
||||
-- | Strip suffixes from floating-point literals so as to handle Python's
|
||||
-- TODO: tree-sitter-python needs some love so that it parses j-suffixed floats as complexen
|
||||
dropAlphaSuffix :: ByteString -> ByteString
|
||||
dropAlphaSuffix = B.takeWhile (\x -> x `notElem` ("lLjJiI" :: [Char]))
|
||||
dropAlphaSuffix = B.takeWhile (\x -> x `notElem` ("lLjJiI" :: Prelude.String))
|
||||
|
||||
-- | This is the shared function that munges a bytestring representation of a float
|
||||
-- so that it can be parsed to a @Scientific@ later. It takes as its arguments a list of functions, which
|
||||
|
@ -4,7 +4,7 @@ module Data.Syntax.Statement where
|
||||
import qualified Data.Abstract.Environment as Env
|
||||
import Data.Abstract.Evaluatable
|
||||
import Diffing.Algorithm
|
||||
import Prelude hiding (fail)
|
||||
import Prelude
|
||||
import Prologue
|
||||
|
||||
-- | Conditional. This must have an else block, which can be filled with some default value when omitted in the source, e.g. 'pure ()' for C-style if-without-else or 'pure Nothing' for Ruby-style, in both cases assuming some appropriate Applicative context into which the If will be lifted.
|
||||
|
@ -95,8 +95,8 @@ algorithmForTerms :: Diffable syntax
|
||||
-> Algorithm (Term syntax ann1) (Term syntax ann2) (Diff syntax ann1 ann2) (Diff syntax ann1 ann2)
|
||||
algorithmForTerms t1@(Term (In ann1 f1)) t2@(Term (In ann2 f2))
|
||||
= mergeFor t1 t2
|
||||
<|> deleteF . In ann1 <$> subalgorithmFor byDeleting (flip mergeFor t2) f1
|
||||
<|> insertF . In ann2 <$> subalgorithmFor byInserting ( mergeFor t1) f2
|
||||
<|> deleteF . In ann1 <$> subalgorithmFor byDeleting (`mergeFor` t2) f1
|
||||
<|> insertF . In ann2 <$> subalgorithmFor byInserting (mergeFor t1) f2
|
||||
where mergeFor (Term (In ann1 f1)) (Term (In ann2 f2)) = merge (ann1, ann2) <$> algorithmFor f1 f2
|
||||
|
||||
-- | An O(1) relation on terms indicating their non-recursive comparability (i.e. are they of the same “kind” in a way that warrants comparison), defined in terms of the comparability of their respective syntax.
|
||||
@ -246,7 +246,7 @@ instance GDiffable Par1 where
|
||||
-- | Diff two constant parameters (K1 is the Generic1 newtype representing type parameter constants).
|
||||
-- i.e. data Foo = Foo Int (the 'Int' is a constant parameter).
|
||||
instance Eq c => GDiffable (K1 i c) where
|
||||
galgorithmFor (K1 a1) (K1 a2) = guard (a1 == a2) *> pure (K1 a1)
|
||||
galgorithmFor (K1 a1) (K1 a2) = guard (a1 == a2) $> K1 a1
|
||||
|
||||
-- | Diff two terms whose constructors contain 0 type parameters.
|
||||
-- i.e. data Foo = Foo.
|
||||
@ -256,3 +256,5 @@ instance GDiffable U1 where
|
||||
-- | Diff two 'Diffable' containers of parameters.
|
||||
instance Diffable f => GDiffable (Rec1 f) where
|
||||
galgorithmFor a1 a2 = Rec1 <$> algorithmFor (unRec1 a1) (unRec1 a2)
|
||||
|
||||
{-# ANN module ("HLint: ignore Avoid return" :: String) #-}
|
||||
|
@ -18,7 +18,7 @@ data FeatureVector = FV !Double# !Double# !Double# !Double# !Double#
|
||||
!Double# !Double# !Double# !Double# !Double#
|
||||
|
||||
unFV :: FeatureVector -> [Double]
|
||||
unFV !(FV d00 d01 d02 d03 d04 d05 d06 d07 d08 d09 d10 d11 d12 d13 d14)
|
||||
unFV (FV d00 d01 d02 d03 d04 d05 d06 d07 d08 d09 d10 d11 d12 d13 d14)
|
||||
= [ D# d00, D# d01, D# d02, D# d03, D# d04
|
||||
, D# d05, D# d06, D# d07, D# d08, D# d09
|
||||
, D# d10, D# d11, D# d12, D# d13, D# d14 ]
|
||||
@ -48,8 +48,8 @@ unitVector !hash =
|
||||
(invMagnitude *## d10) (invMagnitude *## d11) (invMagnitude *## d12) (invMagnitude *## d13) (invMagnitude *## d14)
|
||||
|
||||
addVectors :: FeatureVector -> FeatureVector -> FeatureVector
|
||||
addVectors !(FV a00 a01 a02 a03 a04 a05 a06 a07 a08 a09 a10 a11 a12 a13 a14)
|
||||
!(FV b00 b01 b02 b03 b04 b05 b06 b07 b08 b09 b10 b11 b12 b13 b14)
|
||||
addVectors (FV a00 a01 a02 a03 a04 a05 a06 a07 a08 a09 a10 a11 a12 a13 a14)
|
||||
(FV b00 b01 b02 b03 b04 b05 b06 b07 b08 b09 b10 b11 b12 b13 b14)
|
||||
= FV (a00 +## b00) (a01 +## b01) (a02 +## b02) (a03 +## b03) (a04 +## b04)
|
||||
(a05 +## b05) (a06 +## b06) (a07 +## b07) (a08 +## b08) (a09 +## b09)
|
||||
(a10 +## b10) (a11 +## b11) (a12 +## b12) (a13 +## b13) (a14 +## b14)
|
||||
|
@ -1,4 +1,4 @@
|
||||
{-# LANGUAGE BangPatterns, GADTs, ImplicitParams, MultiParamTypeClasses, ScopedTypeVariables #-}
|
||||
{-# LANGUAGE BangPatterns, GADTs, MultiParamTypeClasses, ScopedTypeVariables #-}
|
||||
module Diffing.Algorithm.SES
|
||||
( EditScript
|
||||
, ses
|
||||
|
@ -1,4 +1,4 @@
|
||||
{-# LANGUAGE DataKinds, DeriveAnyClass, RankNTypes, TupleSections, TypeOperators #-}
|
||||
{-# LANGUAGE DataKinds, RankNTypes, TypeOperators #-}
|
||||
module Language.Go.Assignment
|
||||
( assignment
|
||||
, Syntax
|
||||
@ -275,7 +275,7 @@ channelType = makeTerm' <$> symbol ChannelType <*> children (mkChannelType <$>
|
||||
| otherwise = inj . Go.Type.BidirectionalChannel
|
||||
|
||||
fieldDeclaration :: Assignment
|
||||
fieldDeclaration = mkFieldDeclarationWithTag <$> symbol FieldDeclaration <*> children ((,,) <$> (manyTermsTill expression (void (symbol TypeIdentifier)) <|> (manyTerm expression)) <*> optional expression <*> optional expression)
|
||||
fieldDeclaration = mkFieldDeclarationWithTag <$> symbol FieldDeclaration <*> children ((,,) <$> (manyTermsTill expression (void (symbol TypeIdentifier)) <|> manyTerm expression) <*> optional expression <*> optional expression)
|
||||
where
|
||||
mkFieldDeclarationWithTag loc (fields, type', tag) | Just ty <- type', Just tag' <- tag = makeTerm loc (Go.Syntax.Field [ty, tag'] (makeTerm loc fields))
|
||||
| Just ty <- type' = makeTerm loc (Go.Syntax.Field [ty] (makeTerm loc fields))
|
||||
@ -409,7 +409,7 @@ indexExpression :: Assignment
|
||||
indexExpression = makeTerm <$> symbol IndexExpression <*> children (Expression.Subscript <$> expression <*> manyTerm expression)
|
||||
|
||||
methodDeclaration :: Assignment
|
||||
methodDeclaration = makeTerm <$> symbol MethodDeclaration <*> children (mkTypedMethodDeclaration <$> receiver <*> term fieldIdentifier <*> manyTerm parameters <*> ((makeTerm <$> location <*> (manyTermsTill expression (void (symbol Block)))) <|> emptyTerm) <*> (term block <|> emptyTerm))
|
||||
methodDeclaration = makeTerm <$> symbol MethodDeclaration <*> children (mkTypedMethodDeclaration <$> receiver <*> term fieldIdentifier <*> manyTerm parameters <*> ((makeTerm <$> location <*> manyTermsTill expression (void (symbol Block))) <|> emptyTerm) <*> (term block <|> emptyTerm))
|
||||
where
|
||||
receiver = symbol ParameterList *> children ((symbol ParameterDeclaration *> children expressions) <|> expressions)
|
||||
mkTypedMethodDeclaration receiver' name' parameters' type'' body' = Declaration.Method [type''] receiver' name' parameters' body'
|
||||
@ -469,13 +469,13 @@ unaryExpression = makeTerm' <$> symbol UnaryExpression <*> ( notExpression
|
||||
<|> unaryComplement
|
||||
<|> unaryPlus )
|
||||
where
|
||||
notExpression = inj <$> (children (Expression.Not <$ symbol AnonBang <*> expression))
|
||||
unaryAmpersand = inj <$> (children (Literal.Reference <$ symbol AnonAmpersand <*> expression))
|
||||
unaryComplement = inj <$> (children (Expression.Complement <$ symbol AnonCaret <*> expression))
|
||||
unaryMinus = inj <$> (children (Expression.Negate <$ symbol AnonMinus <*> expression))
|
||||
unaryPlus = children (symbol AnonPlus *> (Term.termOut <$> expression))
|
||||
unaryPointer = inj <$> (children (Literal.Pointer <$ symbol AnonStar <*> expression))
|
||||
unaryReceive = inj <$> (children (Go.Syntax.ReceiveOperator <$ symbol AnonLAngleMinus <*> expression))
|
||||
notExpression = inj <$> children (Expression.Not <$ symbol AnonBang <*> expression)
|
||||
unaryAmpersand = inj <$> children (Literal.Reference <$ symbol AnonAmpersand <*> expression)
|
||||
unaryComplement = inj <$> children (Expression.Complement <$ symbol AnonCaret <*> expression)
|
||||
unaryMinus = inj <$> children (Expression.Negate <$ symbol AnonMinus <*> expression)
|
||||
unaryPlus = children (symbol AnonPlus *> (Term.termOut <$> expression))
|
||||
unaryPointer = inj <$> children (Literal.Pointer <$ symbol AnonStar <*> expression)
|
||||
unaryReceive = inj <$> children (Go.Syntax.ReceiveOperator <$ symbol AnonLAngleMinus <*> expression)
|
||||
|
||||
varDeclaration :: Assignment
|
||||
varDeclaration = (symbol ConstDeclaration <|> symbol VarDeclaration) *> children expressions
|
||||
@ -489,7 +489,7 @@ variadicParameterDeclaration = makeTerm <$> symbol VariadicParameterDeclaration
|
||||
varSpecification :: Assignment
|
||||
varSpecification = makeTerm <$> (symbol ConstSpec <|> symbol VarSpec) <*> children (Statement.Assignment <$> pure [] <*> (annotatedLHS <|> identifiers) <*> expressions)
|
||||
where
|
||||
annotatedLHS = makeTerm <$> location <*> (Type.Annotation <$> (makeTerm <$> location <*> (manyTermsTill identifier (void (symbol TypeIdentifier)))) <*> expression)
|
||||
annotatedLHS = makeTerm <$> location <*> (Type.Annotation <$> (makeTerm <$> location <*> manyTermsTill identifier (void (symbol TypeIdentifier))) <*> expression)
|
||||
|
||||
|
||||
-- Statements
|
||||
@ -513,7 +513,7 @@ assignment' = makeTerm' <$> symbol AssignmentStatement <*> children (infixTerm
|
||||
assign :: Term -> Term -> Union Syntax Term
|
||||
assign l r = inj (Statement.Assignment [] l r)
|
||||
|
||||
augmentedAssign :: f :< Syntax => (Term -> Term -> f Term) -> Term -> Term -> Union Syntax Term
|
||||
augmentedAssign :: (f :< Syntax) => (Term -> Term -> f Term) -> Term -> Term -> Union Syntax Term
|
||||
augmentedAssign c l r = assign l (makeTerm1 (c l r))
|
||||
|
||||
invert cons a b = Expression.Not (makeTerm1 (cons a b))
|
||||
@ -610,3 +610,5 @@ manyTerm = many . term
|
||||
-- | Match a term and contextualize any comments preceeding or proceeding the term.
|
||||
term :: Assignment -> Assignment
|
||||
term term' = contextualize comment term' <|> makeTerm1 <$> (Syntax.Context <$> some1 comment <*> emptyTerm)
|
||||
|
||||
{-# ANN module ("HLint: ignore Eta reduce" :: String) #-}
|
||||
|
@ -72,7 +72,7 @@ instance Ord1 Rune where liftCompare = genericLiftCompare
|
||||
instance Show1 Rune where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
-- | A select statement in Go (e.g. `select { case x := <-c: x() }` where each case is a send or receive operation on channels).
|
||||
data Select a = Select { selectCases :: !a }
|
||||
newtype Select a = Select { selectCases :: a }
|
||||
deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
-- TODO: Implement Eval instance for Select
|
||||
@ -138,7 +138,7 @@ instance Show1 Receive where liftShowsPrec = genericLiftShowsPrec
|
||||
instance Evaluatable Receive
|
||||
|
||||
-- | A receive operator unary expression in Go (e.g. `<-channel` )
|
||||
data ReceiveOperator a = ReceiveOperator a
|
||||
newtype ReceiveOperator a = ReceiveOperator a
|
||||
deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
instance Eq1 ReceiveOperator where liftEq = genericLiftEq
|
||||
|
@ -56,7 +56,7 @@ instance Eq1 ThematicBreak where liftEq = genericLiftEq
|
||||
instance Ord1 ThematicBreak where liftCompare = genericLiftCompare
|
||||
instance Show1 ThematicBreak where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
data HTMLBlock a = HTMLBlock ByteString
|
||||
newtype HTMLBlock a = HTMLBlock ByteString
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
instance Eq1 HTMLBlock where liftEq = genericLiftEq
|
||||
|
@ -300,7 +300,7 @@ scopedCallExpression = makeTerm <$> symbol ScopedCallExpression <*> children (Ex
|
||||
where makeMemberAccess loc expr memberName = makeTerm loc (Expression.MemberAccess expr memberName)
|
||||
|
||||
functionCallExpression :: Assignment
|
||||
functionCallExpression = makeTerm <$> symbol FunctionCallExpression <*> children (Expression.Call [] <$> (term (qualifiedName <|> callableExpression)) <*> arguments <*> emptyTerm)
|
||||
functionCallExpression = makeTerm <$> symbol FunctionCallExpression <*> children (Expression.Call [] <$> term (qualifiedName <|> callableExpression) <*> arguments <*> emptyTerm)
|
||||
|
||||
callableExpression :: Assignment
|
||||
callableExpression = choice [
|
||||
@ -376,7 +376,7 @@ defaultArgumentSpecifier = symbol DefaultArgumentSpecifier *> children (term exp
|
||||
|
||||
variadicParameter :: Assignment
|
||||
variadicParameter = makeTerm <$> symbol VariadicParameter <*> children (makeTypeAnnotation <$> (term typeDeclaration <|> emptyTerm) <*> term variableName)
|
||||
where makeTypeAnnotation ty variableName = (Type.Annotation variableName ty)
|
||||
where makeTypeAnnotation ty variableName = Type.Annotation variableName ty
|
||||
|
||||
functionUseClause :: Assignment
|
||||
functionUseClause = makeTerm <$> symbol AnonymousFunctionUseClause <*> children (Syntax.UseClause <$> someTerm variableName)
|
||||
@ -397,10 +397,10 @@ compoundStatement :: Assignment
|
||||
compoundStatement = makeTerm <$> symbol CompoundStatement <*> children (manyTerm statement)
|
||||
|
||||
objectCreationExpression :: Assignment
|
||||
objectCreationExpression = (makeTerm <$> symbol ObjectCreationExpression <*> children (fmap Expression.New $ ((:) <$> term classTypeDesignator <*> (arguments <|> pure []))))
|
||||
objectCreationExpression = (makeTerm <$> symbol ObjectCreationExpression <*> children (Expression.New <$> ((:) <$> term classTypeDesignator <*> (arguments <|> pure []))))
|
||||
|
||||
<|> (makeTerm <$> symbol ObjectCreationExpression <*> children (makeAnonClass <$ token AnonNew <* token AnonClass <*> emptyTerm <*> (arguments <|> pure []) <*> (term classBaseClause <|> emptyTerm) <*> (term classInterfaceClause <|> emptyTerm) <*> (makeTerm <$> location <*> manyTerm classMemberDeclaration)))
|
||||
where makeAnonClass identifier args baseClause interfaceClause declarations = (Declaration.Class [] identifier (args ++ [baseClause, interfaceClause]) declarations)
|
||||
where makeAnonClass identifier args baseClause interfaceClause declarations = Declaration.Class [] identifier (args <> [baseClause, interfaceClause]) declarations
|
||||
|
||||
classMemberDeclaration :: Assignment
|
||||
classMemberDeclaration = choice [
|
||||
@ -680,7 +680,7 @@ namespaceDefinition = makeTerm <$> symbol NamespaceDefinition <*> children (Synt
|
||||
|
||||
namespaceUseDeclaration :: Assignment
|
||||
namespaceUseDeclaration = makeTerm <$> symbol NamespaceUseDeclaration <*> children (Syntax.NamespaceUseDeclaration <$>
|
||||
(((++) <$> (pure <$> (term namespaceFunctionOrConst <|> emptyTerm)) <*> someTerm namespaceUseClause) <|> ((\a b cs -> a : b : cs) <$> term namespaceFunctionOrConst <*> term namespaceName <*> someTerm namespaceUseGroupClause1) <|> ((:) <$> term namespaceName <*> someTerm namespaceUseGroupClause2)))
|
||||
((mappend <$> (pure <$> (term namespaceFunctionOrConst <|> emptyTerm)) <*> someTerm namespaceUseClause) <|> ((\a b cs -> a : b : cs) <$> term namespaceFunctionOrConst <*> term namespaceName <*> someTerm namespaceUseGroupClause1) <|> ((:) <$> term namespaceName <*> someTerm namespaceUseGroupClause2)))
|
||||
|
||||
namespaceUseClause :: Assignment
|
||||
namespaceUseClause = makeTerm <$> symbol NamespaceUseClause <*> children (fmap Syntax.NamespaceUseClause $ (\a b -> [a, b]) <$> term qualifiedName <*> (term namespaceAliasingClause <|> emptyTerm))
|
||||
@ -752,3 +752,5 @@ infixTerm :: Assignment
|
||||
-> [Assignment.Assignment [] Grammar (Term -> Term -> Union Syntax Term)]
|
||||
-> Assignment.Assignment [] Grammar (Union Syntax Term)
|
||||
infixTerm = infixContext (comment <|> textInterpolation)
|
||||
|
||||
{-# ANN module ("HLint: ignore Eta reduce" :: String) #-}
|
||||
|
@ -126,14 +126,14 @@ instance Eq1 QualifiedName where liftEq = genericLiftEq
|
||||
instance Ord1 QualifiedName where liftCompare = genericLiftCompare
|
||||
instance Show1 QualifiedName where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
data NamespaceName a = NamespaceName [a]
|
||||
newtype NamespaceName a = NamespaceName [a]
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
instance Eq1 NamespaceName where liftEq = genericLiftEq
|
||||
instance Ord1 NamespaceName where liftCompare = genericLiftCompare
|
||||
instance Show1 NamespaceName where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
data ConstDeclaration a = ConstDeclaration [a]
|
||||
newtype ConstDeclaration a = ConstDeclaration [a]
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
instance Eq1 ConstDeclaration where liftEq = genericLiftEq
|
||||
@ -147,92 +147,91 @@ instance Eq1 ClassConstDeclaration where liftEq = genericLiftEq
|
||||
instance Ord1 ClassConstDeclaration where liftCompare = genericLiftCompare
|
||||
instance Show1 ClassConstDeclaration where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
data ClassInterfaceClause a = ClassInterfaceClause [a]
|
||||
newtype ClassInterfaceClause a = ClassInterfaceClause [a]
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
instance Eq1 ClassInterfaceClause where liftEq = genericLiftEq
|
||||
instance Ord1 ClassInterfaceClause where liftCompare = genericLiftCompare
|
||||
instance Show1 ClassInterfaceClause where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
data ClassBaseClause a = ClassBaseClause a
|
||||
newtype ClassBaseClause a = ClassBaseClause a
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
instance Eq1 ClassBaseClause where liftEq = genericLiftEq
|
||||
instance Ord1 ClassBaseClause where liftCompare = genericLiftCompare
|
||||
instance Show1 ClassBaseClause where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
|
||||
data UseClause a = UseClause [a]
|
||||
newtype UseClause a = UseClause [a]
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
instance Eq1 UseClause where liftEq = genericLiftEq
|
||||
instance Ord1 UseClause where liftCompare = genericLiftCompare
|
||||
instance Show1 UseClause where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
data ReturnType a = ReturnType a
|
||||
newtype ReturnType a = ReturnType a
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
instance Eq1 ReturnType where liftEq = genericLiftEq
|
||||
instance Ord1 ReturnType where liftCompare = genericLiftCompare
|
||||
instance Show1 ReturnType where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
data TypeDeclaration a = TypeDeclaration a
|
||||
newtype TypeDeclaration a = TypeDeclaration a
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
instance Eq1 TypeDeclaration where liftEq = genericLiftEq
|
||||
instance Ord1 TypeDeclaration where liftCompare = genericLiftCompare
|
||||
instance Show1 TypeDeclaration where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
data BaseTypeDeclaration a = BaseTypeDeclaration a
|
||||
newtype BaseTypeDeclaration a = BaseTypeDeclaration a
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
instance Eq1 BaseTypeDeclaration where liftEq = genericLiftEq
|
||||
instance Ord1 BaseTypeDeclaration where liftCompare = genericLiftCompare
|
||||
instance Show1 BaseTypeDeclaration where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
data ScalarType a = ScalarType ByteString
|
||||
newtype ScalarType a = ScalarType ByteString
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
instance Eq1 ScalarType where liftEq = genericLiftEq
|
||||
instance Ord1 ScalarType where liftCompare = genericLiftCompare
|
||||
instance Show1 ScalarType where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
data EmptyIntrinsic a = EmptyIntrinsic a
|
||||
newtype EmptyIntrinsic a = EmptyIntrinsic a
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
instance Eq1 EmptyIntrinsic where liftEq = genericLiftEq
|
||||
instance Ord1 EmptyIntrinsic where liftCompare = genericLiftCompare
|
||||
instance Show1 EmptyIntrinsic where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
data ExitIntrinsic a = ExitIntrinsic a
|
||||
newtype ExitIntrinsic a = ExitIntrinsic a
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
instance Eq1 ExitIntrinsic where liftEq = genericLiftEq
|
||||
instance Ord1 ExitIntrinsic where liftCompare = genericLiftCompare
|
||||
instance Show1 ExitIntrinsic where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
data IssetIntrinsic a = IssetIntrinsic a
|
||||
newtype IssetIntrinsic a = IssetIntrinsic a
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
instance Eq1 IssetIntrinsic where liftEq = genericLiftEq
|
||||
instance Ord1 IssetIntrinsic where liftCompare = genericLiftCompare
|
||||
instance Show1 IssetIntrinsic where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
data EvalIntrinsic a = EvalIntrinsic a
|
||||
newtype EvalIntrinsic a = EvalIntrinsic a
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
instance Eq1 EvalIntrinsic where liftEq = genericLiftEq
|
||||
instance Ord1 EvalIntrinsic where liftCompare = genericLiftCompare
|
||||
instance Show1 EvalIntrinsic where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
data PrintIntrinsic a = PrintIntrinsic a
|
||||
newtype PrintIntrinsic a = PrintIntrinsic a
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
instance Eq1 PrintIntrinsic where liftEq = genericLiftEq
|
||||
instance Ord1 PrintIntrinsic where liftCompare = genericLiftCompare
|
||||
instance Show1 PrintIntrinsic where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
data NamespaceAliasingClause a = NamespaceAliasingClause a
|
||||
newtype NamespaceAliasingClause a = NamespaceAliasingClause a
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
instance Eq1 NamespaceAliasingClause where liftEq = genericLiftEq
|
||||
@ -379,14 +378,14 @@ instance Eq1 Declare where liftEq = genericLiftEq
|
||||
instance Ord1 Declare where liftCompare = genericLiftCompare
|
||||
instance Show1 Declare where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
data DeclareDirective a = DeclareDirective a
|
||||
newtype DeclareDirective a = DeclareDirective a
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
instance Eq1 DeclareDirective where liftEq = genericLiftEq
|
||||
instance Ord1 DeclareDirective where liftCompare = genericLiftCompare
|
||||
instance Show1 DeclareDirective where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
data LabeledStatement a = LabeledStatement { _labeledStatementIdentifier :: a }
|
||||
newtype LabeledStatement a = LabeledStatement { _labeledStatementIdentifier :: a }
|
||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
instance Eq1 LabeledStatement where liftEq = genericLiftEq
|
||||
|
@ -9,13 +9,8 @@ module Language.Python.Assignment
|
||||
|
||||
import Assigning.Assignment hiding (Assignment, Error)
|
||||
import Data.Abstract.FreeVariables
|
||||
import Data.Functor (void)
|
||||
import Data.List.NonEmpty (some1)
|
||||
import Data.Maybe (fromMaybe)
|
||||
import Data.Record
|
||||
import Data.Semigroup
|
||||
import Data.Syntax (contextualize, emptyTerm, handleError, infixContext, makeTerm, makeTerm', makeTerm'', makeTerm1, parseError, postContextualize)
|
||||
import Data.Union
|
||||
import GHC.Stack
|
||||
import Language.Python.Grammar as Grammar
|
||||
import Language.Python.Syntax as Python.Syntax
|
||||
@ -28,6 +23,7 @@ import qualified Data.Syntax.Literal as Literal
|
||||
import qualified Data.Syntax.Statement as Statement
|
||||
import qualified Data.Syntax.Type as Type
|
||||
import qualified Data.Term as Term
|
||||
import Prologue
|
||||
|
||||
|
||||
-- | The type of Python syntax.
|
||||
@ -250,7 +246,7 @@ functionDefinition
|
||||
<|> makeFunctionDeclaration <$> (symbol Lambda' <|> symbol Lambda) <*> children ((,,,) <$ token AnonLambda <*> emptyTerm <*> (symbol LambdaParameters *> children (manyTerm expression) <|> pure []) <*> optional (symbol Type *> children (term expression)) <*> expressions)
|
||||
where
|
||||
makeFunctionDeclaration loc (functionName', functionParameters, ty, functionBody) = makeTerm loc $ Type.Annotation (makeTerm loc $ Declaration.Function [] functionName' functionParameters functionBody) (fromMaybe (makeTerm loc Syntax.Empty) ty)
|
||||
makeAsyncFunctionDeclaration loc (async', functionName', functionParameters, ty, functionBody) = makeTerm loc $ Type.Annotation (makeTerm loc $ Type.Annotation (makeTerm loc $ Declaration.Function [] functionName' functionParameters functionBody) (maybe (makeTerm loc Syntax.Empty) id ty)) async'
|
||||
makeAsyncFunctionDeclaration loc (async', functionName', functionParameters, ty, functionBody) = makeTerm loc $ Type.Annotation (makeTerm loc $ Type.Annotation (makeTerm loc $ Declaration.Function [] functionName' functionParameters functionBody) (fromMaybe (makeTerm loc Syntax.Empty) ty)) async'
|
||||
|
||||
async' :: Assignment
|
||||
async' = makeTerm <$> symbol AnonAsync <*> (Syntax.Identifier <$> (name <$> source))
|
||||
@ -335,7 +331,7 @@ assignment' = makeTerm <$> symbol Assignment <*> children (Statement.Assignmen
|
||||
, assign Expression.BXOr <$ symbol AnonCaretEqual
|
||||
])
|
||||
where rvalue = expressionList <|> assignment' <|> yield
|
||||
assign :: f :< Syntax => (Term -> Term -> f Term) -> Term -> Term -> Union Syntax Term
|
||||
assign :: (f :< Syntax) => (Term -> Term -> f Term) -> Term -> Term -> Union Syntax Term
|
||||
assign c l r = inj (Statement.Assignment [] l (makeTerm1 (c l r)))
|
||||
|
||||
yield :: Assignment
|
||||
@ -386,7 +382,7 @@ comment = makeTerm <$> symbol Comment <*> (Comment.Comment <$> source)
|
||||
|
||||
import' :: Assignment
|
||||
import' = makeTerm'' <$> symbol ImportStatement <*> children (manyTerm (aliasedImport <|> plainImport))
|
||||
<|> makeTerm <$> symbol ImportFromStatement <*> children (Declaration.Import <$> (identifier <|> emptyTerm) <*> (wildcard <|> (some (aliasImportSymbol <|> importSymbol))) <*> emptyTerm)
|
||||
<|> makeTerm <$> symbol ImportFromStatement <*> children (Declaration.Import <$> (identifier <|> emptyTerm) <*> (wildcard <|> some (aliasImportSymbol <|> importSymbol)) <*> emptyTerm)
|
||||
where
|
||||
-- `import a as b`
|
||||
aliasedImport = makeImport <$> symbol AliasedImport <*> children ((,) <$> expression <*> (Just <$> expression))
|
||||
@ -397,7 +393,7 @@ import' = makeTerm'' <$> symbol ImportStatement <*> children (manyTerm (aliase
|
||||
-- `from a import foo as bar`
|
||||
aliasImportSymbol = symbol AliasedImport *> children (makeNameAliasPair <$> rawIdentifier <*> (Just <$> rawIdentifier))
|
||||
-- `from a import *`
|
||||
wildcard = symbol WildcardImport *> source *> pure []
|
||||
wildcard = symbol WildcardImport *> source $> []
|
||||
|
||||
rawIdentifier = (name <$> identifier') <|> (qualifiedName <$> dottedName')
|
||||
dottedName' = symbol DottedName *> children (some identifier')
|
||||
@ -512,3 +508,5 @@ infixTerm :: HasCallStack
|
||||
-> [Assignment.Assignment [] Grammar (Term -> Term -> Union Syntax Term)]
|
||||
-> Assignment.Assignment [] Grammar (Union Syntax Term)
|
||||
infixTerm = infixContext comment
|
||||
|
||||
{-# ANN module ("HLint: ignore Eta reduce" :: String) #-}
|
||||
|
@ -121,7 +121,7 @@ expressionChoices =
|
||||
, mk Yield Statement.Yield
|
||||
, module'
|
||||
, pair
|
||||
, parenthesized_expressions
|
||||
, parenthesizedExpressions
|
||||
, parseError
|
||||
, rescue
|
||||
, scopeResolution
|
||||
@ -140,8 +140,8 @@ expressionChoices =
|
||||
expressions :: Assignment
|
||||
expressions = makeTerm'' <$> location <*> many expression
|
||||
|
||||
parenthesized_expressions :: Assignment
|
||||
parenthesized_expressions = makeTerm'' <$> symbol ParenthesizedStatements <*> children (many expression)
|
||||
parenthesizedExpressions :: Assignment
|
||||
parenthesizedExpressions = makeTerm'' <$> symbol ParenthesizedStatements <*> children (many expression)
|
||||
|
||||
identifier :: Assignment
|
||||
identifier =
|
||||
@ -241,7 +241,7 @@ lambda = makeTerm <$> symbol Lambda <*> children (
|
||||
block :: Assignment
|
||||
block = makeTerm <$> symbol DoBlock <*> children (Declaration.Function <$> pure [] <*> emptyTerm <*> params <*> expressions)
|
||||
<|> makeTerm <$> symbol Block <*> children (Declaration.Function <$> pure [] <*> emptyTerm <*> params <*> expressions)
|
||||
where params = (symbol BlockParameters) *> children (many parameter) <|> pure []
|
||||
where params = symbol BlockParameters *> children (many parameter) <|> pure []
|
||||
|
||||
comment :: Assignment
|
||||
comment = makeTerm <$> symbol Comment <*> (Comment.Comment <$> source)
|
||||
@ -281,14 +281,14 @@ until' =
|
||||
|
||||
for :: Assignment
|
||||
for = makeTerm <$> symbol For <*> children (Statement.ForEach <$> (makeTerm <$> location <*> manyTermsTill expression (symbol In)) <*> inClause <*> expressions)
|
||||
where inClause = symbol In *> children (expression)
|
||||
where inClause = symbol In *> children expression
|
||||
|
||||
case' :: Assignment
|
||||
case' = makeTerm <$> symbol Case <*> children (Statement.Match <$> (symbol When *> emptyTerm <|> expression) <*> whens)
|
||||
where
|
||||
whens = makeTerm <$> location <*> many (when' <|> else' <|> expression)
|
||||
when' = makeTerm <$> symbol When <*> children (Statement.Pattern <$> (makeTerm <$> location <*> some pattern) <*> whens)
|
||||
pattern = postContextualize comment (symbol Pattern *> children ((symbol SplatArgument *> children expression) <|> expression))
|
||||
when' = makeTerm <$> symbol When <*> children (Statement.Pattern <$> (makeTerm <$> location <*> some pattern') <*> whens)
|
||||
pattern' = postContextualize comment (symbol Pattern *> children ((symbol SplatArgument *> children expression) <|> expression))
|
||||
else' = postContextualize comment (symbol Else *> children expressions)
|
||||
|
||||
subscript :: Assignment
|
||||
@ -303,11 +303,11 @@ methodCall = makeTerm' <$> symbol MethodCall <*> children (require <|> load <|>
|
||||
regularCall = inj <$> (Expression.Call <$> pure [] <*> expression <*> args <*> (block <|> emptyTerm))
|
||||
require = inj <$> (symbol Identifier *> do
|
||||
s <- source
|
||||
guard (elem s ["require", "require_relative"])
|
||||
guard (s `elem` ["require", "require_relative"])
|
||||
Ruby.Syntax.Require (s == "require_relative") <$> nameExpression)
|
||||
load = inj <$> (symbol Identifier *> do
|
||||
s <- source
|
||||
guard (elem s ["load"])
|
||||
guard (s == "load")
|
||||
Ruby.Syntax.Load <$> loadArgs)
|
||||
args = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children (many expression) <|> pure []
|
||||
loadArgs = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children (some expression)
|
||||
@ -316,7 +316,7 @@ methodCall = makeTerm' <$> symbol MethodCall <*> children (require <|> load <|>
|
||||
call :: Assignment
|
||||
call = makeTerm <$> symbol Call <*> children (Expression.MemberAccess <$> expression <*> (expression <|> args))
|
||||
where
|
||||
args = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children (expressions)
|
||||
args = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children expressions
|
||||
|
||||
rescue :: Assignment
|
||||
rescue = rescue'
|
||||
@ -350,7 +350,7 @@ assignment' = makeTerm <$> symbol Assignment <*> children (Statement.As
|
||||
, assign Expression.BXOr <$ symbol AnonCaretEqual
|
||||
])
|
||||
where
|
||||
assign :: f :< Syntax => (Term -> Term -> f Term) -> Term -> Term -> Union Syntax Term
|
||||
assign :: (f :< Syntax) => (Term -> Term -> f Term) -> Term -> Term -> Union Syntax Term
|
||||
assign c l r = inj (Statement.Assignment [] l (makeTerm1 (c l r)))
|
||||
|
||||
lhs = makeTerm <$> symbol LeftAssignmentList <*> children (many expr) <|> expr
|
||||
@ -423,3 +423,5 @@ infixTerm :: HasCallStack
|
||||
-> [Assignment.Assignment [] Grammar (Term -> Term -> Union Syntax Term)]
|
||||
-> Assignment.Assignment [] Grammar (Union Syntax Term)
|
||||
infixTerm = infixContext comment
|
||||
|
||||
{-# ANN module ("HLint: ignore Eta reduce" :: String) #-}
|
||||
|
@ -245,7 +245,7 @@ augmentedAssignmentExpression = makeTerm' <$> symbol AugmentedAssignmentExpressi
|
||||
, assign Expression.RShift <$ symbol AnonRAngleRAngleEqual
|
||||
, assign Expression.UnsignedRShift <$ symbol AnonRAngleRAngleRAngleEqual
|
||||
, assign Expression.BOr <$ symbol AnonPipeEqual ])
|
||||
where assign :: f :< Syntax => (Term -> Term -> f Term) -> Term -> Term -> Union Syntax Term
|
||||
where assign :: (f :< Syntax) => (Term -> Term -> f Term) -> Term -> Term -> Union Syntax Term
|
||||
assign c l r = inj (Statement.Assignment [] l (makeTerm1 (c l r)))
|
||||
|
||||
|
||||
@ -300,7 +300,7 @@ abstractMethodSignature = makeSignature <$> symbol Grammar.AbstractMethodSignatu
|
||||
where makeSignature loc (modifier, propertyName, (typeParams, params, annotation)) = makeTerm loc (TypeScript.Syntax.AbstractMethodSignature [modifier, typeParams, annotation] propertyName params)
|
||||
|
||||
classHeritage' :: Assignment.Assignment [] Grammar [Term]
|
||||
classHeritage' = symbol Grammar.ClassHeritage *> children (((++) `on` toList) <$> optional (term extendsClause) <*> optional (term implementsClause'))
|
||||
classHeritage' = symbol Grammar.ClassHeritage *> children ((mappend `on` toList) <$> optional (term extendsClause) <*> optional (term implementsClause'))
|
||||
|
||||
extendsClause :: Assignment
|
||||
extendsClause = makeTerm <$> symbol Grammar.ExtendsClause <*> children (TypeScript.Syntax.ExtendsClause <$> manyTerm (typeReference <|> expression))
|
||||
@ -643,7 +643,7 @@ importStatement = makeImportTerm <$> symbol Grammar.ImportStatement <*> childr
|
||||
<|> makeTerm' <$> symbol Grammar.ImportStatement <*> children (requireImport <|> sideEffectImport)
|
||||
where
|
||||
-- `import foo = require "./foo"`
|
||||
requireImport = inj <$> (symbol Grammar.ImportRequireClause *> children (flip Declaration.QualifiedImport <$> (term identifier) <*> term fromClause <*> pure []))
|
||||
requireImport = inj <$> (symbol Grammar.ImportRequireClause *> children (flip Declaration.QualifiedImport <$> term identifier <*> term fromClause <*> pure []))
|
||||
-- `import "./foo"`
|
||||
sideEffectImport = inj <$> (Declaration.SideEffectImport <$> term fromClause <*> emptyTerm)
|
||||
-- `import { bar } from "./foo"`
|
||||
@ -651,7 +651,7 @@ importStatement = makeImportTerm <$> symbol Grammar.ImportStatement <*> childr
|
||||
-- `import defaultMember from "./foo"`
|
||||
defaultImport = (,,,) <$> pure Prelude.False <*> pure Nothing <*> (pure <$> (makeNameAliasPair <$> rawIdentifier <*> pure Nothing)) <*> emptyTerm
|
||||
-- `import * as name from "./foo"`
|
||||
namespaceImport = symbol Grammar.NamespaceImport *> children ((,,,) <$> pure Prelude.True <*> (Just <$> (term identifier)) <*> pure [] <*> emptyTerm)
|
||||
namespaceImport = symbol Grammar.NamespaceImport *> children ((,,,) <$> pure Prelude.True <*> (Just <$> term identifier) <*> pure [] <*> emptyTerm)
|
||||
|
||||
-- Combinations of the above.
|
||||
importClause = symbol Grammar.ImportClause *>
|
||||
@ -666,7 +666,7 @@ importStatement = makeImportTerm <$> symbol Grammar.ImportStatement <*> childr
|
||||
makeImportTerm1 loc from (_, _, symbols, extra) = makeTerm loc (Declaration.Import from symbols extra)
|
||||
makeImportTerm loc ([x], from) = makeImportTerm1 loc from x
|
||||
makeImportTerm loc (xs, from) = makeTerm loc $ fmap (makeImportTerm1 loc from) xs
|
||||
importSymbol = symbol Grammar.ImportSpecifier *> children (makeNameAliasPair <$> rawIdentifier <*> ((Just <$> rawIdentifier) <|> (pure Nothing)))
|
||||
importSymbol = symbol Grammar.ImportSpecifier *> children (makeNameAliasPair <$> rawIdentifier <*> ((Just <$> rawIdentifier) <|> pure Nothing))
|
||||
rawIdentifier = (symbol Identifier <|> symbol Identifier') *> (name <$> source)
|
||||
makeNameAliasPair from (Just alias) = (from, alias)
|
||||
makeNameAliasPair from Nothing = (from, from)
|
||||
@ -717,13 +717,13 @@ ambientDeclaration :: Assignment
|
||||
ambientDeclaration = makeTerm <$> symbol Grammar.AmbientDeclaration <*> children (TypeScript.Syntax.AmbientDeclaration <$> term (choice [declaration, statementBlock]))
|
||||
|
||||
exportStatement :: Assignment
|
||||
exportStatement = makeTerm <$> symbol Grammar.ExportStatement <*> (children (flip Declaration.QualifiedExportFrom <$> exportClause <*> term fromClause))
|
||||
exportStatement = makeTerm <$> symbol Grammar.ExportStatement <*> children (flip Declaration.QualifiedExportFrom <$> exportClause <*> term fromClause)
|
||||
<|> makeTerm <$> symbol Grammar.ExportStatement <*> children (Declaration.QualifiedExport <$> exportClause)
|
||||
<|> makeTerm <$> symbol Grammar.ExportStatement <*> children (Declaration.DefaultExport <$> contextualize decorator (term (declaration <|> expression <|> identifier <|> importAlias')))
|
||||
where
|
||||
exportClause = symbol Grammar.ExportClause *> children (many exportSymbol)
|
||||
exportSymbol = symbol Grammar.ExportSpecifier *> children (makeNameAliasPair <$> rawIdentifier <*> (Just <$> rawIdentifier))
|
||||
<|> symbol Grammar.ExportSpecifier *> children (makeNameAliasPair <$> rawIdentifier <*> (pure Nothing))
|
||||
<|> symbol Grammar.ExportSpecifier *> children (makeNameAliasPair <$> rawIdentifier <*> pure Nothing)
|
||||
makeNameAliasPair from (Just alias) = (from, alias)
|
||||
makeNameAliasPair from Nothing = (from, from)
|
||||
rawIdentifier = (symbol Identifier <|> symbol Identifier') *> (name <$> source)
|
||||
|
@ -51,7 +51,7 @@ import Data.Bifoldable as X
|
||||
import Data.Bifunctor as X (Bifunctor(..))
|
||||
import Data.Bitraversable as X
|
||||
import Data.Foldable as X hiding (product , sum)
|
||||
import Data.Functor as X (void)
|
||||
import Data.Functor as X (($>), void)
|
||||
import Data.Function as X (fix, on, (&))
|
||||
import Data.Functor.Classes as X
|
||||
import Data.Functor.Classes.Generic as X
|
||||
|
@ -34,7 +34,7 @@ diffAlgebra d i as = case d of
|
||||
termAlgebra :: (ConstructorName syntax, Foldable syntax) => TermF syntax ann (Int -> [Attribute B.ByteString] -> State) -> Int -> [Attribute B.ByteString] -> State
|
||||
termAlgebra t i defaultAttrs = State
|
||||
root
|
||||
(root `connect` stateRoots combined `overlay` (stateGraph combined))
|
||||
(root `connect` stateRoots combined `overlay` stateGraph combined)
|
||||
(IntMap.insert (succ i) ("label" := unConstructorLabel (constructorLabel t) : defaultAttrs) (stateVertexAttributes combined))
|
||||
where root = vertex (succ i)
|
||||
combined = foldl' combine (State empty root mempty) t
|
||||
|
@ -5,7 +5,7 @@ module Rendering.SExpression
|
||||
) where
|
||||
|
||||
import Prologue
|
||||
import Data.ByteString.Char8 hiding (intersperse, foldr, spanEnd, length, null)
|
||||
import Data.ByteString.Char8
|
||||
import Data.Diff
|
||||
import Data.Patch
|
||||
import Data.Record
|
||||
|
@ -30,7 +30,7 @@ import Text.Read
|
||||
readFile :: forall m. MonadIO m => FilePath -> Maybe Language -> m (Maybe Blob.Blob)
|
||||
readFile "/dev/null" _ = pure Nothing
|
||||
readFile path language = do
|
||||
raw <- liftIO $ (Just <$> B.readFile path)
|
||||
raw <- liftIO (Just <$> B.readFile path)
|
||||
pure $ Blob.sourceBlob path language . fromBytes <$> raw
|
||||
|
||||
readFilePair :: forall m. MonadIO m => (FilePath, Maybe Language) -> (FilePath, Maybe Language) -> m Blob.BlobPair
|
||||
@ -64,7 +64,7 @@ readBlobsFromHandle = fmap toBlobs . readFromHandle
|
||||
where toBlobs BlobParse{..} = fmap toBlob blobs
|
||||
|
||||
readBlobsFromPaths :: MonadIO m => [(FilePath, Maybe Language)] -> m [Blob.Blob]
|
||||
readBlobsFromPaths files = traverse (uncurry Semantic.IO.readFile) files >>= pure . catMaybes
|
||||
readBlobsFromPaths files = catMaybes <$> traverse (uncurry Semantic.IO.readFile) files
|
||||
|
||||
readBlobsFromDir :: MonadIO m => FilePath -> m [Blob.Blob]
|
||||
readBlobsFromDir path = do
|
||||
|
@ -256,3 +256,5 @@ instance MonadIO Task where
|
||||
instance MonadError SomeException Task where
|
||||
throwError error = Throw error `Then` return
|
||||
catchError during handler = Catch during handler `Then` return
|
||||
|
||||
{-# ANN module ("HLint: ignore Avoid return" :: String) #-}
|
||||
|
Loading…
Reference in New Issue
Block a user