Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Tracked by #7923
magnus-madsen opened this issue Jun 21, 2024 · 5 comments
Open
Tracked by #7923
Assignees

Comments

@magnus-madsen
Copy link
Member

magnus-madsen commented Jun 21, 2024

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 magnus-madsen changed the title Add support for structs to the lexer, parser, and weeder Structs: Add support for structs to the lexer, parser, and weeder Jun 21, 2024
@magnus-madsen magnus-madsen changed the title Structs: Add support for structs to the lexer, parser, and weeder Structs: Add support for structs to the Lexer, Parser, and Weeder Jun 21, 2024
@magnus-madsen
Copy link
Member Author

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

@magnus-madsen
Copy link
Member Author

@dghosef I added some more examples to the ticket.

@dghosef
Copy link
Contributor

dghosef commented Jun 21, 2024

@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

@magnus-madsen
Copy link
Member Author

@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
Copy link
Member Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants