osscameroon / sh-rs

A rust shell example
2 stars 0 forks source link

Proposal of a parser (tokenizer) #2

Closed pythonbrad closed 1 year ago

pythonbrad commented 2 years ago

Base structure

Token

Input

~/OSSCameroon/sh-rs> echo PNG Search Script; echo Search started && echo Searching... & ls | sort | head -2 | grep .png$ > result.txt || echo Not Found; echo Search End;

Output

[
    Token {
        cmd: Some(
            "echo",
        ),
        params: [
            "PNG",
            "Search",
            "Script",
        ],
        status: None,
        on_read: None,
        on_success: None,
        on_failure: None,
        next: None,
        stdin: None,
        stdout: None,
    },
    Token {
        cmd: Some(
            "echo",
        ),
        params: [
            "Not",
            "Found",
        ],
        status: None,
        on_read: None,
        on_success: None,
        on_failure: Some(
            Token {
                cmd: Some(
                    "grep",
                ),
                params: [
                    ".png$",
                ],
                status: None,
                on_read: Some(
                    Token {
                        cmd: Some(
                            "head",
                        ),
                        params: [
                            "-2",
                        ],
                        status: None,
                        on_read: Some(
                            Token {
                                cmd: Some(
                                    "sort",
                                ),
                                params: [],
                                status: None,
                                on_read: Some(
                                    Token {
                                        cmd: Some(
                                            "ls",
                                        ),
                                        params: [],
                                        status: None,
                                        on_read: None,
                                        on_success: None,
                                        on_failure: None,
                                        next: Some(
                                            Token {
                                                cmd: Some(
                                                    "echo",
                                                ),
                                                params: [
                                                    "Searching...",
                                                ],
                                                status: None,
                                                on_read: None,
                                                on_success: Some(
                                                    Token {
                                                        cmd: Some(
                                                            "echo",
                                                        ),
                                                        params: [
                                                            "Search",
                                                            "started",
                                                        ],
                                                        status: None,
                                                        on_read: None,
                                                        on_success: None,
                                                        on_failure: None,
                                                        next: None,
                                                        stdin: None,
                                                        stdout: None,
                                                    },
                                                ),
                                                on_failure: None,
                                                next: None,
                                                stdin: None,
                                                stdout: None,
                                            },
                                        ),
                                        stdin: None,
                                        stdout: None,
                                    },
                                ),
                                on_success: None,
                                on_failure: None,
                                next: None,
                                stdin: None,
                                stdout: None,
                            },
                        ),
                        on_success: None,
                        on_failure: None,
                        next: None,
                        stdin: None,
                        stdout: None,
                    },
                ),
                on_success: None,
                on_failure: None,
                next: None,
                stdin: Some(
                    "result.txt",
                ),
                stdout: None,
            },
        ),
        next: None,
        stdin: None,
        stdout: None,
    },
    Token {
        cmd: Some(
            "echo",
        ),
        params: [
            "Search",
            "End",
        ],
        status: None,
        on_read: None,
        on_success: None,
        on_failure: None,
        next: None,
        stdin: None,
        stdout: None,
    },
    Token {
        cmd: None,
        params: [],
        status: None,
        on_read: None,
        on_success: None,
        on_failure: None,
        next: None,
        stdin: None,
        stdout: None,
    },
]
RMPR commented 2 years ago

Hey, thanks for the PR. Really nice effort, the first question I want to wrt to this design is why JSON?

pythonbrad commented 2 years ago

Hey, thanks for the PR. Really nice effort, the first question I want to wrt to this design is why JSON?

i don't understand what you means by wrt.

RMPR commented 2 years ago

Sorry, I am wondering why you chose JSON to represent the AST.

pythonbrad commented 2 years ago

Sorry, I am wondering why you chose JSON to represent the AST.

It's not json.

pythonbrad commented 2 years ago

I will done some research to have a better understanding of a parser.