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

AST format #2

Open
tst2005 opened this issue Jul 5, 2017 · 1 comment
Open

AST format #2

tst2005 opened this issue Jul 5, 2017 · 1 comment

Comments

@tst2005
Copy link

tst2005 commented Jul 5, 2017

Hello,

I wonder if you already know the AST format defined/used by metalua ?

It use a type name into a ["tag"] key, all data are used by numerical indexes.

It is shorter to dump for human debug

The current lua-sh-parser ast format :

{
        type = "Program",
        body = {
                {
                        type = "SimpleCommand",
                        prefix = {
                                {
                                        type = "Assignment",
                                        name = {
                                                type = "Name",
                                                text = "FOO",
                                        },
                                        value = {
                                                type = "Word",
                                                content = {
                                                        "bar",
                                                },
                                        },
                                },
                        },
                },
        },
}

the current format but shown with a metalua style

`Program{
        body=`SimpleCommand{
                prefix=`Assignment{
                        value=`Word{
                                content="bar"
                        },
                        name=`Name{
                                text="FOO"
                        }
                }
        },
}

The same data in metalua AST format

{
        tag = "Program",
        {
                {
                        tag = "SimpleCommand",
                        {
                                {
                                        tag = "Assignment",
                                        {
                                                tag = "Word",
                                                {
                                                        "bar",
                                                },
                                        },
                                        {
                                                tag = "Name",
                                                "FOO",
                                        },
                                },
                        },
                },
        },
}

The metalua usual form for the same sample

`Program{
        `SimpleCommand{
                `Assignment{
                        `Name{
                                "FOO"
                        }
                        `Word{
                                "bar"
                        },
                },
        },
}

What did you think about the metalua AST format ?

I'm working on the step that I want convert back AST to sh then I'm trying to move ast format to a common one ;-)

Regards,

@jirutka
Copy link
Owner

jirutka commented Jul 5, 2017

Yes, I know metalua AST format. It's designed for very different grammar, that is much simpler and saner than sh.

You can very easily get similar representation using sh-parser's low-level API (raw captures). Tag indices are documented in AST.adoc.

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

No branches or pull requests

2 participants