Permalink
Browse files

Union tag docs now can be in parentheses

Fix #153
  • Loading branch information...
dahlia committed Jul 22, 2017
1 parent c59b7ff commit a23e5c2241b2b247fa896aa13515b401bc0cade6
Showing with 27 additions and 9 deletions.
  1. +7 −3 examples/shapes.nrm
  2. +11 −4 src/Nirum/Parser.hs
  3. +9 −2 test/Nirum/ParserSpec.hs
View
@@ -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.
point upper-left,
point lower-right
)
| circle (point origin, offset radius)
;
View
@@ -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
@@ -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''
View
@@ -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
]
}
}

0 comments on commit a23e5c2

Please sign in to comment.