Add UPLC support for 'ProtoList' & 'ProtoPair' constants

Supersedes #35.

  The syntax for these elements isn't "set in stone"; in the sense that it is unspecified in [input-output-hk/plutus](https://github.com/input-output-hk/plutus). There's no visible plan from IOG to extend the Haskell parser to support this syntax, though there are samples of imagined syntax in the code. Thus, we can lead the way and simply choose a suitable syntax and let the Haskell implementation align to it later.

  This syntax is thus inspired from input-output-hk/plutus' samples, with only a small change: we use `<` and `>` for encapsulating type declaration instead of `(`, `)`. There are already enough parentheses in the UPLC syntax, adding more reduces visibility.

  Doing this, I've also added a lot more test cases for the UPLC parser. There could be more, but this is a good start.

  Here are some example programs (taken from test cases) utilizing this syntax:

  ```
  (program 0.0.0 (con list<bytestring> [#00, #01]))
  ```

  ```
  (program 0.0.0
      (con pair
        <integer, integer>
        [14, 42]
      )
  )
  ```

  ```
  (program 0.0.0
      (con pair<string, list<integer>> ["foo", [14, 42]])
  )
  ```

  _(Note that this was mainly done as an exercise to get more familiar with Rust and parts of Aiken.)_
This commit is contained in:
KtorZ
2022-11-24 09:54:00 +01:00
committed by Lucas
parent 5ec93a8692
commit 375499930a
4 changed files with 705 additions and 70 deletions

View File

@@ -14,8 +14,6 @@
| `equalsInteger` | \- | (integer, integer) | bool |
| `lessThanInteger` | \- | (integer, integer) | bool |
| `lessThanEqualsInteger` | \- | (integer, integer) | bool |
| `greaterThanInteger` | \- | (integer, integer) | bool |
| `greaterThanEqualsInteger` | \- | (integer, integer) | bool |
| --- | --- | --- | --- |
| `appendString` | \- | (string, string) | string |
| `emptyString` | \- | (string) | bool |
@@ -24,15 +22,12 @@
| --- | --- | --- | --- |
| `appendByteString` | \- | (bytestring, bytestring) | bytestring |
| `consByteString` | \- | (integer, bytestring) | bytestring |
| `indexByteString` | \- | (integer, bytestring) | integer |
| `indexByteString` | \- | (bytestring, integer) | integer |
| `sliceByteString` | \- | (integer, integer, bytestring) | bytestring |
| `lengthOfByteString` | \- | (bytestring) | integer |
| `emptyByteString` | \- | (bytestring) | bool |
| `equalsByteString` | \- | (bytestring, bytestring) | bool |
| `lessThanByteString` | \- | (bytestring, bytestring) | bool |
| `lessThanEqualsByteString` | \- | (bytestring, bytestring) | bool |
| `greaterThanByteString` | \- | (bytestring, bytestring) | bool |
| `greaterThanEqualsByteString` | \- | (bytestring, bytestring) | bool |
| `decodeUtf8` | \- | (bytestring) | string |
| --- | --- | --- | --- |
| `chooseData`[^2] | \\(α\\) | (data, \\(α\\), \\(α\\), \\(α\\), \\(α\\), \\(α\\)) | \\(α\\) |

View File

@@ -4,22 +4,26 @@ Let's start with a little reminder about the syntax. The complete syntax for Unt
## Primitive Types
Plutus Core has 5 primitive types: `unit`, `bool`, `integer`, `string` and
`bytestring`. One can construct constants using the `con` keyword, followed by
the name of the primitive type and its value.
Plutus Core has 7 primitive types (a.k.a. constants): `unit`, `bool`, `integer`, `bytestring`, `string`, `pair` and `list`.
One can construct constants using the `con` keyword, followed by the name of the primitive type and its value.
- Unit is denoted `()`;
- Bool are `True` or `False`;
- Bytestrings are denoted with a leading `#` followed by an hexadecimal sequence;
- Strings are UTF-8 text strings, between double quotes `"`.
- Strings are UTF-8 text strings, between double quotes `"` `"`;
- Pair and lists are encapsulated between brackets `[` and `]`.
| Primitive Type | Example |
| --- | --- |
| `unit` | `con unit ()` |
| `bool` | `con bool True` |
| `integer` | `con integer 42` |
| `bytestring` | `con bytestring #41696b656e` |
| `string` | `con string "Aiken"` |
Note that each constant is named after its type. For pairs and lists -- which are compound types --, the type of their elements is specified between chevrons `<` and `>`.
| Primitive Type | Example |
| --- | --- |
| `unit` | `con unit ()` |
| `bool` | `con bool True` |
| `integer` | `con integer 42` |
| `bytestring` | `con bytestring #41696b656e` |
| `string` | `con string "Aiken"` |
| `pair` | `con pair<bool, integer> [True, 42]` |
| `list` | `con list<bytestring> [#00, #aa]` |
## Functions