mirth-lang / mirth

Compiler for the Mirth programming language.
BSD Zero Clause License
447 stars 14 forks source link

Add new syntax for data, & add struct declarations. #309

Closed typeswitch-dev closed 6 months ago

typeswitch-dev commented 6 months ago

This PR adds syntactic sugar for data declarations. Now we can write them as follows:

data Maybe(t) {
    None
    Some [ t ]
}

Constructors can still be written in the old style, with arrows and commas:

data Maybe(t) {
    None,
    Some -> t,
}

In addition, I added a struct declaration, which is syntactic sugar for a single-constructor data declaration:

struct Person {
    name: Str
    age: Int
}

is equivalent to:

data Person {
    Person [
        name: Str
        age: Int
    ]
}

The rationale behind the new data syntax is to make it look visually distinct from the new def syntax, so that it's easier to not confuse them, which was a problem with the old style.