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

initial ast and parser structure skeleton #50

Merged
merged 13 commits into from
Jan 5, 2024
Merged

Conversation

edg-l
Copy link
Member

@edg-l edg-l commented Jan 4, 2024

The ast was inspired from our austral port.

The parser in this pr is just enough to parse the factorial program at the bottom.

Current test produces the following output:

Program:

mod ModuleName {
    const MY_CONSTANT: u8 = 2;
    const MY_CONSTANT2: bool = true;
    const MY_CONSTANT3: string = "hello world!";
}

Ast:

[crates/concrete_parser/src/lib.rs:26] ast = [
    ModuleBase {
        doc_string: None,
        imports: [],
        name: Ident {
            name: "ModuleName",
            span: Span {
                from: 5,
                to: 15,
            },
        },
        contents: [
            Constant(
                ConstantDef {
                    decl: ConstantDecl {
                        doc_string: None,
                        name: Ident {
                            name: "MY_CONSTANT",
                            span: Span {
                                from: 28,
                                to: 39,
                            },
                        },
                        type: Simple {
                            name: Ident {
                                name: "u8",
                                span: Span {
                                    from: 41,
                                    to: 43,
                                },
                            },
                        },
                    },
                    value: Atomic(
                        ConstInt(
                            2,
                        ),
                    ),
                },
            ),
            Constant(
                ConstantDef {
                    decl: ConstantDecl {
                        doc_string: None,
                        name: Ident {
                            name: "MY_CONSTANT2",
                            span: Span {
                                from: 59,
                                to: 71,
                            },
                        },
                        type: Simple {
                            name: Ident {
                                name: "bool",
                                span: Span {
                                    from: 73,
                                    to: 77,
                                },
                            },
                        },
                    },
                    value: Atomic(
                        ConstBool(
                            true,
                        ),
                    ),
                },
            ),
            Constant(
                ConstantDef {
                    decl: ConstantDecl {
                        doc_string: None,
                        name: Ident {
                            name: "MY_CONSTANT3",
                            span: Span {
                                from: 96,
                                to: 108,
                            },
                        },
                        type: Simple {
                            name: Ident {
                                name: "string",
                                span: Span {
                                    from: 110,
                                    to: 116,
                                },
                            },
                        },
                    },
                    value: Atomic(
                        ConstStr(
                            "\"hello world!\"",
                        ),
                    ),
                },
            ),
        ],
    },
]

factorial:

mod FactorialModule {
    pub fn factorial(x: u64) -> u64  {
        return match x {
            0 -> return 1,
            n -> return n * factorial(n-1),
        };
    }
}

https://gist.github.com/edg-l/068898bb319fdb324beca30b08c7caf4

@codecov-commenter
Copy link

Welcome to Codecov 🎉

Once merged to your default branch, Codecov will compare your coverage reports and display the results in this comment.

Thanks for integrating Codecov - We've got you covered ☂️

@edg-l edg-l changed the title initial ast structure skeleton initial ast structure skeleton + tokens Jan 5, 2024
@edg-l edg-l changed the title initial ast structure skeleton + tokens initial ast and parser structure skeleton Jan 5, 2024
@edg-l edg-l marked this pull request as ready for review January 5, 2024 11:44
@edg-l edg-l linked an issue Jan 5, 2024 that may be closed by this pull request
4 tasks
Copy link
Collaborator

@juanbono juanbono left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Cargo.toml Show resolved Hide resolved
pub enum Expression {
Match(MatchExpr),
Operation(Operation),
// Block(Vec<Statement>),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be commented

@unbalancedparentheses unbalancedparentheses merged commit 694d1bc into main Jan 5, 2024
4 checks passed
@unbalancedparentheses
Copy link
Member

@igaray mentioned a few things were off, let's fix it in the next pr.

@edg-l edg-l deleted the ast_edgl branch May 8, 2024 10:07
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

Successfully merging this pull request may close these issues.

Initial skeleton
5 participants