lambdaclass / concrete

Concrete is a simple programming language specifically crafted for creating highly scalable systems that are reliable, efficient, and easy to maintain.
Apache License 2.0
123 stars 11 forks source link

initial ast and parser structure skeleton #50

Closed edg-l closed 8 months ago

edg-l commented 8 months ago

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 commented 8 months ago

Welcome to Codecov :tada:

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 :open_umbrella:

unbalancedparentheses commented 8 months ago

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