I-Language-Development / I-language-rust

The I programming language is a high level programming language written in rust.
https://i-language-rust.readthedocs.io/en/latest/
MIT License
11 stars 2 forks source link

[FEATURE] Add grammar, translations and better parser #43

Closed ElBe-Plaq closed 1 year ago

ElBe-Plaq commented 1 year ago

Describe the solution you'd like Add pest grammar.

Describe alternatives you've considered BNF, EBNF or ABNF grammar.

Additional context Pest needs to be added to the dependency list.

This issue is now being used to track other changes as well.

create-issue-branch[bot] commented 1 year ago

Branch issue-43 created!

ElBe-Plaq commented 1 year ago

After rewriting the identifier rule, development can continue

ElBe-Plaq commented 1 year ago

Currently doing filtering stuff, just to give you an update,

ElBe-Plaq commented 1 year ago

I will take a look at https://learning-rust.github.io/docs/custom-error-types/ for the error rewrite.

ElBe-Plaq commented 1 year ago

I have decided not to use the pest provided pairs, but to make my own token struct and convert the pest types.

ElBe-Plaq commented 1 year ago

When running the parser with the input var x=1\n the output is

[
    Token {
        token_type: Mark(
            Assignment,
        ),
        content: "var x=1",
        inner: Some(
            [
                Token {
                    token_type: Mark(
                        Variable,
                    ),
                    content: "var",
                    inner: None,
                    position: Position {
                        line: 1,
                        colon: 1,
                    },
                },
                Token {
                    token_type: Identifier,
                    content: "x",
                    inner: None,
                    position: Position {
                        line: 1,
                        colon: 5,
                    },
                },
                Token {
                    token_type: TypeDefinition(
                        Integer,
                    ),
                    content: "1",
                    inner: Some(
                        [
                            Token {
                                token_type: TypeDefinition(
                                    IntegerSign,
                                ),
                                content: "",
                                inner: None,
                                position: Position {
                                    line: 1,
                                    colon: 7,
                                },
                            },
                            Token {
                                token_type: TypeDefinition(
                                    Integer,
                                ),
                                content: "1",
                                inner: None,
                                position: Position {
                                    line: 1,
                                    colon: 7,
                                },
                            },
                        ],
                    ),
                    position: Position {
                        line: 1,
                        colon: 7,
                    },
                },
            ],
        ),
        position: Position {
            line: 1,
            colon: 1,
        },
    },
]
ElBe-Plaq commented 1 year ago

This issue is now being used for multiple improvements, such as working on the parser or adding translations.

ElBe-Plaq commented 1 year ago

I will add a pratt parser and more grammar in the future.