Support multi-clause patterns as syntactic sugar

And disable multi-patterns clauses. I was originally just controlling
  whether we did disable that from the parser but then I figured we
  could actually support multi-patterns clauses quite easily by simply
  desugaring a multi-pattern into multiple clauses.

  This is only a syntactic sugar, which means that the cost of writing
  that on-chain is as expensive as writing the fully expanded form; yet
  it seems like a useful shorthand; especially for short clause
  expressions.

  This commit however disables multi-pattern when clauses, which we do
  not support in the code-generation. Instead, one pattern on tuples for
  that.
This commit is contained in:
KtorZ
2023-03-16 22:42:07 +01:00
committed by Lucas
parent 660ca3fada
commit c113582404
9 changed files with 127 additions and 62 deletions

View File

@@ -0,0 +1,5 @@
# This file was generated by Aiken
# You typically do not need to edit this file
requirements = []
packages = []

View File

@@ -0,0 +1,2 @@
name = "aiken-lang/acceptance_test_078"
version = "0.0.0"

View File

@@ -0,0 +1,45 @@
type DayOfTheWeek {
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
}
fn is_work(day: DayOfTheWeek) {
when day is {
Tuesday | Wednesday | Thursday | Friday | Saturday ->
True
_ ->
False
}
}
test is_work_1() {
is_work(Thursday)
}
test is_work_2() {
!is_work(Monday)
}
fn is_happy_hour(day: DayOfTheWeek, current_time: Int) {
when day is {
Monday | Sunday ->
True
Tuesday | Wednesday | Thursday | Friday | Saturday if current_time > 18 ->
True
_ ->
False
}
}
test is_happy_hour_1() {
is_happy_hour(Sunday, 14)
}
test is_happy_hour_2() {
is_happy_hour(Friday, 22)
}

View File

@@ -0,0 +1,8 @@
{
"preamble": {
"title": "aiken-lang/acceptance_test_078",
"version": "0.0.0",
"plutusVersion": "v2"
},
"validators": []
}