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

Remove --no-format option #2121

Merged
merged 2 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions app/Commands/Dev/Scope/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ parseScope = do
instance CanonicalProjection (GlobalOptions, ScopeOptions) Scoper.Options where
project (g, _) =
Scoper.defaultOptions
{ Scoper._optShowNameIds = g ^. globalShowNameIds,
Scoper._optNoApe = g ^. globalNoApe
{ Scoper._optShowNameIds = g ^. globalShowNameIds
}
10 changes: 1 addition & 9 deletions app/GlobalOptions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ data GlobalOptions = GlobalOptions
_globalShowNameIds :: Bool,
_globalBuildDir :: Maybe (AppPath Dir),
_globalOnlyErrors :: Bool,
_globalNoApe :: Bool,
_globalStdin :: Bool,
_globalNoTermination :: Bool,
_globalNoPositivity :: Bool,
Expand All @@ -42,8 +41,7 @@ instance CanonicalProjection GlobalOptions Abstract.Options where
instance CanonicalProjection GlobalOptions E.GenericOptions where
project GlobalOptions {..} =
E.GenericOptions
{ E._showNameIds = _globalShowNameIds,
E._genericNoApe = _globalNoApe
{ E._showNameIds = _globalShowNameIds
}

instance CanonicalProjection GlobalOptions Core.CoreOptions where
Expand All @@ -61,7 +59,6 @@ defaultGlobalOptions =
{ _globalNoColors = False,
_globalShowNameIds = False,
_globalOnlyErrors = False,
_globalNoApe = False,
_globalNoTermination = False,
_globalBuildDir = Nothing,
_globalStdin = False,
Expand Down Expand Up @@ -92,11 +89,6 @@ parseGlobalFlags = do
<> help "Directory for compiler internal output"
)
)
_globalNoApe <-
switch
( long "no-format"
<> help "Disable the new pretty printing algorithm"
)
_globalStdin <-
switch
( long "stdin"
Expand Down
65 changes: 16 additions & 49 deletions src/Juvix/Compiler/Concrete/Pretty/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ module Juvix.Compiler.Concrete.Pretty.Base
where

import Data.List.NonEmpty.Extra qualified as NonEmpty
import Juvix.Compiler.Concrete.Data.ScopedName (AbsModulePath, IsConcrete (..))
import Juvix.Compiler.Concrete.Data.ScopedName
( AbsModulePath,
IsConcrete (..),
)
import Juvix.Compiler.Concrete.Data.ScopedName qualified as S
import Juvix.Compiler.Concrete.Extra (unfoldApplication)
import Juvix.Compiler.Concrete.Keywords (delimJudocStart)
import Juvix.Compiler.Concrete.Language
import Juvix.Compiler.Concrete.Pretty.Options
import Juvix.Data.Ape
import Juvix.Data.CodeAnn
import Juvix.Extra.Strings qualified as Str
import Juvix.Prelude
import Juvix.Prelude.Pretty qualified as PP

doc :: (PrettyCode c) => Options -> c -> Doc Ann
doc opts =
Expand Down Expand Up @@ -495,7 +496,7 @@ instance (SingI s) => PrettyCode (TypeSignature s) where
instance (SingI s) => PrettyCode (Function s) where
ppCode a = case sing :: SStage s of
SParsed -> ppCode' a
SScoped -> apeHelper a (ppCode' a)
SScoped -> apeHelper a
where
ppCode' :: forall r. (Members '[Reader Options] r) => Function s -> Sem r (Doc Ann)
ppCode' Function {..} = do
Expand Down Expand Up @@ -629,10 +630,7 @@ instance PrettyCode PatternArg where
return $ (n' <&> (<> kwAt)) ?<> delimIf i (isJust n && not (isAtomic p)) p'

instance PrettyCode PatternApp where
ppCode p@(PatternApp l r) = apeHelper p $ do
l' <- ppLeftExpression appFixity l
r' <- ppRightExpression appFixity r
return $ l' <+> r'
ppCode = apeHelper

ppPatternParensType :: forall s r. (SingI s, Member (Reader Options) r) => PatternParensType s -> Sem r (Doc Ann)
ppPatternParensType p = case sing :: SStage s of
Expand Down Expand Up @@ -678,27 +676,13 @@ instance PrettyCode Text where
ppCode = return . pretty

instance PrettyCode InfixApplication where
ppCode i@InfixApplication {..} =
apeHelper i $ do
infixAppLeft' <- ppLeftExpression (getFixity i) _infixAppLeft
infixAppOperator' <- ppCode _infixAppOperator
infixAppRight' <- ppRightExpression (getFixity i) _infixAppRight
return $ infixAppLeft' <+> infixAppOperator' <+> infixAppRight'
ppCode = apeHelper

instance PrettyCode PostfixApplication where
ppCode i@PostfixApplication {..} =
apeHelper i $ do
postfixAppParameter' <- ppPostExpression (getFixity i) _postfixAppParameter
postfixAppOperator' <- ppCode _postfixAppOperator
return $ postfixAppParameter' <+> postfixAppOperator'
ppCode = apeHelper

instance PrettyCode Application where
ppCode a =
apeHelper a $ do
let (f, args) = unfoldApplication a
f' <- ppCode f
args' <- mapM ppCodeAtom args
return $ PP.group (f' <+> nest' (vsep args'))
ppCode = apeHelper

instance PrettyCode ApeLeaf where
ppCode = \case
Expand All @@ -708,16 +692,12 @@ instance PrettyCode ApeLeaf where
ApeLeafPattern r -> ppCode r
ApeLeafPatternArg r -> ppCode r

apeHelper :: (IsApe a ApeLeaf, Members '[Reader Options] r) => a -> Sem r (Doc CodeAnn) -> Sem r (Doc CodeAnn)
apeHelper a alt = do
apeHelper :: (IsApe a ApeLeaf, Members '[Reader Options] r) => a -> Sem r (Doc CodeAnn)
apeHelper a = do
opts <- ask @Options
if
| not (opts ^. optNoApe) ->
return $
let params :: ApeParams ApeLeaf
params = ApeParams (run . runReader opts . ppCode)
in runApe params a
| otherwise -> alt
let params :: ApeParams ApeLeaf
params = ApeParams (run . runReader opts . ppCode)
return $ runApe params a

instance PrettyCode Literal where
ppCode = \case
Expand Down Expand Up @@ -774,21 +754,8 @@ instance PrettyCode Pattern where
PatternWildcard {} -> return kwWildcard
PatternEmpty {} -> return $ parens mempty
PatternConstructor constr -> ppCode constr
PatternInfixApplication i -> ppPatternInfixApp i
PatternPostfixApplication i -> ppPatternPostfixApp i
where
ppPatternInfixApp :: PatternInfixApp -> Sem r (Doc Ann)
ppPatternInfixApp p@PatternInfixApp {..} = apeHelper p $ do
patInfixConstructor' <- ppCode _patInfixConstructor
patInfixLeft' <- ppLeftExpression (getFixity p) _patInfixLeft
patInfixRight' <- ppRightExpression (getFixity p) _patInfixRight
return $ patInfixLeft' <+> patInfixConstructor' <+> patInfixRight'

ppPatternPostfixApp :: PatternPostfixApp -> Sem r (Doc Ann)
ppPatternPostfixApp p@PatternPostfixApp {..} = apeHelper p $ do
patPostfixConstructor' <- ppCode _patPostfixConstructor
patPostfixParameter' <- ppLeftExpression (getFixity p) _patPostfixParameter
return $ patPostfixParameter' <+> patPostfixConstructor'
PatternInfixApplication i -> apeHelper i
PatternPostfixApplication i -> apeHelper i

ppPostExpression ::
(PrettyCode a, HasAtomicity a, Member (Reader Options) r) =>
Expand Down
8 changes: 1 addition & 7 deletions src/Juvix/Compiler/Concrete/Pretty/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,21 @@ import Juvix.Prelude

data Options = Options
{ _optShowNameIds :: Bool,
_optNoApe :: Bool,
_optInJudocBlock :: Bool
}

defaultOptions :: Options
defaultOptions =
Options
{ _optShowNameIds = False,
_optNoApe = False,
_optInJudocBlock = False
}

makeLenses ''Options

fromGenericOptions :: GenericOptions -> Options
fromGenericOptions GenericOptions {..} =
set optShowNameIds _showNameIds $
set
optNoApe
_genericNoApe
defaultOptions
set optShowNameIds _showNameIds defaultOptions

inJudocBlock :: Members '[Reader Options] r => Sem r a -> Sem r a
inJudocBlock = local (set optInJudocBlock True)
6 changes: 2 additions & 4 deletions src/Juvix/Data/Error/GenericError.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ data GenericError = GenericError
}

data GenericOptions = GenericOptions
{ _showNameIds :: Bool,
_genericNoApe :: Bool
{ _showNameIds :: Bool
}
deriving stock (Eq, Show)

Expand All @@ -28,8 +27,7 @@ makeLenses ''GenericOptions
defaultGenericOptions :: GenericOptions
defaultGenericOptions =
GenericOptions
{ _showNameIds = False,
_genericNoApe = False
{ _showNameIds = False
}

instance Pretty GenericError where
Expand Down
66 changes: 32 additions & 34 deletions tests/smoke/Commands/dev/geb.smoke.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ tests:
command:
- juvix
- --no-colors
- dev
- dev
- geb
- repl
stdout:
contains: "Welcome to the Juvix Geb REPL!"
contains: 'Welcome to the Juvix Geb REPL!'
exit-status: 0

jonaprieto marked this conversation as resolved.
Show resolved Hide resolved
- name: geb-quit
command:
- juvix
- --no-colors
- dev
- dev
- geb
- repl
stdout:
contains: "geb>"
stdin: ":quit"
stdout:
contains: 'geb>'
stdin: ':quit'
exit-status: 0

- name: geb-infer-type-unit
Expand All @@ -31,80 +31,78 @@ tests:
- dev
- geb
- repl
stdin: ":type unit"
stdin: ':type unit'
stdout:
contains: "so1"
contains: 'so1'
exit-status: 0

- name: geb-infer-type-object
command:
- juvix
- --no-colors
- --no-colors
- dev
- geb
- repl
stdin: ":type so1"
stdout:
contains: "Inference only works on Geb morphisms"
stdin: ':type so1'
stdout:
contains: 'Inference only works on Geb morphisms'
exit-status: 0

- name: geb-infer-type-integer
command:
- juvix
- --no-colors
- --no-colors
- dev
- geb
- repl
stdin: ":t (mul 2 3)"
stdout:
contains: "int"
exit-status: 0
stdin: ':t (mul 2 3)'
stdout:
contains: 'int'
exit-status: 0

# - name: geb-check-int
# command:
# - juvix
# - --no-colors
# - --no-colors
# - dev
# - geb
# - repl
# stdin: ":check (typed (add 1 2) so1)"
# stderr:
# stderr:
# contains: "so1 is not a valid object for (add 1 2)"
# exit-status: 1

- name: geb-eval-and-operations
command:
- juvix
- --no-format
- dev
- geb
- repl
stdin: "(add 2 (mul 3 4))"
stdout:
stdin: '(add 2 (mul 3 4))'
stdout:
contains: |
14
exit-status: 0
exit-status: 0

- name: geb-eval-with-spaces
command:
- juvix
- dev
- geb
- repl
stdin: " unit"
stdout:
contains:
"unit"
exit-status:
stdin: ' unit'
stdout:
contains: 'unit'
exit-status:

- name: geb-load-and-eval-gebext
command:
shell:
- bash
script: |
cd ./Geb/positive/ && juvix dev geb repl
stdin: ":load basic-app.geb"
stdout:
stdin: ':load basic-app.geb'
stdout:
contains: |
3000
exit-status: 0
Expand All @@ -116,13 +114,13 @@ tests:
- dev
- geb
- repl
stdin: ":root"
stdout:
stdin: ':root'
stdout:
matches: |
Welcome .*
Juvix .*
Type .*

geb> .*/tests/
exit-status: 0

Expand Down