Skip to content

Commit

Permalink
Merge pull request #479 from input-output-hk/plutus-core/fix-name-gen…
Browse files Browse the repository at this point in the history
…eration

Filter out keywords from name generation
  • Loading branch information
michaelpj committed Jan 29, 2019
2 parents a9b7103 + 2e48a7f commit 1c9d628
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
1 change: 0 additions & 1 deletion language-plutus-core/src/Language/PlutusCore/Lexer.x
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ tokens :-
<0> "sha2_256" { mkBuiltin SHA2 }
<0> "sha3_256" { mkBuiltin SHA3 }
<0> verifySignature { mkBuiltin VerifySignature }
<0> equalsByteString { mkBuiltin EqByteString }
<0> txhash { mkBuiltin TxHash }
<0> blocknum { mkBuiltin BlockNum }
<0> sizeOfInteger { mkBuiltin SizeOfInteger }
Expand Down
22 changes: 21 additions & 1 deletion language-plutus-core/test/Generators.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}

module Generators ( genTerm
, genProgram
) where
Expand All @@ -8,6 +10,7 @@ import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Range as Range
import Language.PlutusCore
import Language.PlutusCore.Constant
import Language.PlutusCore.Pretty

genVersion :: MonadGen m => m (Version ())
genVersion = Version () <$> int' <*> int' <*> int'
Expand All @@ -20,7 +23,24 @@ genTyName = TyName <$> genName
genName :: MonadGen m => m (Name ())
genName = Name () <$> name' <*> int'
where int' = Unique <$> Gen.int (Range.linear 0 3000)
name' = Gen.text (Range.linear 1 20) Gen.lower
name' = Gen.filter (\n -> not (isKw n || isBuiltin n)) (Gen.text (Range.linear 1 20) Gen.lower)
isKw "abs" = True
isKw "lam" = True
isKw "ifix" = True
isKw "fun" = True
isKw "all" = True
isKw "bytestring" = True
isKw "integer" = True
isKw "size" = True
isKw "type" = True
isKw "program" = True
isKw "con" = True
isKw "iwrap" = True
isKw "builtin" = True
isKw "unwrap" = True
isKw "error" = True
isKw _ = False
isBuiltin n = n `elem` fmap prettyText allBuiltinNames

simpleRecursive :: MonadGen m => [m a] -> [m a] -> m a
simpleRecursive = Gen.recursive Gen.choice
Expand Down

0 comments on commit 1c9d628

Please sign in to comment.