~jojo/Carth

0ca6854f36d83bfe5c58e75b48afa968edb7c662 — JoJo 2 years ago 3438b5b
Disallow arbitrary constructors of reserved names like "Fun"

Also increase number of tests
2 files changed, 4 insertions(+), 2 deletions(-)

M src/Ast.hs
M test/ParseSpec.hs
M src/Ast.hs => src/Ast.hs +3 -1
@@ 188,7 188,9 @@ instance Arbitrary Id where
            else pure (Id id)

arbitraryConstructor :: Gen String
arbitraryConstructor = liftM2 (:) (choose ('A', 'Z')) arbitraryRestIdent
arbitraryConstructor = do
    c <- liftM2 (:) (choose ('A', 'Z')) arbitraryRestIdent
    if elem c reserveds then arbitraryConstructor else pure c

arbitraryRestIdent :: Gen String
arbitraryRestIdent = choose (0, 8) >>= flip vectorOf c

M test/ParseSpec.hs => test/ParseSpec.hs +1 -1
@@ 16,5 16,5 @@ spec = do
        $ it
              "Parsing a pretty printed program should return the original program"
        $ withMaxSuccess
              5e4
              4e5
              (\progAst -> parse "spec" (pretty progAst) == Right progAst)