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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Union tag docs now can be in parentheses #154

Merged
merged 1 commit into from Jul 22, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions examples/shapes.nrm
Expand Up @@ -23,16 +23,20 @@ record point (
# Record type definition.

offset left/x,
# for backward compatibility, you can specify *behind name*.
# For backward compatibility, you can specify *behind name*.

offset top,
# trailing comma is okay
# Trailing comma is okay.
);

union shape
# Type constructors in a sum type become translated to subtypes in OO
# languages, and datatypes in functional languages.
= rectangle (point upper-left, point lower-right)
= rectangle (
# Each tag can have zero or more fields like record types.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃憤

point upper-left,
point lower-right
)
| circle (point origin, offset radius)
;

Expand Down
15 changes: 11 additions & 4 deletions src/Nirum/Parser.hs
Expand Up @@ -419,6 +419,11 @@ tag = do
tagName <- name <?> "union tag name"
spaces
paren <- optional $ char '('
spaces
frontDocs <- optional $ do
d <- docs <?> "union tag docs"
spaces
return d
fields' <- case paren of
Just _ -> do
spaces
Expand All @@ -428,10 +433,12 @@ tag = do
return f
Nothing -> return empty
spaces
docs' <- optional $ do
d <- docs <?> "union tag docs"
spaces
return d
docs' <- case frontDocs of
d@(Just _) -> return d
Nothing -> optional $ do
d <- docs <?> "union tag docs"
spaces
return d
annotationSet'' <- annotationsWithDocs annotationSet' docs'
return $ Tag tagName fields' annotationSet''

Expand Down
11 changes: 9 additions & 2 deletions test/Nirum/ParserSpec.hs
Expand Up @@ -717,14 +717,21 @@ union shape
union shape
= circle (point origin, offset radius,)
# tag docs
| rectangle (point upper-left, point lower-right,)
| rectangle (
# front docs
point upper-left, point lower-right,
)
| none
;|] `shouldBeRight`
a { type' = union'
{ tags = [ circleTag
{ tagAnnotations = singleDocs "tag docs"
}
, rectTag, noneTag
, rectTag
{ tagAnnotations =
singleDocs "front docs"
}
, noneTag
]
}
}
Expand Down