miking-lang / miking

Miking - the meta viking: a meta-language system for creating embedded languages
Other
51 stars 30 forks source link

Call for Feedback: Updated MLang Syntax #837

Open marten-voorberg opened 2 months ago

marten-voorberg commented 2 months ago

As part of my master thesis, I am planning to make some (minor) alterations and additions to the MLang syntax with two goals:

  1. Add support for product extension
  2. Make the distinction of a syntax or semantic extension vs. a base declaration clearer

We have been using the term Product Extension as a catch-all term for functionality in which we are able to add new fields to existing constructors. Our canonical examples are adding a ty or info field to an existing language. I have been using the term fine-grained product extension to talk about the ability of specifying the fields to add for a single, specific constructor and the term coarse-grained product extension to describe adding fields to all constructors of a syntax. I also suggest introducing a nominal aspect into the product extension syntax by giving each product extension a name. The most important reason for this is that this name can be used in an eventual type system extension to more concisely represent types.

The following program demonstrates my proposed syntax.

lang A = 
    -- Syntax declaration
    syn S = 
    -- Semantic declaration
    sem f =
ed
lang B = A
    -- Sum Extension
    -- We add two constructors 'Foo' and 'Bar' to S
    syn S += 
    | Foo {}
    | Bar {x: Int}
    -- Semantic extension
    -- We add two additional cases to 'f'
    sem f += 
    | Foo _ -> 10
    | Bar {x = x} -> x
end
lang C = A + B
    -- Product Extension
    -- We add a field 'y' to each constructor in S
    -- And add a field 'z' to Foo specifically
    syn S as MyProdExt *= {y : Int}
    | Foo with {z : String}
end
marten-voorberg commented 2 months ago

The base definition should not include an = symbol if no constructors or cases are defined.