Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split syntax module to reduce compilation time #1852

Merged
merged 5 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,343 changes: 6 additions & 1,337 deletions src/swarm-lang/Swarm/Language/Syntax.hs

Large diffs are not rendered by default.

73 changes: 73 additions & 0 deletions src/swarm-lang/Swarm/Language/Syntax/Comments.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ViewPatterns #-}

-- |
-- SPDX-License-Identifier: BSD-3-Clause
--
-- Types for working with comments in Swarm prgramming language.
nitinprakash96 marked this conversation as resolved.
Show resolved Hide resolved
module Swarm.Language.Syntax.Comments (
CommentType (..),
CommentSituation (..),
isStandalone,
Comment (..),
Comments (..),
beforeComments,
afterComments,
) where

import Control.Lens (AsEmpty, makeLenses)
import Data.Aeson.Types hiding (Key)
import Data.Data (Data)
import Data.Sequence (Seq)
import Data.Text hiding (filter, length, map)
import GHC.Generics (Generic)
import Swarm.Language.Syntax.Loc

-- | Line vs block comments.
data CommentType = LineComment | BlockComment
deriving (Eq, Ord, Read, Show, Enum, Bounded, Generic, Data, ToJSON, FromJSON)

-- | Was a comment all by itself on a line, or did it occur after some
-- other tokens on a line?
data CommentSituation = StandaloneComment | SuffixComment
deriving (Eq, Ord, Read, Show, Enum, Bounded, Generic, Data, ToJSON, FromJSON)

-- | Test whether a comment is a standalone comment or not.
isStandalone :: Comment -> Bool
isStandalone = (== StandaloneComment) . commentSituation

-- | A comment is retained as some text plus metadata (source
-- location, comment type, + comment situation). While parsing we
-- record all comments out-of-band, for later re-insertion into the
-- AST.
data Comment = Comment
{ commentSrcLoc :: SrcLoc
, commentType :: CommentType
, commentSituation :: CommentSituation
, commentText :: Text
}
deriving (Eq, Show, Generic, Data, ToJSON, FromJSON)

-- | Comments which can be attached to a particular AST node. Some
-- comments come textually before the node and some come after.
data Comments = Comments
{ _beforeComments :: Seq Comment
, _afterComments :: Seq Comment
}
deriving (Eq, Show, Generic, Data, ToJSON, FromJSON)

makeLenses ''Comments

instance Semigroup Comments where
Comments b1 a1 <> Comments b2 a2 = Comments (b1 <> b2) (a1 <> a2)

instance Monoid Comments where
mempty = Comments mempty mempty

instance AsEmpty Comments
Loading
Loading