melt-umn / silver

An attribute grammar-based programming language for composable language extensions
http://melt.cs.umn.edu/silver/
GNU Lesser General Public License v3.0
59 stars 7 forks source link

Shorthand datatype syntax #777

Closed krame505 closed 1 year ago

krame505 commented 1 year ago

For data nonterminals with no attributes, writing productions with empty bodies is a bit verbose. We might want to add an extension that lets one write Haskell-style syntax, e.g.

data Foo<a>
  = foo x::a
  | bar i::Integer q::[a]
  | baz;

which would translate to

data nonterminal Foo<a>;
production foo
top::Foo<a> ::= x::a
{}
production bar
top::Foo<a> ::= i::Integer q::[a]
{}
production baz
top::Foo<a> ::=
{}

Not super urgent and I'm not planning to do this, but I wouldn't object if someone wanted to. Might make a good hackathon intro project.

krame505 commented 1 year ago

Note that we probably also want to support with ... on data declarations, to allow for annotations in defining "records":

annotation x::Integer;
annotation y::Integer;

data Point = point
  with x, y;

global p::Point = point(x=2, y=4);