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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Changed

- In #7391 made the parser accept constants with extra parens in them, e.g. `(con (list data) [(I 0), (B #1234)])`.
4 changes: 2 additions & 2 deletions plutus-core/plutus-core/src/PlutusCore/Parser/Builtin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Data.Text qualified as T
import Data.Text.Internal.Read (hexDigitToInt)
import Data.Vector.Strict (Vector)
import Data.Vector.Strict qualified as Vector
import Text.Megaparsec (customFailure, getSourcePos, takeWhileP)
import Text.Megaparsec (customFailure, getSourcePos, takeWhileP, try)
import Text.Megaparsec.Char (char, hexDigitChar, string)
import Text.Megaparsec.Char.Lexer qualified as Lex

Expand Down Expand Up @@ -145,7 +145,7 @@ conBLS12_381_G2_Element = do
-- | Parser for constants of the given type.
constantOf :: ExpectParens -> DefaultUni (Esc a) -> Parser a
constantOf expectParens uni =
Copy link
Member

Choose a reason for hiding this comment

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

I think the expectParens parameter is useless now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, we still can't allow (con data I 42), it has to be (con data (I 42)).
While (con (list data) [I 42]) is fine.
So the distinction still exists.

case uni of
try (trailingWhitespace . inParens $ constantOf ExpectParensNo uni) <|> case uni of
Copy link
Contributor

Choose a reason for hiding this comment

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

This now accepts

(con (list data) [ (((((((((((I 5))))))))))), B #FF ])

and

(con unit (((((((((((((((((((()))))))))))))))))))))

Do we really want that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, the prettyprinter still prints list elements without parentheses. I suppose we have to choose one way or the other, so that seems fine.

DefaultUniInteger -> conInteger
DefaultUniByteString -> conBS
DefaultUniString -> conText
Expand Down
9 changes: 9 additions & 0 deletions plutus-core/plutus-core/test/Parser/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ parseValueValid = do
\, [ ( #6161616161616161616161616161616161616161616161616161616161616161\
\ , -100 ) ] ) ])"

parseDataParens :: Assertion
parseDataParens = do
expectParserSuccess code
where
code = "(con (list data) [(I 0), (B #1234)])"

tests :: TestTree
tests =
testGroup
Expand All @@ -88,4 +94,7 @@ tests =
, testCase
"parser of Value should succeed"
parseValueValid
, testCase
"parser of Data with extra parens should succeed"
parseDataParens
]