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

Proposal of a parser (tokenizer) #2

Closed
wants to merge 2 commits into from
Closed

Proposal of a parser (tokenizer) #2

wants to merge 2 commits into from

Conversation

pythonbrad
Copy link
Member

Base structure

  • The command line will be parsed and a list of linked token will be generated.
  • Each command will be represented in a token.

Token

  • read: The stdin will be the output of the command given
  • cmd: The command name
  • params: The parameters of the command,
  • status: The status of the execution of the command
  • success: The next command to execute in case of success
  • failure: The next command to execute in case of failure
  • next: The next command to execute whatever the execution status

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,
    },
]

@pythonbrad pythonbrad mentioned this pull request Nov 5, 2022
@pythonbrad pythonbrad marked this pull request as ready for review November 5, 2022 19:54
@pythonbrad pythonbrad marked this pull request as draft November 5, 2022 19:58
@RMPR
Copy link
Collaborator

RMPR commented Nov 6, 2022

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

@pythonbrad
Copy link
Member Author

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
Copy link
Collaborator

RMPR commented Nov 11, 2022

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

@pythonbrad
Copy link
Member Author

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

It's not json.

@pythonbrad
Copy link
Member Author

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

@pythonbrad pythonbrad closed this by deleting the head repository Oct 2, 2023
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.

2 participants