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

Allow optional pipe before the first constructor for inductive type declarations #1699

Merged
merged 1 commit into from
Jan 5, 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
4 changes: 1 addition & 3 deletions src/Juvix/Compiler/Concrete/Pretty/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,7 @@ instance SingI s => PrettyCode (InductiveDef s) where
ppConstructorBlock ::
NonEmpty (InductiveConstructorDef s) -> Sem r (Doc Ann)
ppConstructorBlock cs =
do
concatWith (\x y -> x <> softline <> kwPipe <+> y)
<$> mapM ppCode (toList cs)
vsep <$> mapM (fmap (kwPipe <+>) . ppCode) (toList cs)

dotted :: Foldable f => f (Doc Ann) -> Doc Ann
dotted = concatWith (surround kwDot)
Expand Down
4 changes: 3 additions & 1 deletion src/Juvix/Compiler/Concrete/Translation/FromSource.hs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,9 @@ inductiveDef _inductiveBuiltin = do
P.<?> "<type annotation e.g. ': Type'>"
kw kwAssign P.<?> "<assignment symbol ':='>"
_inductiveConstructors <-
P.sepBy1 constructorDef (kw kwPipe) P.<?> "<constructor definition>"
optional (kw kwPipe)
>> P.sepBy1 constructorDef (kw kwPipe)
P.<?> "<constructor definition>"
return InductiveDef {..}

inductiveParam :: Members '[InfoTableBuilder, JudocStash, NameIdGen] r => ParsecS r (InductiveParameter 'Parsed)
Expand Down
4 changes: 4 additions & 0 deletions test/Scope/Positive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ tests =
"Inductive"
$(mkRelDir ".")
$(mkRelFile "Inductive.juvix"),
PosTest
"Pipes symbol as possible prefix for each data constructor"
$(mkRelDir ".")
$(mkRelFile "InductivePipes.juvix"),
PosTest
"Imports and qualified names"
$(mkRelDir "Imports")
Expand Down
9 changes: 9 additions & 0 deletions tests/positive/InductivePipes.juvix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module InductivePipes;

type T := | t : T;
type T2 :=
| t1 : T2
| t2 : T2
| t3 : T2;

end ;