1
1
mirror of https://github.com/anoma/juvix.git synced 2025-01-05 22:46:08 +03:00

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

This commit is contained in:
Jonathan Cubides 2023-01-05 11:28:54 +01:00 committed by GitHub
parent 8ef970d3fd
commit d48e3bd16a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 4 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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")

View File

@ -0,0 +1,9 @@
module InductivePipes;
type T := | t : T;
type T2 :=
| t1 : T2
| t2 : T2
| t3 : T2;
end ;