flix icon indicating copy to clipboard operation
flix copied to clipboard

Structs: Add support for structs to the `Lexer`, `Parser`, and `Weeder`

Open magnus-madsen opened this issue 1 year ago • 5 comments

Syntax Example I:

struct Box[r: Region] {
    aBool: Bool
}

Syntax Example II:

struct Person[a: Type, r: Region] {
    fstName: String,
    lstName: String
}

Syntax Example III:

struct Box[a: Type, r: Region] {
    value: a
}

Syntax Example IV:

struct Node[a: Type, r: Region] {
    value: a
    prev: Node[a, r]
    next: Node[a, r]
}

We should discuss the data types in WeededAst. I would propose something like:

case class Struct(doc: Ast.Doc, ann: Ast.Annotations, mod: Ast.Modifiers, ident: Name.Ident, tparams: TypeParams, fields: List[Field], loc: SourceLocation) extends Declaration

case class Field(ident: Name.Ident, tpe: Type, loc: SourceLocation)

magnus-madsen avatar Jun 21 '24 11:06 magnus-madsen

@dghosef I suggest that the first PR should simply be to add a new struct token to the Lexer.

magnus-madsen avatar Jun 21 '24 13:06 magnus-madsen

@dghosef I added some more examples to the ticket.

magnus-madsen avatar Jun 21 '24 13:06 magnus-madsen

@magnus-madsen I run into the problem that now since Weeder technically can return a struct, the desugar pattern matching is incomplete. Is there a way to temporarily silence this error? My current solution is to just throw an exception in the desugar phase upon matching with a struct

@dghosef I suggest that the first PR should simply be to add a new struct token to the Lexer.

Oh sorry I just saw this. Should I revert the other stuff I've done and make a smaller PR? I have put all the stuff I have done in a bigger draft PR here: https://github.com/flix/flix/pull/7927

dghosef avatar Jun 21 '24 14:06 dghosef

@magnus-madsen I run into the problem that now since Weeder technically can return a struct, the desugar pattern matching is incomplete. Is there a way to temporarily silence this error? My current solution is to just throw an exception in the desugar phase upon matching with a struct

@dghosef I suggest that the first PR should simply be to add a new struct token to the Lexer.

Oh sorry I just saw this. Should I revert the other stuff I've done and make a smaller PR? I have put all the stuff I have done in a bigger draft PR here: #7927

I suggest to work one phase at a time, just so everyone can keep up. The lexer PR should be easy 👍

magnus-madsen avatar Jun 21 '24 14:06 magnus-madsen

@magnus-madsen I run into the problem that now since Weeder technically can return a struct, the desugar pattern matching is incomplete. Is there a way to temporarily silence this error? My current solution is to just throw an exception in the desugar phase upon matching with a struct

You have to throw an exception which is OK

magnus-madsen avatar Jun 21 '24 14:06 magnus-madsen

Fixed in master.

magnus-madsen avatar Aug 26 '24 18:08 magnus-madsen