From 26723f9e1e9dff8d3abc605548b8227d9ed984e9 Mon Sep 17 00:00:00 2001 From: Patrick Thomson Date: Mon, 27 Jan 2020 13:10:00 -0500 Subject: [PATCH] De-Prologue various assignment and syntax modules. --- src/Analysis/Abstract/Graph.hs | 3 ++- src/Assigning/Assignment/Table.hs | 14 +++++++--- src/Diffing/Algorithm/RWS.hs | 39 +++++++++++++++++++-------- src/Language/Go/Assignment.hs | 17 +++++++----- src/Language/Go/Type.hs | 10 ++++--- src/Language/Markdown/Assignment.hs | 21 +++++++++------ src/Language/Markdown/Syntax.hs | 10 +++++-- src/Language/PHP/Assignment.hs | 13 ++++++--- src/Language/PHP/Syntax.hs | 14 +++++++--- src/Language/Python/Assignment.hs | 15 ++++++++--- src/Language/Python/Syntax.hs | 21 ++++++++++++--- src/Language/Ruby/Assignment.hs | 15 ++++++++--- src/Language/Ruby/Syntax.hs | 21 ++++++++++++--- src/Language/TSX/Assignment.hs | 33 ++++++++++++++--------- src/Language/TypeScript/Assignment.hs | 35 +++++++++++++++--------- 15 files changed, 200 insertions(+), 81 deletions(-) diff --git a/src/Analysis/Abstract/Graph.hs b/src/Analysis/Abstract/Graph.hs index 96a23bc0c..28137fad3 100644 --- a/src/Analysis/Abstract/Graph.hs +++ b/src/Analysis/Abstract/Graph.hs @@ -36,6 +36,7 @@ import Data.Abstract.Module (Module (moduleInfo), ModuleInfo (..)) import Data.ByteString.Builder import Data.Graph import Data.Graph.ControlFlowVertex +import Data.Map (Map) import qualified Data.Map as Map import qualified Data.Text.Encoding as T import Source.Loc @@ -131,7 +132,7 @@ graphingModules recur m = do where -- NB: path is null for Languages like Ruby that have module imports that require concrete value semantics. includeModule path - = let path' = if Prologue.null path then "unknown, concrete semantics required" else path + = let path' = if Prelude.null path then "unknown, concrete semantics required" else path info = moduleInfo m in moduleInclusion (moduleVertex (ModuleInfo path' (moduleLanguage info) (moduleOid info))) diff --git a/src/Assigning/Assignment/Table.hs b/src/Assigning/Assignment/Table.hs index 11719ee42..5a3f0d294 100644 --- a/src/Assigning/Assignment/Table.hs +++ b/src/Assigning/Assignment/Table.hs @@ -1,4 +1,7 @@ -{-# LANGUAGE DeriveGeneric, DeriveTraversable, DerivingVia, RecordWildCards #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DeriveTraversable #-} +{-# LANGUAGE DerivingVia #-} +{-# LANGUAGE RecordWildCards #-} module Assigning.Assignment.Table ( Table(tableAddresses) , singleton @@ -7,10 +10,15 @@ module Assigning.Assignment.Table , lookup ) where -import Prologue -import Prelude hiding (lookup) +import Data.Bifunctor +import Data.Functor.Classes +import Data.IntMap (IntMap) import qualified Data.IntMap as IntMap import qualified Data.IntSet as IntSet +import Data.Monoid.Generic +import Data.Traversable +import GHC.Generics (Generic) +import Prelude hiding (lookup) data Table i a = Table { tableAddresses :: [i], tableBranches :: IntMap a } deriving (Eq, Foldable, Functor, Show, Traversable, Generic) diff --git a/src/Diffing/Algorithm/RWS.hs b/src/Diffing/Algorithm/RWS.hs index b57aad0ba..99b8aaad8 100644 --- a/src/Diffing/Algorithm/RWS.hs +++ b/src/Diffing/Algorithm/RWS.hs @@ -1,4 +1,10 @@ -{-# LANGUAGE DataKinds, DeriveAnyClass, DeriveGeneric, GADTs, RankNTypes, RecordWildCards, TypeOperators #-} +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE TypeOperators #-} {-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-} -- FIXME module Diffing.Algorithm.RWS ( rws @@ -14,16 +20,27 @@ module Diffing.Algorithm.RWS , equalTerms ) where -import Control.Monad.State.Strict -import Data.Diff (DiffF(..), comparing, deleting, inserting, merge) -import Data.Edit +import Control.Applicative +import Control.Arrow ((&&&)) +import Control.Monad.State.Strict +import Data.Diff (DiffF (..), comparing, deleting, inserting, merge) +import Data.Edit +import Data.Foldable +import Data.Function +import Data.Functor.Classes +import Data.Functor.Foldable (cata) +import Data.Hashable +import Data.Hashable.Lifted +import Data.Ix (inRange) import qualified Data.KdMap.Static as KdMap -import Data.List (sortOn) -import Data.Term as Term -import Diffing.Algorithm (Diffable(..)) -import Diffing.Algorithm.RWS.FeatureVector -import Diffing.Algorithm.SES -import Prologue +import Data.List (sortOn) +import Data.Maybe +import Data.Term as Term +import Data.Traversable +import Diffing.Algorithm (Diffable (..)) +import Diffing.Algorithm.RWS.FeatureVector +import Diffing.Algorithm.SES +import GHC.Generics (Generic) -- | A relation on 'Term's, guaranteed constant-time in the size of the 'Term' by parametricity. -- @@ -158,7 +175,7 @@ editDistanceUpTo m a b = diffCost m (approximateDiff a b) where diffCost = flip . cata $ \ diff m -> case diff of _ | m <= 0 -> 0 Merge body -> sum (fmap ($ pred m) body) - body -> succ (sum (fmap ($ pred m) body)) + body -> succ (sum (fmap ($ pred m) body)) approximateDiff a b = maybe (comparing a b) (merge (termAnnotation a, termAnnotation b)) (tryAlignWith (Just . edit deleting inserting approximateDiff) (termOut a) (termOut b)) diff --git a/src/Language/Go/Assignment.hs b/src/Language/Go/Assignment.hs index 269bd20b4..c27cc9104 100644 --- a/src/Language/Go/Assignment.hs +++ b/src/Language/Go/Assignment.hs @@ -1,4 +1,8 @@ -{-# LANGUAGE DataKinds, FlexibleContexts, RankNTypes, TypeFamilies, TypeOperators #-} +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE TypeOperators #-} module Language.Go.Assignment ( assignment , Go.Syntax @@ -6,12 +10,14 @@ module Language.Go.Assignment , Go.Term(..) ) where -import Prologue - import Assigning.Assignment hiding (Assignment, Error) import qualified Assigning.Assignment as Assignment -import qualified Data.Abstract.ScopeGraph as ScopeGraph (AccessControl(..)) +import Control.Monad import Data.Abstract.Name (name) +import qualified Data.Abstract.ScopeGraph as ScopeGraph (AccessControl (..)) +import Data.ImportPath (defaultAlias, importPath) +import Data.List.NonEmpty (NonEmpty (..), some1) +import Data.Sum import Data.Syntax (contextualize, emptyTerm, handleError, infixContext, makeTerm, makeTerm', makeTerm'', makeTerm1, parseError) import qualified Data.Syntax as Syntax @@ -22,10 +28,9 @@ 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 Language.Go.Syntax as Go.Syntax hiding (runeLiteral, labelName) +import Language.Go.Syntax as Go.Syntax hiding (labelName, runeLiteral) import Language.Go.Term as Go import Language.Go.Type as Go.Type -import Data.ImportPath (importPath, defaultAlias) import TreeSitter.Go as Grammar type Assignment = Assignment.Assignment [] Grammar diff --git a/src/Language/Go/Type.hs b/src/Language/Go/Type.hs index 1548779e5..d24445146 100644 --- a/src/Language/Go/Type.hs +++ b/src/Language/Go/Type.hs @@ -1,11 +1,15 @@ -{-# LANGUAGE DeriveAnyClass, DeriveGeneric, DeriveTraversable, DuplicateRecordFields #-} +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DeriveTraversable #-} +{-# LANGUAGE DuplicateRecordFields #-} module Language.Go.Type (module Language.Go.Type) where -import Prologue - import Data.Abstract.Evaluatable +import Data.Functor.Classes.Generic +import Data.Hashable.Lifted import Data.JSON.Fields import Diffing.Algorithm +import GHC.Generics (Generic1) -- | A Bidirectional channel in Go (e.g. `chan`). newtype BidirectionalChannel a = BidirectionalChannel { value :: a } diff --git a/src/Language/Markdown/Assignment.hs b/src/Language/Markdown/Assignment.hs index d1124bc3b..37036d8e0 100644 --- a/src/Language/Markdown/Assignment.hs +++ b/src/Language/Markdown/Assignment.hs @@ -1,4 +1,9 @@ -{-# LANGUAGE DataKinds, FlexibleContexts, RankNTypes, RecordWildCards, TypeFamilies, TypeOperators #-} +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE TypeOperators #-} module Language.Markdown.Assignment ( assignment , Markdown.Syntax @@ -6,11 +11,11 @@ module Language.Markdown.Assignment , Markdown.Term(..) ) where -import Prologue - import Assigning.Assignment hiding (Assignment, Error) import qualified Assigning.Assignment as Assignment import qualified CMarkGFM +import Control.Monad +import Data.Sum import Data.Syntax (makeTerm) import qualified Data.Syntax as Syntax import qualified Data.Term as Term @@ -46,7 +51,7 @@ list :: Assignment (Term Loc) list = Term.termIn <$> symbol List <*> (makeList . Term.termFAnnotation . Term.termFOut <$> currentNode <*> children (many item)) where makeList (CMarkGFM.LIST CMarkGFM.ListAttributes{..}) = case listType of - CMarkGFM.BULLET_LIST -> inject . Markup.UnorderedList + CMarkGFM.BULLET_LIST -> inject . Markup.UnorderedList CMarkGFM.ORDERED_LIST -> inject . Markup.OrderedList makeList _ = inject . Markup.UnorderedList @@ -57,7 +62,7 @@ heading :: Assignment (Term Loc) heading = makeTerm <$> symbol Heading <*> (makeHeading . Term.termFAnnotation . Term.termFOut <$> currentNode <*> children (many inlineElement) <*> manyTill blockElement (void (symbol Heading) <|> eof)) where makeHeading (CMarkGFM.HEADING level) = Markup.Heading level - makeHeading _ = Markup.Heading 0 + makeHeading _ = Markup.Heading 0 blockQuote :: Assignment (Term Loc) blockQuote = makeTerm <$> symbol BlockQuote <*> children (Markup.BlockQuote <$> many blockElement) @@ -66,7 +71,7 @@ codeBlock :: Assignment (Term Loc) codeBlock = makeTerm <$> symbol CodeBlock <*> (makeCode . Term.termFAnnotation . Term.termFOut <$> currentNode <*> source) where makeCode (CMarkGFM.CODE_BLOCK language _) = Markup.Code (nullText language) - makeCode _ = Markup.Code Nothing + makeCode _ = Markup.Code Nothing thematicBreak :: Assignment (Term Loc) thematicBreak = makeTerm <$> token ThematicBreak <*> pure Markup.ThematicBreak @@ -118,13 +123,13 @@ link :: Assignment (Term Loc) link = makeTerm <$> symbol Link <*> (makeLink . Term.termFAnnotation . Term.termFOut <$> currentNode) <* advance where makeLink (CMarkGFM.LINK url title) = Markup.Link url (nullText title) - makeLink _ = Markup.Link mempty Nothing + makeLink _ = Markup.Link mempty Nothing image :: Assignment (Term Loc) image = makeTerm <$> symbol Image <*> (makeImage . Term.termFAnnotation . Term.termFOut <$> currentNode) <* advance where makeImage (CMarkGFM.IMAGE url title) = Markup.Image url (nullText title) - makeImage _ = Markup.Image mempty Nothing + makeImage _ = Markup.Image mempty Nothing code :: Assignment (Term Loc) code = makeTerm <$> symbol Code <*> (Markup.Code Nothing <$> source) diff --git a/src/Language/Markdown/Syntax.hs b/src/Language/Markdown/Syntax.hs index 188907426..fa9098d0d 100644 --- a/src/Language/Markdown/Syntax.hs +++ b/src/Language/Markdown/Syntax.hs @@ -1,11 +1,17 @@ -{-# LANGUAGE DeriveAnyClass, DeriveGeneric, DeriveTraversable, DuplicateRecordFields #-} +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DeriveTraversable #-} +{-# LANGUAGE DuplicateRecordFields #-} module Language.Markdown.Syntax (module Language.Markdown.Syntax) where import Data.Abstract.Declarations +import Data.Functor.Classes +import Data.Functor.Classes.Generic +import Data.Hashable.Lifted import Data.JSON.Fields import qualified Data.Text as T import Diffing.Algorithm -import Prologue hiding (Text) +import GHC.Generics (Generic1) newtype Document a = Document { values :: [a] } deriving (Declarations1, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1) diff --git a/src/Language/PHP/Assignment.hs b/src/Language/PHP/Assignment.hs index 54aab1283..816cf6af4 100644 --- a/src/Language/PHP/Assignment.hs +++ b/src/Language/PHP/Assignment.hs @@ -1,4 +1,8 @@ -{-# LANGUAGE DataKinds, FlexibleContexts, RankNTypes, TypeFamilies, TypeOperators #-} +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE TypeOperators #-} module Language.PHP.Assignment ( assignment , PHP.Syntax @@ -6,13 +10,14 @@ module Language.PHP.Assignment , PHP.Term(..) ) where -import Prologue - import Assigning.Assignment hiding (Assignment, Error) import qualified Assigning.Assignment as Assignment import qualified Data.Abstract.Name as Name -import qualified Data.Abstract.ScopeGraph as ScopeGraph (AccessControl(..)) +import qualified Data.Abstract.ScopeGraph as ScopeGraph (AccessControl (..)) +import Data.Foldable +import Data.List.NonEmpty (NonEmpty (..), some1) import qualified Data.List.NonEmpty as NonEmpty +import Data.Sum import Data.Syntax ( contextualize , emptyTerm diff --git a/src/Language/PHP/Syntax.hs b/src/Language/PHP/Syntax.hs index f3826b2a6..a4c1a5ab2 100644 --- a/src/Language/PHP/Syntax.hs +++ b/src/Language/PHP/Syntax.hs @@ -1,11 +1,19 @@ -{-# LANGUAGE DeriveAnyClass, DeriveGeneric, DeriveTraversable, DuplicateRecordFields, FlexibleContexts #-} +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DeriveTraversable #-} +{-# LANGUAGE DuplicateRecordFields #-} +{-# LANGUAGE FlexibleContexts #-} module Language.PHP.Syntax (module Language.PHP.Syntax) where -import Prologue hiding (Text) - import Control.Lens.Getter +import Data.Functor.Classes +import Data.Functor.Classes.Generic +import Data.Hashable.Lifted +import Data.List.NonEmpty (NonEmpty (..)) import qualified Data.Map.Strict as Map +import Data.Maybe.Exts import qualified Data.Text as T +import GHC.Generics (Generic1) import Control.Abstract as Abstract import Data.Abstract.BaseError diff --git a/src/Language/Python/Assignment.hs b/src/Language/Python/Assignment.hs index 90cb3e3bc..05ef1f462 100644 --- a/src/Language/Python/Assignment.hs +++ b/src/Language/Python/Assignment.hs @@ -1,4 +1,8 @@ -{-# LANGUAGE DataKinds, FlexibleContexts, RankNTypes, TypeFamilies, TypeOperators #-} +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE TypeOperators #-} module Language.Python.Assignment ( assignment , Python.Syntax @@ -8,8 +12,12 @@ module Language.Python.Assignment import Assigning.Assignment hiding (Assignment, Error) import qualified Assigning.Assignment as Assignment +import Control.Monad import Data.Abstract.Name (name) +import Data.Functor +import Data.List.NonEmpty (some1) import qualified Data.List.NonEmpty as NonEmpty +import Data.Maybe import Data.Sum import Data.Syntax ( contextualize @@ -32,7 +40,6 @@ import qualified Data.Syntax.Statement as Statement import qualified Data.Syntax.Type as Type import Language.Python.Syntax as Python.Syntax import Language.Python.Term as Python -import Prologue import TreeSitter.Python as Grammar type Assignment = Assignment.Assignment [] Grammar @@ -166,14 +173,14 @@ forStatement = symbol ForStatement >>= \ loc -> children (make loc <$> (symbol V where make loc binding subject body forElseClause = case forElseClause of Nothing -> makeTerm loc (Statement.ForEach binding subject body) - Just a -> makeTerm loc (Statement.Else (makeTerm loc $ Statement.ForEach binding subject body) a) + Just a -> makeTerm loc (Statement.Else (makeTerm loc $ Statement.ForEach binding subject body) a) whileStatement :: Assignment (Term Loc) whileStatement = symbol WhileStatement >>= \ loc -> children (make loc <$> term expression <*> term block <*> optional (symbol ElseClause *> children expressions)) where make loc whileCondition whileBody whileElseClause = case whileElseClause of Nothing -> makeTerm loc (Statement.While whileCondition whileBody) - Just a -> makeTerm loc (Statement.Else (makeTerm loc $ Statement.While whileCondition whileBody) a) + Just a -> makeTerm loc (Statement.Else (makeTerm loc $ Statement.While whileCondition whileBody) a) tryStatement :: Assignment (Term Loc) tryStatement = makeTerm <$> symbol TryStatement <*> children (Statement.Try <$> term block <*> manyTerm (expression <|> elseClause)) diff --git a/src/Language/Python/Syntax.hs b/src/Language/Python/Syntax.hs index 476e4957c..86bf32df3 100644 --- a/src/Language/Python/Syntax.hs +++ b/src/Language/Python/Syntax.hs @@ -1,14 +1,27 @@ -{-# LANGUAGE DeriveAnyClass, DeriveGeneric, DeriveTraversable, FlexibleContexts, RecordWildCards, TypeApplications #-} +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DeriveTraversable #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE TypeApplications #-} module Language.Python.Syntax (module Language.Python.Syntax) where -import Prologue - import Control.Lens.Getter import Data.Aeson hiding (object) +import Data.Foldable +import Data.Functor.Classes +import Data.Functor.Classes.Generic +import Data.Hashable +import Data.Hashable.Lifted import qualified Data.List as List +import Data.List.NonEmpty (NonEmpty (..)) import qualified Data.List.NonEmpty as NonEmpty import qualified Data.Map.Strict as Map +import Data.Maybe.Exts +import Data.Text (Text) import qualified Data.Text as T +import Data.Traversable +import GHC.Generics (Generic, Generic1) import System.FilePath.Posix import Control.Abstract.Heap @@ -160,7 +173,7 @@ instance Evaluatable Import where -- Last module path is the one we want to import let path = NonEmpty.last modulePaths ((moduleScope, moduleFrame), _) <- require path - if Prologue.null xs then do + if Prelude.null xs then do insertImportEdge moduleScope insertFrameLink ScopeGraph.Import (Map.singleton moduleScope moduleFrame) else do diff --git a/src/Language/Ruby/Assignment.hs b/src/Language/Ruby/Assignment.hs index c32e530c2..3aa16205d 100644 --- a/src/Language/Ruby/Assignment.hs +++ b/src/Language/Ruby/Assignment.hs @@ -1,4 +1,9 @@ -{-# LANGUAGE DataKinds, FlexibleContexts, OverloadedStrings, RankNTypes, TypeFamilies, TypeOperators #-} +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE TypeOperators #-} module Language.Ruby.Assignment ( assignment , Ruby.Syntax @@ -6,13 +11,15 @@ module Language.Ruby.Assignment , Ruby.Term(..) ) where -import Prologue hiding (for, unless) - import Assigning.Assignment hiding (Assignment, Error) import qualified Assigning.Assignment as Assignment +import Control.Monad hiding (unless) import Data.Abstract.Name (name) -import qualified Data.Abstract.ScopeGraph as ScopeGraph (AccessControl(..)) +import qualified Data.Abstract.ScopeGraph as ScopeGraph (AccessControl (..)) +import Data.List.NonEmpty (some1) import qualified Data.List.NonEmpty as NonEmpty +import Data.Maybe +import Data.Sum import Data.Syntax ( contextualize , emptyTerm diff --git a/src/Language/Ruby/Syntax.hs b/src/Language/Ruby/Syntax.hs index 934de67f5..5c0f2e668 100644 --- a/src/Language/Ruby/Syntax.hs +++ b/src/Language/Ruby/Syntax.hs @@ -1,22 +1,37 @@ -{-# LANGUAGE DeriveAnyClass, DeriveGeneric, DeriveTraversable, DuplicateRecordFields, FlexibleContexts, OverloadedStrings, RecordWildCards, TupleSections, TypeApplications #-} +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DeriveTraversable #-} +{-# LANGUAGE DuplicateRecordFields #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE TupleSections #-} +{-# LANGUAGE TypeApplications #-} module Language.Ruby.Syntax (module Language.Ruby.Syntax) where -import Prologue - import Control.Abstract as Abstract hiding (Load, String) +import Control.Monad import Data.Abstract.BaseError import Data.Abstract.Evaluatable import qualified Data.Abstract.Module as M import Data.Abstract.Name as Name import Data.Abstract.Path import qualified Data.Abstract.ScopeGraph as ScopeGraph +import Data.Functor.Classes +import Data.Functor.Classes.Generic +import Data.Hashable.Lifted import Data.JSON.Fields import qualified Data.Language as Language +import Data.List.NonEmpty (nonEmpty) import qualified Data.Map.Strict as Map +import Data.Maybe.Exts import Data.Semigroup.App import Data.Semigroup.Foldable +import Data.Text (Text) import qualified Data.Text as T +import Data.Traversable (for) import Diffing.Algorithm +import GHC.Generics (Generic1) import System.FilePath.Posix -- TODO: Fully sort out ruby require/load mechanics diff --git a/src/Language/TSX/Assignment.hs b/src/Language/TSX/Assignment.hs index cd4f35dbe..59f218489 100644 --- a/src/Language/TSX/Assignment.hs +++ b/src/Language/TSX/Assignment.hs @@ -1,4 +1,9 @@ -{-# LANGUAGE DataKinds, FlexibleContexts, OverloadedStrings, RankNTypes, TypeFamilies, TypeOperators #-} +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE TypeOperators #-} module Language.TSX.Assignment ( assignment , TSX.Syntax @@ -6,12 +11,17 @@ module Language.TSX.Assignment , TSX.Term(..) ) where -import Assigning.Assignment hiding (Assignment, Error) -import Data.Abstract.Name (name) -import qualified Data.Abstract.ScopeGraph as ScopeGraph (AccessControl(..)) +import Assigning.Assignment hiding (Assignment, Error) import qualified Assigning.Assignment as Assignment -import Data.Sum -import Data.Syntax +import Control.Monad +import Data.Abstract.Name (name) +import qualified Data.Abstract.ScopeGraph as ScopeGraph (AccessControl (..)) +import Data.Foldable +import Data.Function +import Data.List.NonEmpty (nonEmpty, some1) +import Data.Maybe +import Data.Sum +import Data.Syntax ( contextualize , emptyTerm , handleError @@ -31,10 +41,9 @@ import qualified Data.Syntax.Literal as Literal import qualified Data.Syntax.Statement as Statement import qualified Data.Syntax.Type as Type import qualified Language.TSX.Syntax as TSX.Syntax +import Language.TSX.Term as TSX import qualified Language.TypeScript.Resolution as TypeScript.Resolution -import Language.TSX.Term as TSX -import Prologue -import TreeSitter.TSX as Grammar +import TreeSitter.TSX as Grammar type Assignment = Assignment.Assignment [] Grammar @@ -567,11 +576,11 @@ importStatement = makeImportTerm <$> symbol Grammar.ImportStatement <*> childr makeImportTerm1 loc from (Just alias, _) = makeTerm loc (TSX.Syntax.QualifiedAliasedImport alias from) makeImportTerm1 loc from (Nothing, symbols) = makeTerm loc (TSX.Syntax.Import (uncurry TSX.Syntax.Alias <$> symbols) from) makeImportTerm loc ([x], from) = makeImportTerm1 loc from x - makeImportTerm loc (xs, from) = makeTerm loc $ fmap (makeImportTerm1 loc from) xs + makeImportTerm loc (xs, from) = makeTerm loc $ fmap (makeImportTerm1 loc from) xs importSymbol = symbol Grammar.ImportSpecifier *> children (makeNameAliasPair <$> rawIdentifier <*> ((Just <$> rawIdentifier) <|> pure Nothing)) rawIdentifier = symbol Identifier *> (name <$> source) makeNameAliasPair from (Just alias) = (from, alias) - makeNameAliasPair from Nothing = (from, from) + makeNameAliasPair from Nothing = (from, from) -- TODO: Need to validate that inline comments are still handled with this change in assigning to Path and not a Term.Term (Sum TSX.Syntax). fromClause = symbol Grammar.String *> (TypeScript.Resolution.importPath <$> source) @@ -627,7 +636,7 @@ exportStatement = makeTerm <$> symbol Grammar.ExportStatement <*> children (flip exportSymbol = symbol Grammar.ExportSpecifier *> children (makeNameAliasPair <$> rawIdentifier <*> (Just <$> rawIdentifier)) <|> symbol Grammar.ExportSpecifier *> children (makeNameAliasPair <$> rawIdentifier <*> pure Nothing) makeNameAliasPair from (Just alias) = TSX.Syntax.Alias from alias - makeNameAliasPair from Nothing = TSX.Syntax.Alias from from + makeNameAliasPair from Nothing = TSX.Syntax.Alias from from rawIdentifier = symbol Identifier *> (name <$> source) -- TODO: Need to validate that inline comments are still handled with this change in assigning to Path and not a Term.Term (Sum TSX.Syntax). fromClause = symbol Grammar.String *> (TypeScript.Resolution.importPath <$> source) diff --git a/src/Language/TypeScript/Assignment.hs b/src/Language/TypeScript/Assignment.hs index a02a38db4..06f42e172 100644 --- a/src/Language/TypeScript/Assignment.hs +++ b/src/Language/TypeScript/Assignment.hs @@ -1,4 +1,9 @@ -{-# LANGUAGE DataKinds, FlexibleContexts, OverloadedStrings, RankNTypes, TypeFamilies, TypeOperators #-} +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE TypeOperators #-} module Language.TypeScript.Assignment ( assignment , TypeScript.Syntax @@ -6,12 +11,17 @@ module Language.TypeScript.Assignment , TypeScript.Term(..) ) where -import Assigning.Assignment hiding (Assignment, Error) -import Data.Abstract.Name (name) -import qualified Data.Abstract.ScopeGraph as ScopeGraph (AccessControl(..)) +import Assigning.Assignment hiding (Assignment, Error) import qualified Assigning.Assignment as Assignment -import Data.Sum -import Data.Syntax +import Control.Monad +import Data.Abstract.Name (name) +import qualified Data.Abstract.ScopeGraph as ScopeGraph (AccessControl (..)) +import Data.Foldable +import Data.Function +import Data.List.NonEmpty (nonEmpty, some1) +import Data.Maybe +import Data.Sum +import Data.Syntax ( contextualize , emptyTerm , handleError @@ -30,11 +40,10 @@ import qualified Data.Syntax.Expression as Expression import qualified Data.Syntax.Literal as Literal import qualified Data.Syntax.Statement as Statement import qualified Data.Syntax.Type as Type -import qualified Language.TypeScript.Syntax as TypeScript.Syntax import qualified Language.TypeScript.Resolution as TypeScript.Resolution -import Language.TypeScript.Term as TypeScript -import Prologue -import TreeSitter.TypeScript as Grammar +import qualified Language.TypeScript.Syntax as TypeScript.Syntax +import Language.TypeScript.Term as TypeScript +import TreeSitter.TypeScript as Grammar type Assignment = Assignment.Assignment [] Grammar @@ -529,11 +538,11 @@ importStatement = makeImportTerm <$> symbol Grammar.ImportStatement <*> childr makeImportTerm1 loc from (Just alias, _) = makeTerm loc (TypeScript.Syntax.QualifiedAliasedImport alias from) makeImportTerm1 loc from (Nothing, symbols) = makeTerm loc (TypeScript.Syntax.Import (uncurry TypeScript.Syntax.Alias <$> symbols) from) makeImportTerm loc ([x], from) = makeImportTerm1 loc from x - makeImportTerm loc (xs, from) = makeTerm loc $ fmap (makeImportTerm1 loc from) xs + makeImportTerm loc (xs, from) = makeTerm loc $ fmap (makeImportTerm1 loc from) xs importSymbol = symbol Grammar.ImportSpecifier *> children (makeNameAliasPair <$> rawIdentifier <*> ((Just <$> rawIdentifier) <|> pure Nothing)) rawIdentifier = symbol Identifier *> (name <$> source) makeNameAliasPair from (Just alias) = (from, alias) - makeNameAliasPair from Nothing = (from, from) + makeNameAliasPair from Nothing = (from, from) -- TODO: Need to validate that inline comments are still handled with this change in assigning to Path and not a Term. fromClause = symbol Grammar.String *> (TypeScript.Resolution.importPath <$> source) @@ -589,7 +598,7 @@ exportStatement = makeTerm <$> symbol Grammar.ExportStatement <*> children (flip exportSymbol = symbol Grammar.ExportSpecifier *> children (makeNameAliasPair <$> rawIdentifier <*> (Just <$> rawIdentifier)) <|> symbol Grammar.ExportSpecifier *> children (makeNameAliasPair <$> rawIdentifier <*> pure Nothing) makeNameAliasPair from (Just alias) = TypeScript.Syntax.Alias from alias - makeNameAliasPair from Nothing = TypeScript.Syntax.Alias from from + makeNameAliasPair from Nothing = TypeScript.Syntax.Alias from from rawIdentifier = symbol Identifier *> (name <$> source) -- TODO: Need to validate that inline comments are still handled with this change in assigning to Path and not a Term. fromClause = symbol Grammar.String *> (TypeScript.Resolution.importPath <$> source)