mirror of
https://github.com/anoma/juvix.git
synced 2025-01-08 16:51:53 +03:00
[ormolu] run ormolu
This commit is contained in:
parent
f736e57d58
commit
66f36c0bd4
84
app/Main.hs
84
app/Main.hs
@ -1,45 +1,51 @@
|
|||||||
{-# LANGUAGE ApplicativeDo #-}
|
{-# LANGUAGE ApplicativeDo #-}
|
||||||
|
|
||||||
module Main (main) where
|
module Main (main) where
|
||||||
|
|
||||||
import MiniJuvix.Utils.Prelude
|
import Data.Aeson (defaultOptions)
|
||||||
import qualified MiniJuvix.Syntax.Concrete.Parser as M
|
import qualified MiniJuvix.Syntax.Concrete.Parser as M
|
||||||
import qualified MiniJuvix.Syntax.Concrete.Scoped.Scoper as M
|
|
||||||
import qualified MiniJuvix.Syntax.Concrete.Scoped.Pretty.Ansi as M
|
import qualified MiniJuvix.Syntax.Concrete.Scoped.Pretty.Ansi as M
|
||||||
|
import MiniJuvix.Syntax.Concrete.Scoped.Pretty.Base (Options (_optShowNameId))
|
||||||
import qualified MiniJuvix.Syntax.Concrete.Scoped.Pretty.Base as M
|
import qualified MiniJuvix.Syntax.Concrete.Scoped.Pretty.Base as M
|
||||||
|
import qualified MiniJuvix.Syntax.Concrete.Scoped.Scoper as M
|
||||||
|
import MiniJuvix.Utils.Prelude
|
||||||
import Options.Applicative
|
import Options.Applicative
|
||||||
import Options.Applicative.Help.Pretty
|
import Options.Applicative.Help.Pretty
|
||||||
import Data.Aeson (defaultOptions)
|
|
||||||
import MiniJuvix.Syntax.Concrete.Scoped.Pretty.Base (Options(_optShowNameId))
|
|
||||||
|
|
||||||
data Command =
|
data Command
|
||||||
Scope ScopeOptions
|
= Scope ScopeOptions
|
||||||
| Parse ParseOptions
|
| Parse ParseOptions
|
||||||
|
|
||||||
data ScopeOptions = ScopeOptions {
|
data ScopeOptions = ScopeOptions
|
||||||
_scopeRootDir :: FilePath
|
{ _scopeRootDir :: FilePath,
|
||||||
, _scopeInputFile :: FilePath
|
_scopeInputFile :: FilePath,
|
||||||
, _scopeShowIds :: Bool
|
_scopeShowIds :: Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
data ParseOptions = ParseOptions
|
data ParseOptions = ParseOptions
|
||||||
|
|
||||||
parseScope :: Parser ScopeOptions
|
parseScope :: Parser ScopeOptions
|
||||||
parseScope = do
|
parseScope = do
|
||||||
_scopeRootDir <- strOption
|
_scopeRootDir <-
|
||||||
(long "rootDir"
|
strOption
|
||||||
<> short 'd'
|
( long "rootDir"
|
||||||
<> metavar "DIR"
|
<> short 'd'
|
||||||
<> value "."
|
<> metavar "DIR"
|
||||||
<> showDefault
|
<> value "."
|
||||||
<> help "Root directory")
|
<> showDefault
|
||||||
_scopeInputFile <- argument str
|
<> help "Root directory"
|
||||||
(metavar "MINIJUVIX_FILE"
|
)
|
||||||
<> help "Path to a .mjuvix file"
|
_scopeInputFile <-
|
||||||
)
|
argument
|
||||||
_scopeShowIds <- switch
|
str
|
||||||
( long "show-name-ids"
|
( metavar "MINIJUVIX_FILE"
|
||||||
<> help "Show the unique number of each identifier"
|
<> help "Path to a .mjuvix file"
|
||||||
)
|
)
|
||||||
|
_scopeShowIds <-
|
||||||
|
switch
|
||||||
|
( long "show-name-ids"
|
||||||
|
<> help "Show the unique number of each identifier"
|
||||||
|
)
|
||||||
|
|
||||||
pure ScopeOptions {..}
|
pure ScopeOptions {..}
|
||||||
|
|
||||||
@ -47,26 +53,30 @@ parseParse :: Parser ParseOptions
|
|||||||
parseParse = pure ParseOptions
|
parseParse = pure ParseOptions
|
||||||
|
|
||||||
descr :: ParserInfo Command
|
descr :: ParserInfo Command
|
||||||
descr = info (parseCommand <**> helper)
|
descr =
|
||||||
(fullDesc
|
info
|
||||||
|
(parseCommand <**> helper)
|
||||||
|
( fullDesc
|
||||||
<> progDesc "The MiniJuvix compiler."
|
<> progDesc "The MiniJuvix compiler."
|
||||||
<> headerDoc (Just $ dullblue $ bold $ underline "MiniJuvix help")
|
<> headerDoc (Just $ dullblue $ bold $ underline "MiniJuvix help")
|
||||||
<> footerDoc (Just foot)
|
<> footerDoc (Just foot)
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
foot :: Doc
|
foot :: Doc
|
||||||
foot = bold "maintainers: " <> "jan@heliax.dev; jonathan@heliax.dev"
|
foot = bold "maintainers: " <> "jan@heliax.dev; jonathan@heliax.dev"
|
||||||
|
|
||||||
parseCommand :: Parser Command
|
parseCommand :: Parser Command
|
||||||
parseCommand = subparser (
|
parseCommand =
|
||||||
command "parse" (info (Parse <$> parseParse) (progDesc "Parse some .mjuvix files"))
|
subparser
|
||||||
<> command "scope" (info (Scope <$> parseScope) (progDesc "Parse and scope some .mjuvix files"))
|
( command "parse" (info (Parse <$> parseParse) (progDesc "Parse some .mjuvix files"))
|
||||||
)
|
<> command "scope" (info (Scope <$> parseScope) (progDesc "Parse and scope some .mjuvix files"))
|
||||||
|
)
|
||||||
|
|
||||||
mkPrettyOptions :: ScopeOptions -> M.Options
|
mkPrettyOptions :: ScopeOptions -> M.Options
|
||||||
mkPrettyOptions ScopeOptions {..} = M.defaultOptions {
|
mkPrettyOptions ScopeOptions {..} =
|
||||||
_optShowNameId = _scopeShowIds
|
M.defaultOptions
|
||||||
}
|
{ _optShowNameId = _scopeShowIds
|
||||||
|
}
|
||||||
|
|
||||||
go :: Command -> IO ()
|
go :: Command -> IO ()
|
||||||
go c = case c of
|
go c = case c of
|
||||||
|
@ -234,22 +234,22 @@ deriving stock instance (Lift (ExpressionType s), Lift (SymbolType s)) => Lift (
|
|||||||
-- Pattern
|
-- Pattern
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
data PatternInfixApp = PatternInfixApp {
|
data PatternInfixApp = PatternInfixApp
|
||||||
patInfixConstructor :: NameType 'Scoped,
|
{ patInfixConstructor :: NameType 'Scoped,
|
||||||
patInfixLeft :: Pattern,
|
patInfixLeft :: Pattern,
|
||||||
patInfixRight :: Pattern
|
patInfixRight :: Pattern
|
||||||
}
|
}
|
||||||
deriving stock (Show, Eq, Ord)
|
deriving stock (Show, Eq, Ord)
|
||||||
|
|
||||||
data PatternPostfixApp = PatternPostfixApp {
|
data PatternPostfixApp = PatternPostfixApp
|
||||||
patPostfixConstructor :: NameType 'Scoped,
|
{ patPostfixConstructor :: NameType 'Scoped,
|
||||||
patPostfixParameter :: Pattern
|
patPostfixParameter :: Pattern
|
||||||
}
|
}
|
||||||
deriving stock (Show, Eq, Ord)
|
deriving stock (Show, Eq, Ord)
|
||||||
|
|
||||||
data PatternPrefixApp = PatternPrefixApp {
|
data PatternPrefixApp = PatternPrefixApp
|
||||||
patPrefixConstructor :: NameType 'Scoped,
|
{ patPrefixConstructor :: NameType 'Scoped,
|
||||||
patPrefixParameter :: Pattern
|
patPrefixParameter :: Pattern
|
||||||
}
|
}
|
||||||
deriving stock (Show, Eq, Ord)
|
deriving stock (Show, Eq, Ord)
|
||||||
|
|
||||||
@ -826,9 +826,9 @@ data PostfixApplication = PostfixApplication
|
|||||||
-- Let block expression
|
-- Let block expression
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
data LetBlock (s :: Stage) = LetBlock {
|
data LetBlock (s :: Stage) = LetBlock
|
||||||
letClauses :: [LetClause s],
|
{ letClauses :: [LetClause s],
|
||||||
letExpression :: ExpressionType s
|
letExpression :: ExpressionType s
|
||||||
}
|
}
|
||||||
|
|
||||||
deriving stock instance
|
deriving stock instance
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
module MiniJuvix.Syntax.Concrete.Scoped.Pretty.Ansi where
|
module MiniJuvix.Syntax.Concrete.Scoped.Pretty.Ansi where
|
||||||
|
|
||||||
import Prettyprinter
|
|
||||||
import MiniJuvix.Syntax.Concrete.Scoped.Pretty.Base
|
|
||||||
import MiniJuvix.Syntax.Concrete.Language
|
import MiniJuvix.Syntax.Concrete.Language
|
||||||
|
import MiniJuvix.Syntax.Concrete.Scoped.Name (NameKind (..))
|
||||||
|
import MiniJuvix.Syntax.Concrete.Scoped.Pretty.Base
|
||||||
import MiniJuvix.Utils.Prelude
|
import MiniJuvix.Utils.Prelude
|
||||||
|
import Prettyprinter
|
||||||
import Prettyprinter.Render.Terminal
|
import Prettyprinter.Render.Terminal
|
||||||
import MiniJuvix.Syntax.Concrete.Scoped.Name (NameKind(..))
|
|
||||||
|
|
||||||
printTopModuleDefault :: Module 'Scoped 'ModuleTop -> IO ()
|
printTopModuleDefault :: Module 'Scoped 'ModuleTop -> IO ()
|
||||||
printTopModuleDefault = printTopModule defaultOptions
|
printTopModuleDefault = printTopModule defaultOptions
|
||||||
@ -13,10 +13,10 @@ printTopModuleDefault = printTopModule defaultOptions
|
|||||||
printTopModule :: Options -> Module 'Scoped 'ModuleTop -> IO ()
|
printTopModule :: Options -> Module 'Scoped 'ModuleTop -> IO ()
|
||||||
printTopModule opts m = renderIO stdout docStream'
|
printTopModule opts m = renderIO stdout docStream'
|
||||||
where
|
where
|
||||||
docStream :: SimpleDocStream Ann
|
docStream :: SimpleDocStream Ann
|
||||||
docStream = layoutPretty defaultLayoutOptions (prettyTopModule opts m)
|
docStream = layoutPretty defaultLayoutOptions (prettyTopModule opts m)
|
||||||
docStream' :: SimpleDocStream AnsiStyle
|
docStream' :: SimpleDocStream AnsiStyle
|
||||||
docStream' = reAnnotateS stylize docStream
|
docStream' = reAnnotateS stylize docStream
|
||||||
|
|
||||||
stylize :: Ann -> AnsiStyle
|
stylize :: Ann -> AnsiStyle
|
||||||
stylize a = case a of
|
stylize a = case a of
|
||||||
|
@ -1,37 +1,38 @@
|
|||||||
module MiniJuvix.Syntax.Concrete.Scoped.Pretty.Base where
|
module MiniJuvix.Syntax.Concrete.Scoped.Pretty.Base where
|
||||||
|
|
||||||
|
import Data.Singletons
|
||||||
import qualified MiniJuvix.Syntax.Concrete.Scoped.Name as S
|
|
||||||
import MiniJuvix.Utils.Prelude hiding (Reader, runReader, asks)
|
|
||||||
import MiniJuvix.Syntax.Concrete.Language
|
import MiniJuvix.Syntax.Concrete.Language
|
||||||
|
import qualified MiniJuvix.Syntax.Concrete.Scoped.Name as S
|
||||||
|
import MiniJuvix.Utils.Prelude hiding (Reader, asks, runReader)
|
||||||
import Polysemy
|
import Polysemy
|
||||||
import Polysemy.Reader
|
import Polysemy.Reader
|
||||||
import Prettyprinter hiding (braces, parens)
|
import Prettyprinter hiding (braces, parens)
|
||||||
import Data.Singletons
|
|
||||||
|
|
||||||
|
data Ann
|
||||||
data Ann = AnnKind S.NameKind
|
= AnnKind S.NameKind
|
||||||
| AnnKeyword
|
| AnnKeyword
|
||||||
| AnnDelimiter
|
| AnnDelimiter
|
||||||
|
|
||||||
data Options = Options {
|
data Options = Options
|
||||||
_optOptimizeParens :: Bool,
|
{ _optOptimizeParens :: Bool,
|
||||||
_optShowNameId :: Bool,
|
_optShowNameId :: Bool,
|
||||||
_optIndent :: Int
|
_optIndent :: Int
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultOptions :: Options
|
defaultOptions :: Options
|
||||||
defaultOptions = Options {
|
defaultOptions =
|
||||||
_optOptimizeParens = True,
|
Options
|
||||||
_optShowNameId = False,
|
{ _optOptimizeParens = True,
|
||||||
_optIndent = 2
|
_optShowNameId = False,
|
||||||
}
|
_optIndent = 2
|
||||||
|
}
|
||||||
|
|
||||||
-- | Pretty prints a top module.
|
-- | Pretty prints a top module.
|
||||||
prettyTopModule :: Options -> Module 'Scoped 'ModuleTop -> Doc Ann
|
prettyTopModule :: Options -> Module 'Scoped 'ModuleTop -> Doc Ann
|
||||||
prettyTopModule opts = run . runReader opts . ppModule
|
prettyTopModule opts = run . runReader opts . ppModule
|
||||||
|
|
||||||
infixl 7 <+?>
|
infixl 7 <+?>
|
||||||
|
|
||||||
(<+?>) :: Doc ann -> Maybe (Doc ann) -> Doc ann
|
(<+?>) :: Doc ann -> Maybe (Doc ann) -> Doc ann
|
||||||
(<+?>) a = maybe a (a <+>)
|
(<+?>) a = maybe a (a <+>)
|
||||||
|
|
||||||
@ -185,30 +186,33 @@ endSemicolon x = x <> kwSemicolon
|
|||||||
|
|
||||||
ppModule :: (SingI t, Members '[Reader Options] r) => Module 'Scoped t -> Sem r (Doc Ann)
|
ppModule :: (SingI t, Members '[Reader Options] r) => Module 'Scoped t -> Sem r (Doc Ann)
|
||||||
ppModule Module {..} = do
|
ppModule Module {..} = do
|
||||||
moduleBody' <- mapM (fmap endSemicolon . ppStatement) moduleBody >>= indented . vsep
|
moduleBody' <- mapM (fmap endSemicolon . ppStatement) moduleBody >>= indented . vsep
|
||||||
modulePath' <- ppModulePathType modulePath
|
modulePath' <- ppModulePathType modulePath
|
||||||
return $ kwModule <+> modulePath' <> kwSemicolon <> line
|
return $
|
||||||
<> moduleBody' <> line
|
kwModule <+> modulePath' <> kwSemicolon <> line
|
||||||
<> kwEnd <> kwSemicolon
|
<> moduleBody'
|
||||||
|
<> line
|
||||||
|
<> kwEnd
|
||||||
|
<> kwSemicolon
|
||||||
|
|
||||||
ppOperatorSyntaxDef :: Members '[Reader Options] r => OperatorSyntaxDef -> Sem r (Doc Ann)
|
ppOperatorSyntaxDef :: Members '[Reader Options] r => OperatorSyntaxDef -> Sem r (Doc Ann)
|
||||||
ppOperatorSyntaxDef OperatorSyntaxDef {..} = do
|
ppOperatorSyntaxDef OperatorSyntaxDef {..} = do
|
||||||
opSymbol' <- ppSymbol opSymbol
|
opSymbol' <- ppSymbol opSymbol
|
||||||
return $ ppFixity opFixity <+> opSymbol'
|
return $ ppFixity opFixity <+> opSymbol'
|
||||||
where
|
where
|
||||||
ppFixity :: Fixity -> Doc Ann
|
ppFixity :: Fixity -> Doc Ann
|
||||||
ppFixity Fixity {..} =
|
ppFixity Fixity {..} =
|
||||||
ppArity <+> pretty fixityPrecedence
|
ppArity <+> pretty fixityPrecedence
|
||||||
where
|
where
|
||||||
ppArity :: Doc Ann
|
ppArity :: Doc Ann
|
||||||
ppArity = case fixityArity of
|
ppArity = case fixityArity of
|
||||||
Unary p -> case p of
|
Unary p -> case p of
|
||||||
AssocPrefix -> kwPrefix
|
AssocPrefix -> kwPrefix
|
||||||
AssocPostfix -> kwPostfix
|
AssocPostfix -> kwPostfix
|
||||||
Binary p -> case p of
|
Binary p -> case p of
|
||||||
AssocRight -> kwInfixr
|
AssocRight -> kwInfixr
|
||||||
AssocLeft -> kwInfixl
|
AssocLeft -> kwInfixl
|
||||||
AssocNone -> kwInfix
|
AssocNone -> kwInfix
|
||||||
|
|
||||||
ppDataConstructorDef :: Members '[Reader Options] r => DataConstructorDef 'Scoped -> Sem r (Doc Ann)
|
ppDataConstructorDef :: Members '[Reader Options] r => DataConstructorDef 'Scoped -> Sem r (Doc Ann)
|
||||||
ppDataConstructorDef DataConstructorDef {..} = do
|
ppDataConstructorDef DataConstructorDef {..} = do
|
||||||
@ -222,18 +226,19 @@ ppDataTypeDef DataTypeDef {..} = do
|
|||||||
dataTypeParameters' <- hsep <$> mapM ppDataTypeParameter dataTypeParameters
|
dataTypeParameters' <- hsep <$> mapM ppDataTypeParameter dataTypeParameters
|
||||||
dataTypeType' <- ppTypeType
|
dataTypeType' <- ppTypeType
|
||||||
dataTypeConstructors' <- ppBlock ppDataConstructorDef dataTypeConstructors
|
dataTypeConstructors' <- ppBlock ppDataConstructorDef dataTypeConstructors
|
||||||
return $ kwInductive <+> dataTypeName' <+> dataTypeParameters' <+?> dataTypeType'
|
return $
|
||||||
<+> dataTypeConstructors'
|
kwInductive <+> dataTypeName' <+> dataTypeParameters' <+?> dataTypeType'
|
||||||
|
<+> dataTypeConstructors'
|
||||||
where
|
where
|
||||||
ppTypeType :: Sem r (Maybe (Doc Ann))
|
ppTypeType :: Sem r (Maybe (Doc Ann))
|
||||||
ppTypeType = case dataTypeType of
|
ppTypeType = case dataTypeType of
|
||||||
Nothing -> return Nothing
|
Nothing -> return Nothing
|
||||||
Just e -> Just . (kwColon <+>) <$> ppExpression e
|
Just e -> Just . (kwColon <+>) <$> ppExpression e
|
||||||
ppDataTypeParameter :: DataTypeParameter 'Scoped -> Sem r (Doc Ann)
|
ppDataTypeParameter :: DataTypeParameter 'Scoped -> Sem r (Doc Ann)
|
||||||
ppDataTypeParameter DataTypeParameter {..} = do
|
ppDataTypeParameter DataTypeParameter {..} = do
|
||||||
dataTypeParameterName' <- ppSSymbol dataTypeParameterName
|
dataTypeParameterName' <- ppSSymbol dataTypeParameterName
|
||||||
dataTypeParameterType' <- ppExpression dataTypeParameterType
|
dataTypeParameterType' <- ppExpression dataTypeParameterType
|
||||||
return $ parens (dataTypeParameterName' <+> kwColon <+> dataTypeParameterType')
|
return $ parens (dataTypeParameterName' <+> kwColon <+> dataTypeParameterType')
|
||||||
|
|
||||||
dotted :: [Doc Ann] -> Doc Ann
|
dotted :: [Doc Ann] -> Doc Ann
|
||||||
dotted = concatWith (surround kwDot)
|
dotted = concatWith (surround kwDot)
|
||||||
@ -274,8 +279,8 @@ ppOpen OpenModule {..} = do
|
|||||||
openUsingHiding' <- ppUsingHiding
|
openUsingHiding' <- ppUsingHiding
|
||||||
return $ keyword "open" <+> openModuleName' <+> openUsingHiding'
|
return $ keyword "open" <+> openModuleName' <+> openUsingHiding'
|
||||||
where
|
where
|
||||||
ppUsingHiding :: Sem r (Doc Ann)
|
ppUsingHiding :: Sem r (Doc Ann)
|
||||||
ppUsingHiding = return $ pretty ("TODO" :: Text)
|
ppUsingHiding = return $ pretty ("TODO" :: Text)
|
||||||
|
|
||||||
ppTypeSignature :: Members '[Reader Options] r => TypeSignature 'Scoped -> Sem r (Doc Ann)
|
ppTypeSignature :: Members '[Reader Options] r => TypeSignature 'Scoped -> Sem r (Doc Ann)
|
||||||
ppTypeSignature TypeSignature {..} = do
|
ppTypeSignature TypeSignature {..} = do
|
||||||
@ -289,21 +294,21 @@ ppFunction Function {..} = do
|
|||||||
funReturn' <- ppExpressionAtom funReturn
|
funReturn' <- ppExpressionAtom funReturn
|
||||||
return $ funParameter' <+> kwArrowR <+> funReturn'
|
return $ funParameter' <+> kwArrowR <+> funReturn'
|
||||||
where
|
where
|
||||||
ppUsage :: Maybe Usage -> Doc Ann
|
ppUsage :: Maybe Usage -> Doc Ann
|
||||||
ppUsage m = case m of
|
ppUsage m = case m of
|
||||||
Nothing -> kwColon
|
Nothing -> kwColon
|
||||||
Just u -> case u of
|
Just u -> case u of
|
||||||
UsageNone -> kwColonZero
|
UsageNone -> kwColonZero
|
||||||
UsageOnce -> kwColonOne
|
UsageOnce -> kwColonOne
|
||||||
UsageOmega -> kwColonOmega
|
UsageOmega -> kwColonOmega
|
||||||
ppFunParameter :: FunctionParameter 'Scoped -> Sem r (Doc Ann)
|
ppFunParameter :: FunctionParameter 'Scoped -> Sem r (Doc Ann)
|
||||||
ppFunParameter FunctionParameter {..} = do
|
ppFunParameter FunctionParameter {..} = do
|
||||||
case paramName of
|
case paramName of
|
||||||
Nothing -> ppExpressionAtom paramType
|
Nothing -> ppExpressionAtom paramType
|
||||||
Just n -> do
|
Just n -> do
|
||||||
paramName' <- ppSSymbol n
|
paramName' <- ppSSymbol n
|
||||||
paramType' <- ppExpression paramType
|
paramType' <- ppExpression paramType
|
||||||
return $ parens (paramName' <+> ppUsage paramUsage <+> paramType')
|
return $ parens (paramName' <+> ppUsage paramUsage <+> paramType')
|
||||||
|
|
||||||
ppUniverse :: Members '[Reader Options] r => Universe -> Sem r (Doc Ann)
|
ppUniverse :: Members '[Reader Options] r => Universe -> Sem r (Doc Ann)
|
||||||
ppUniverse (Universe n) = return $ kwType <+> pretty n
|
ppUniverse (Universe n) = return $ kwType <+> pretty n
|
||||||
@ -314,10 +319,10 @@ ppLetBlock LetBlock {..} = do
|
|||||||
letExpression' <- ppExpression letExpression
|
letExpression' <- ppExpression letExpression
|
||||||
return $ kwLet <+> letClauses' <+> kwIn <+> letExpression'
|
return $ kwLet <+> letClauses' <+> kwIn <+> letExpression'
|
||||||
where
|
where
|
||||||
ppLetClause :: LetClause 'Scoped -> Sem r (Doc Ann)
|
ppLetClause :: LetClause 'Scoped -> Sem r (Doc Ann)
|
||||||
ppLetClause c = case c of
|
ppLetClause c = case c of
|
||||||
LetTypeSig sig -> ppTypeSignature sig
|
LetTypeSig sig -> ppTypeSignature sig
|
||||||
LetFunClause cl -> ppFunctionClause cl
|
LetFunClause cl -> ppFunctionClause cl
|
||||||
|
|
||||||
ppBlock :: Members '[Reader Options] r => (a -> Sem r (Doc Ann)) -> [a] -> Sem r (Doc Ann)
|
ppBlock :: Members '[Reader Options] r => (a -> Sem r (Doc Ann)) -> [a] -> Sem r (Doc Ann)
|
||||||
ppBlock ppItem items = mapM (fmap endSemicolon . ppItem) items >>= bracesIndent . vsep
|
ppBlock ppItem items = mapM (fmap endSemicolon . ppItem) items >>= bracesIndent . vsep
|
||||||
@ -328,22 +333,22 @@ ppMatch Match {..} = do
|
|||||||
matchAlts' <- ppBlock ppMatchAlt matchAlts
|
matchAlts' <- ppBlock ppMatchAlt matchAlts
|
||||||
return $ kwMatch <+> matchExpression' <+> matchAlts'
|
return $ kwMatch <+> matchExpression' <+> matchAlts'
|
||||||
where
|
where
|
||||||
ppMatchAlt :: MatchAlt 'Scoped -> Sem r (Doc Ann)
|
ppMatchAlt :: MatchAlt 'Scoped -> Sem r (Doc Ann)
|
||||||
ppMatchAlt MatchAlt {..} = do
|
ppMatchAlt MatchAlt {..} = do
|
||||||
matchAltPattern' <- ppPattern matchAltPattern
|
matchAltPattern' <- ppPattern matchAltPattern
|
||||||
matchAltBody' <- ppExpression matchAltBody
|
matchAltBody' <- ppExpression matchAltBody
|
||||||
return $ matchAltPattern' <+> kwMapsto <+> matchAltBody'
|
return $ matchAltPattern' <+> kwMapsto <+> matchAltBody'
|
||||||
|
|
||||||
ppLambda :: forall r. Members '[Reader Options] r => Lambda 'Scoped -> Sem r (Doc Ann)
|
ppLambda :: forall r. Members '[Reader Options] r => Lambda 'Scoped -> Sem r (Doc Ann)
|
||||||
ppLambda Lambda {..} = do
|
ppLambda Lambda {..} = do
|
||||||
lambdaClauses' <- ppBlock ppLambdaClause lambdaClauses
|
lambdaClauses' <- ppBlock ppLambdaClause lambdaClauses
|
||||||
return $ kwLambda <+> lambdaClauses'
|
return $ kwLambda <+> lambdaClauses'
|
||||||
where
|
where
|
||||||
ppLambdaClause :: LambdaClause 'Scoped -> Sem r (Doc Ann)
|
ppLambdaClause :: LambdaClause 'Scoped -> Sem r (Doc Ann)
|
||||||
ppLambdaClause LambdaClause {..} = do
|
ppLambdaClause LambdaClause {..} = do
|
||||||
lambdaParameters' <- hsep . toList <$> mapM ppPattern lambdaParameters
|
lambdaParameters' <- hsep . toList <$> mapM ppPattern lambdaParameters
|
||||||
lambdaBody' <- ppExpression lambdaBody
|
lambdaBody' <- ppExpression lambdaBody
|
||||||
return $ lambdaParameters' <+> kwMapsto <+> lambdaBody'
|
return $ lambdaParameters' <+> kwMapsto <+> lambdaBody'
|
||||||
|
|
||||||
ppFunctionClause :: forall r. Members '[Reader Options] r => FunctionClause 'Scoped -> Sem r (Doc Ann)
|
ppFunctionClause :: forall r. Members '[Reader Options] r => FunctionClause 'Scoped -> Sem r (Doc Ann)
|
||||||
ppFunctionClause FunctionClause {..} = do
|
ppFunctionClause FunctionClause {..} = do
|
||||||
@ -351,17 +356,18 @@ ppFunctionClause FunctionClause {..} = do
|
|||||||
clausePatterns' <- hsep <$> mapM ppPattern clausePatterns
|
clausePatterns' <- hsep <$> mapM ppPattern clausePatterns
|
||||||
clauseBody' <- ppExpression clauseBody
|
clauseBody' <- ppExpression clauseBody
|
||||||
clauseWhere' <- sequence $ ppWhereBlock <$> clauseWhere
|
clauseWhere' <- sequence $ ppWhereBlock <$> clauseWhere
|
||||||
return $ clauseOwnerFunction' <+> clausePatterns' <+> kwAssignment <+> clauseBody'
|
return $
|
||||||
<+?> (((line <> kwWhere) <+>) <$> clauseWhere')
|
clauseOwnerFunction' <+> clausePatterns' <+> kwAssignment <+> clauseBody'
|
||||||
|
<+?> (((line <> kwWhere) <+>) <$> clauseWhere')
|
||||||
where
|
where
|
||||||
ppWhereBlock :: WhereBlock 'Scoped -> Sem r (Doc Ann)
|
ppWhereBlock :: WhereBlock 'Scoped -> Sem r (Doc Ann)
|
||||||
ppWhereBlock WhereBlock {..} = ppBlock ppWhereClause whereClauses
|
ppWhereBlock WhereBlock {..} = ppBlock ppWhereClause whereClauses
|
||||||
where
|
where
|
||||||
ppWhereClause :: WhereClause 'Scoped -> Sem r (Doc Ann)
|
ppWhereClause :: WhereClause 'Scoped -> Sem r (Doc Ann)
|
||||||
ppWhereClause c = case c of
|
ppWhereClause c = case c of
|
||||||
WhereOpenModule o -> ppOpen o
|
WhereOpenModule o -> ppOpen o
|
||||||
WhereTypeSig sig -> ppTypeSignature sig
|
WhereTypeSig sig -> ppTypeSignature sig
|
||||||
WhereFunClause fun -> ppFunctionClause fun
|
WhereFunClause fun -> ppFunctionClause fun
|
||||||
|
|
||||||
ppAxiom :: Members '[Reader Options] r => AxiomDef 'Scoped -> Sem r (Doc Ann)
|
ppAxiom :: Members '[Reader Options] r => AxiomDef 'Scoped -> Sem r (Doc Ann)
|
||||||
ppAxiom AxiomDef {..} = do
|
ppAxiom AxiomDef {..} = do
|
||||||
@ -387,57 +393,57 @@ ppImport (Import (Module {..})) = do
|
|||||||
ppPattern :: forall r. Members '[Reader Options] r => Pattern -> Sem r (Doc Ann)
|
ppPattern :: forall r. Members '[Reader Options] r => Pattern -> Sem r (Doc Ann)
|
||||||
ppPattern = goAtom
|
ppPattern = goAtom
|
||||||
where
|
where
|
||||||
isAtomicPat :: Pattern -> Bool
|
isAtomicPat :: Pattern -> Bool
|
||||||
isAtomicPat p = case p of
|
isAtomicPat p = case p of
|
||||||
PatternVariable {} -> True
|
PatternVariable {} -> True
|
||||||
PatternApplication {} -> False
|
PatternApplication {} -> False
|
||||||
PatternConstructor {} -> True
|
PatternConstructor {} -> True
|
||||||
PatternInfixApplication {} -> False
|
PatternInfixApplication {} -> False
|
||||||
PatternPostfixApplication {} -> False
|
PatternPostfixApplication {} -> False
|
||||||
PatternPrefixApplication {} -> False
|
PatternPrefixApplication {} -> False
|
||||||
PatternWildcard -> True
|
PatternWildcard -> True
|
||||||
PatternEmpty -> True
|
PatternEmpty -> True
|
||||||
goAtom :: Pattern -> Sem r (Doc Ann)
|
goAtom :: Pattern -> Sem r (Doc Ann)
|
||||||
goAtom p = do
|
goAtom p = do
|
||||||
p' <- go p
|
p' <- go p
|
||||||
return $ if isAtomicPat p then p' else parens p'
|
return $ if isAtomicPat p then p' else parens p'
|
||||||
go :: Pattern -> Sem r (Doc Ann)
|
go :: Pattern -> Sem r (Doc Ann)
|
||||||
go p = case p of
|
go p = case p of
|
||||||
PatternVariable v -> ppSSymbol v
|
PatternVariable v -> ppSSymbol v
|
||||||
PatternApplication l r -> do
|
PatternApplication l r -> do
|
||||||
l' <- goAtom l
|
l' <- goAtom l
|
||||||
r' <- goAtom r
|
r' <- goAtom r
|
||||||
return $ l' <+> r'
|
return $ l' <+> r'
|
||||||
PatternWildcard -> return kwWildcard
|
PatternWildcard -> return kwWildcard
|
||||||
PatternEmpty -> return $ parens mempty
|
PatternEmpty -> return $ parens mempty
|
||||||
PatternConstructor constr -> ppSName constr
|
PatternConstructor constr -> ppSName constr
|
||||||
PatternInfixApplication i -> ppPatternInfixApp i
|
PatternInfixApplication i -> ppPatternInfixApp i
|
||||||
PatternPrefixApplication i -> ppPatternPrefixApp i
|
PatternPrefixApplication i -> ppPatternPrefixApp i
|
||||||
PatternPostfixApplication i -> ppPatternPostfixApp i
|
PatternPostfixApplication i -> ppPatternPostfixApp i
|
||||||
|
|
||||||
ppPatternInfixApp :: PatternInfixApp -> Sem r (Doc Ann)
|
ppPatternInfixApp :: PatternInfixApp -> Sem r (Doc Ann)
|
||||||
ppPatternInfixApp PatternInfixApp {..} = do
|
ppPatternInfixApp PatternInfixApp {..} = do
|
||||||
patInfixConstructor' <- ppSName patInfixConstructor
|
patInfixConstructor' <- ppSName patInfixConstructor
|
||||||
patInfixLeft' <- goAtom patInfixLeft
|
patInfixLeft' <- goAtom patInfixLeft
|
||||||
patInfixRight' <- goAtom patInfixRight
|
patInfixRight' <- goAtom patInfixRight
|
||||||
return $ patInfixLeft' <+> patInfixConstructor' <+> patInfixRight'
|
return $ patInfixLeft' <+> patInfixConstructor' <+> patInfixRight'
|
||||||
|
|
||||||
ppPatternPrefixApp :: PatternPrefixApp -> Sem r (Doc Ann)
|
ppPatternPrefixApp :: PatternPrefixApp -> Sem r (Doc Ann)
|
||||||
ppPatternPrefixApp PatternPrefixApp {..} = do
|
ppPatternPrefixApp PatternPrefixApp {..} = do
|
||||||
patPrefixConstructor' <- ppSName patPrefixConstructor
|
patPrefixConstructor' <- ppSName patPrefixConstructor
|
||||||
patPrefixParameter' <- goAtom patPrefixParameter
|
patPrefixParameter' <- goAtom patPrefixParameter
|
||||||
return $ patPrefixConstructor' <+> patPrefixParameter'
|
return $ patPrefixConstructor' <+> patPrefixParameter'
|
||||||
|
|
||||||
ppPatternPostfixApp :: PatternPostfixApp -> Sem r (Doc Ann)
|
ppPatternPostfixApp :: PatternPostfixApp -> Sem r (Doc Ann)
|
||||||
ppPatternPostfixApp PatternPostfixApp {..} = do
|
ppPatternPostfixApp PatternPostfixApp {..} = do
|
||||||
patPostfixConstructor' <- ppSName patPostfixConstructor
|
patPostfixConstructor' <- ppSName patPostfixConstructor
|
||||||
patPostfixParameter' <- goAtom patPostfixParameter
|
patPostfixParameter' <- goAtom patPostfixParameter
|
||||||
return $ patPostfixConstructor' <+> patPostfixParameter'
|
return $ patPostfixConstructor' <+> patPostfixParameter'
|
||||||
|
|
||||||
ppExpressionAtom :: forall r. Members '[Reader Options] r => Expression -> Sem r (Doc Ann)
|
ppExpressionAtom :: forall r. Members '[Reader Options] r => Expression -> Sem r (Doc Ann)
|
||||||
ppExpressionAtom e = do
|
ppExpressionAtom e = do
|
||||||
e' <- ppExpression e
|
e' <- ppExpression e
|
||||||
return $ if isAtomic e then e' else parens e'
|
return $ if isAtomic e then e' else parens e'
|
||||||
|
|
||||||
isAtomic :: Expression -> Bool
|
isAtomic :: Expression -> Bool
|
||||||
isAtomic e = case e of
|
isAtomic e = case e of
|
||||||
@ -464,27 +470,26 @@ ppPostfixApplication PostfixApplication {..} = do
|
|||||||
postfixAppOperator' <- ppSName postfixAppOperator
|
postfixAppOperator' <- ppSName postfixAppOperator
|
||||||
return $ postfixAppParameter' <+> postfixAppOperator'
|
return $ postfixAppParameter' <+> postfixAppOperator'
|
||||||
|
|
||||||
|
|
||||||
ppExpression :: forall r. Members '[Reader Options] r => Expression -> Sem r (Doc Ann)
|
ppExpression :: forall r. Members '[Reader Options] r => Expression -> Sem r (Doc Ann)
|
||||||
ppExpression = go
|
ppExpression = go
|
||||||
where
|
where
|
||||||
ppApplication :: Application -> Sem r (Doc Ann)
|
ppApplication :: Application -> Sem r (Doc Ann)
|
||||||
ppApplication (Application l r) = do
|
ppApplication (Application l r) = do
|
||||||
l' <- goAtom l
|
l' <- goAtom l
|
||||||
r' <- goAtom r
|
r' <- goAtom r
|
||||||
return $ l' <+> r'
|
return $ l' <+> r'
|
||||||
goAtom :: Expression -> Sem r (Doc Ann)
|
goAtom :: Expression -> Sem r (Doc Ann)
|
||||||
goAtom e = do
|
goAtom e = do
|
||||||
e' <- go e
|
e' <- go e
|
||||||
return $ if isAtomic e then e' else parens e'
|
return $ if isAtomic e then e' else parens e'
|
||||||
go :: Expression -> Sem r (Doc Ann)
|
go :: Expression -> Sem r (Doc Ann)
|
||||||
go e = case e of
|
go e = case e of
|
||||||
ExpressionIdentifier n -> ppSName n
|
ExpressionIdentifier n -> ppSName n
|
||||||
ExpressionApplication a -> ppApplication a
|
ExpressionApplication a -> ppApplication a
|
||||||
ExpressionInfixApplication a -> ppInfixApplication a
|
ExpressionInfixApplication a -> ppInfixApplication a
|
||||||
ExpressionPostfixApplication a -> ppPostfixApplication a
|
ExpressionPostfixApplication a -> ppPostfixApplication a
|
||||||
ExpressionLambda l -> ppLambda l
|
ExpressionLambda l -> ppLambda l
|
||||||
ExpressionMatch m -> ppMatch m
|
ExpressionMatch m -> ppMatch m
|
||||||
ExpressionLetBlock lb -> ppLetBlock lb
|
ExpressionLetBlock lb -> ppLetBlock lb
|
||||||
ExpressionUniverse u -> ppUniverse u
|
ExpressionUniverse u -> ppUniverse u
|
||||||
ExpressionFunction f -> ppFunction f
|
ExpressionFunction f -> ppFunction f
|
||||||
|
@ -1030,13 +1030,13 @@ parseTerm :: forall r. Members '[Reader (Parse Expression), Embed Parse] r => Se
|
|||||||
parseTerm = do
|
parseTerm = do
|
||||||
pExpr <- ask
|
pExpr <- ask
|
||||||
embed @Parse $
|
embed @Parse $
|
||||||
parseUniverse
|
parseUniverse
|
||||||
<|> parseNoInfixIdentifier
|
<|> parseNoInfixIdentifier
|
||||||
<|> parseParens pExpr
|
<|> parseParens pExpr
|
||||||
<|> parseFunction
|
<|> parseFunction
|
||||||
<|> parseLambda
|
<|> parseLambda
|
||||||
<|> parseMatch
|
<|> parseMatch
|
||||||
<|> parseLetBlock
|
<|> parseLetBlock
|
||||||
where
|
where
|
||||||
parseLambda :: Parse Expression
|
parseLambda :: Parse Expression
|
||||||
parseLambda = ExpressionLambda <$> P.token lambda mempty
|
parseLambda = ExpressionLambda <$> P.token lambda mempty
|
||||||
@ -1124,7 +1124,7 @@ makePatternTable = do
|
|||||||
nameToPattern n@S.Name' {..} = case _nameKind of
|
nameToPattern n@S.Name' {..} = case _nameKind of
|
||||||
S.KNameConstructor -> PatternConstructor n
|
S.KNameConstructor -> PatternConstructor n
|
||||||
S.KNameLocal
|
S.KNameLocal
|
||||||
| NameUnqualified s <- _nameConcrete -> PatternVariable S.Name' {S._nameConcrete = s, ..}
|
| NameUnqualified s <- _nameConcrete -> PatternVariable S.Name' {S._nameConcrete = s, ..}
|
||||||
_ -> error "impossible"
|
_ -> error "impossible"
|
||||||
getEntry :: SymbolInfo -> SymbolEntry
|
getEntry :: SymbolInfo -> SymbolEntry
|
||||||
getEntry (SymbolInfo m) = case toList m of
|
getEntry (SymbolInfo m) = case toList m of
|
||||||
@ -1185,11 +1185,11 @@ parsePrePatTerm ::
|
|||||||
parsePrePatTerm = do
|
parsePrePatTerm = do
|
||||||
pPat <- ask
|
pPat <- ask
|
||||||
embed @ParsePat $
|
embed @ParsePat $
|
||||||
parseNoInfixConstructor
|
parseNoInfixConstructor
|
||||||
<|> parseVariable
|
<|> parseVariable
|
||||||
<|> parseParens pPat
|
<|> parseParens pPat
|
||||||
<|> parseWildcard
|
<|> parseWildcard
|
||||||
<|> parseEmpty
|
<|> parseEmpty
|
||||||
where
|
where
|
||||||
parseNoInfixConstructor :: ParsePat Pattern
|
parseNoInfixConstructor :: ParsePat Pattern
|
||||||
parseNoInfixConstructor =
|
parseNoInfixConstructor =
|
||||||
|
Loading…
Reference in New Issue
Block a user