Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions plutus-core/plutus-core/src/PlutusCore/Parser/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -135,29 +135,29 @@ i.e. parse into @Tree Text@ and do the kind checking afterwards, but given that
to do the kind checking of builtins regardless (even for UPLC), we don't win much by deferring
doing it. -}
defaultUni :: Parser (SomeTypeIn (Kinded DefaultUni))
defaultUni = do
choice $
map
try
[ trailingWhitespace (inParens defaultUniApplication)
, someType @_ @Integer <$ symbol "integer"
, someType @_ @ByteString <$ symbol "bytestring"
, someType @_ @Text <$ symbol "string"
, someType @_ @() <$ symbol "unit"
, someType @_ @Bool <$ symbol "bool"
, someType @_ @[] <$ symbol "list"
, someType @_ @Strict.Vector <$ symbol "array"
, someType @_ @(,) <$ symbol "pair"
, someType @_ @Data <$ symbol "data"
, someType @_ @BLS12_381.G1.Element <$ symbol "bls12_381_G1_element"
, someType @_ @BLS12_381.G2.Element <$ symbol "bls12_381_G2_element"
, someType @_ @BLS12_381.Pairing.MlResult <$ symbol "bls12_381_mlresult"
, someType @_ @Value <$ symbol "value"
, -- We include an explicit failure case here to produce clearer error messages.
-- Without this, using `choice` with `symbol` results in error messages that cover the longest possible SrcSpan,
-- which in this context would be 20 characters spanning the entire "bls12_381_G2_element" token.
fail "Unknown type, expected one of: bool, integer, bytestring, string, unit, list, array, pair, data, value, bls12_381_G1_element, bls12_381_G2_element, bls12_381_mlresult, or a type application in parens"
]
defaultUni =
( choice $
map
try
[ trailingWhitespace (inParens defaultUniApplication)
, someType @_ @Integer <$ symbol "integer"
, someType @_ @ByteString <$ symbol "bytestring"
, someType @_ @Text <$ symbol "string"
, someType @_ @() <$ symbol "unit"
, someType @_ @Bool <$ symbol "bool"
, someType @_ @[] <$ symbol "list"
, someType @_ @Strict.Vector <$ symbol "array"
, someType @_ @(,) <$ symbol "pair"
, someType @_ @Data <$ symbol "data"
, someType @_ @BLS12_381.G1.Element <$ symbol "bls12_381_G1_element"
, someType @_ @BLS12_381.G2.Element <$ symbol "bls12_381_G2_element"
, someType @_ @BLS12_381.Pairing.MlResult <$ symbol "bls12_381_mlresult"
, someType @_ @Value <$ symbol "value"
]
)
<?> "type name (integer, bytestring, string, unit, bool, list, array, pair,\
\ data, value, bls12_381_G1_element, bls12_381_G2_element,\
\ bls12_381_mlresult, or type application)"

tyName :: Parser TyName
tyName = TyName <$> name
44 changes: 22 additions & 22 deletions plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,31 +100,31 @@ term =
]
where
tryAppTerm :: Parser PTerm
tryAppTerm = do
withSpan $ \sp -> do
_ <- try (symbol "[")
t <- appTerm sp
_ <- char ']'
return t
tryAppTerm =
withSpan $ \sp ->
between
(symbol "[" <?> "opening bracket '['")
(char ']' <?> "closing bracket ']'")
(appTerm sp)

tryTermInParens :: Parser PTerm
tryTermInParens =
withSpan $ \sp -> do
_ <- try (symbol "(")
t <-
choice
[ try (symbol "builtin") *> builtinTerm sp
, try (symbol "lam") *> lamTerm sp
, try (symbol "constr") *> constrTerm sp -- "constr" must come before "con"
, try (symbol "con") *> conTerm sp
, try (symbol "delay") *> delayTerm sp
, try (symbol "force") *> forceTerm sp
, try (symbol "error") *> errorTerm sp
, try (symbol "constr") *> constrTerm sp
, try (symbol "case") *> caseTerm sp
]
_ <- char ')'
return t
withSpan $ \sp ->
between
(symbol "(" <?> "opening parenthesis '('")
(char ')' <?> "closing parenthesis ')'")
( choice
[ symbol "builtin" *> builtinTerm sp
, symbol "lam" *> lamTerm sp
, symbol "constr" *> constrTerm sp -- "constr" must come before "con"
, symbol "con" *> conTerm sp
, symbol "delay" *> delayTerm sp
, symbol "force" *> forceTerm sp
, symbol "error" *> errorTerm sp
, symbol "case" *> caseTerm sp
]
<?> "term keyword (builtin, lam, constr, con, delay, force, error, case)"
)

-- | Parser for UPLC programs.
program :: Parser (UPLC.Program PLC.Name PLC.DefaultUni PLC.DefaultFun SrcSpan)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test:1:18:
|
1 | (program 1.1.0 [(var x))
| ^^^^^^^
unexpected "var x))"
expecting term keyword (builtin, lam, constr, con, delay, force, error, case)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test:1:17:
|
1 | (program 1.1.0 (foo x))
| ^^^^^^^
unexpected "foo x))"
expecting term keyword (builtin, lam, constr, con, delay, force, error, case)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test:3:64:
|
3 | (force (builtin mkCons)) (con integer 4) (con (list integer) [true]) ]
| ^
unexpected 't'
expecting '+', '-', ']', or integer
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
test:1:24:
|
1 | (program 1.1.0 (builtin))
| ^
Unknown built-in function '' at test:1:24.
Parsable functions are [ addInteger
, andByteString
, appendByteString
, appendString
, bData
, blake2b_224
, blake2b_256
, bls12_381_G1_add
, bls12_381_G1_compress
, bls12_381_G1_equal
, bls12_381_G1_hashToGroup
, bls12_381_G1_multiScalarMul
, bls12_381_G1_neg
, bls12_381_G1_scalarMul
, bls12_381_G1_uncompress
, bls12_381_G2_add
, bls12_381_G2_compress
, bls12_381_G2_equal
, bls12_381_G2_hashToGroup
, bls12_381_G2_multiScalarMul
, bls12_381_G2_neg
, bls12_381_G2_scalarMul
, bls12_381_G2_uncompress
, bls12_381_finalVerify
, bls12_381_millerLoop
, bls12_381_mulMlResult
, byteStringToInteger
, chooseData
, chooseList
, chooseUnit
, complementByteString
, consByteString
, constrData
, countSetBits
, decodeUtf8
, divideInteger
, dropList
, encodeUtf8
, equalsByteString
, equalsData
, equalsInteger
, equalsString
, expModInteger
, findFirstSetBit
, fstPair
, headList
, iData
, ifThenElse
, indexArray
, indexByteString
, insertCoin
, integerToByteString
, keccak_256
, lengthOfArray
, lengthOfByteString
, lessThanByteString
, lessThanEqualsByteString
, lessThanEqualsInteger
, lessThanInteger
, listData
, listToArray
, lookupCoin
, mapData
, mkCons
, mkNilData
, mkNilPairData
, mkPairData
, modInteger
, multiplyInteger
, nullList
, orByteString
, quotientInteger
, readBit
, remainderInteger
, replicateByte
, ripemd_160
, rotateByteString
, scaleValue
, serialiseData
, sha2_256
, sha3_256
, shiftByteString
, sliceByteString
, sndPair
, subtractInteger
, tailList
, trace
, unBData
, unConstrData
, unIData
, unListData
, unMapData
, unValueData
, unionValue
, valueContains
, valueData
, verifyEcdsaSecp256k1Signature
, verifyEd25519Signature
, verifySchnorrSecp256k1Signature
, writeBits
, xorByteString ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test:1:69:
|
1 | (program 1.1.0 [(builtin addInteger) (con integer 1) (con integer 2))
| ^
unexpected ')'
expecting '`', closing bracket ']', opening bracket '[', or opening parenthesis '('
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test:1:24:
|
1 | (program 1.1.0 (lam x (var x))
| ^^^^^^^
unexpected "var x))"
expecting term keyword (builtin, lam, constr, con, delay, force, error, case)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test:1:20:
|
1 | (program 1.1.0 (con))
| ^^
unexpected "))"
expecting type name (integer, bytestring, string, unit, bool, list, array, pair, data, value, bls12_381_G1_element, bls12_381_G2_element, bls12_381_mlresult, or type application)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test:2:38:
|
2 | [ (builtin integerToByteString) (con boot True) (con integer 0) (con integer 712372356934756347862573452345342345) ]
| ^^^^^^^^^^^^^^^^^^^^
unexpected "boot True) (con inte"
expecting type name (integer, bytestring, string, unit, bool, list, array, pair, data, value, bls12_381_G1_element, bls12_381_G2_element, bls12_381_mlresult, or type application)
Loading
Loading