aiken-lang / aiken

A modern smart contract platform for Cardano
https://aiken-lang.org
Apache License 2.0
461 stars 89 forks source link

UPLC parser does not support ProtoList, ProtoPair, PlutusData #34

Closed nielstron closed 1 year ago

nielstron commented 2 years ago

The uplc parser packaged with aiken does not support parsing ProtoList/ProtoPair/PlutusData constants. The official paper outlining UPLC does not mention these options, but they are being used i.e. when compiling pluto down to uplc as i.e. in this example pluto program:

(\s -> data [1, 2])

I am willing to work on this and will propose a PR that implements one way to specify respective constants in UPLC code. If there is some formalization of a UPLC syntax, this should be added into it.

nielstron commented 2 years ago

It appears that the PlutusCore parser supports parsing ProtoList and ProtoPair, so I will focus on constructing them, in a similar syntax as suggested there.

https://github.com/input-output-hk/plutus/blob/master/plutus-core/plutus-core/src/PlutusCore/Parser/Builtin.hs

nielstron commented 2 years ago

Since it is a bit ill-documented what is actually parsed by uplc and what not here some examples of valid uplc programs with lists and pairs:

Evaluated with github.com:input-output-hk/plutus.git@891f5f08e79c9b70de97cec4b72582c66f3503d7

$ cabal run uplc convert -- -i test.uplc --of flat -o test.flat

(program 1.0.0 (con (list integer) [1, 2]))
(program 1.0.0 (con (list (list integer)) [[1], [2]]))
(program 1.0.0 (con (pair (list integer) bytestring) ([1], #01)))