Skip to content

Commit

Permalink
parse properties with optional labels
Browse files Browse the repository at this point in the history
See #342.
  • Loading branch information
byorgey committed May 4, 2022
1 parent 5da61f8 commit a5d2d33
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/Disco/AST/Surface.hs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ type Docs = [DocThing]
data DocThing
= DocString [String] -- ^ A documentation string, i.e. a block
-- of @||| text@ items
| DocProperty Property -- ^ An example/doctest/property of the
-- form @!!! forall (x1:ty1) ... . property@
| DocProperty (Maybe String) Property
-- ^ An optionally labelled example/doctest/property of the
-- form @!!![label] property@
deriving instance ForallTerm Show UD => Show DocThing

-- | A property is a universally quantified term of the form
Expand Down
11 changes: 6 additions & 5 deletions src/Disco/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ parseTopLevel = L.nonIndented sc $
parseDocThing :: Parser DocThing
parseDocThing
= DocString <$> some parseDocString
<|> DocProperty <$> parseProperty
<|> parseProperty

-- | Parse one line of documentation beginning with @|||@.
parseDocString :: Parser String
Expand All @@ -511,10 +511,11 @@ parseDocString = label "documentation" $ L.nonIndented sc $

-- | Parse a top-level property/unit test, which is just @!!!@
-- followed by an arbitrary term.
parseProperty :: Parser Term
parseProperty = label "property" $ L.nonIndented sc $ do
_ <- symbol "!!!"
indented parseTerm
parseProperty :: Parser DocThing
parseProperty = label "property" $ L.nonIndented sc $
DocProperty
<$> lexeme (string "!!!" *> optional (char '[' *> some (noneOf "[]") <* char ']'))
<*> indented parseTerm

-- | Parse a single top-level declaration (either a type declaration
-- or single definition clause).
Expand Down
2 changes: 1 addition & 1 deletion src/Disco/Typecheck.hs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ checkProperties docs =
<$> (traverse . traverse) checkProperty properties
where
properties :: Ctx Term [Property]
properties = fmap (\ds -> [p | DocProperty p <- ds]) docs
properties = fmap (\ds -> [p | DocProperty _ p <- ds]) docs -- XXX

-- | Check the types of the terms embedded in a property.
checkProperty
Expand Down

0 comments on commit a5d2d33

Please sign in to comment.