Giter Site home page Giter Site logo

sh-parser's Introduction

Parser of POSIX Shell Command Language

Build Status

Status: in early phase of development

License

This project is licensed under MIT License. For the full text of the license, see the LICENSE file.

sh-parser's People

Contributors

jirutka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

tst2005 qiyeboy

sh-parser's Issues

shell comment lost

Hello,
I'm playing with LPeg and lot of things around.

I started to test your sh-parser that seems really cool.

I see shell's comment is not managed like the rest of the body

My shell sample is

# comment 1
FOO=foo
# comment 2
BAR=bar

The parsed result is

t = {
   ["body"] = {
      [1] = {
         ["type"] = "SimpleCommand",
         ["prefix"] = {
            [1] = {
               ["type"] = "Assignment",
               ["value"] = {
                  ["type"] = "Word",
                  ["content"] = {
                     [1] = "foo",
                  },
               },
               ["name"] = {
                  ["type"] = "Name",
                  ["text"] = "FOO",
               },
            },
         },
      },
      [2] = {
         ["type"] = "SimpleCommand",
         ["prefix"] = {
            [1] = {
               ["type"] = "Assignment",
               ["value"] = {
                  ["type"] = "Word",
                  ["content"] = {
                     [1] = "bar",
                  },
               },
               ["name"] = {
                  ["type"] = "Name",
                  ["text"] = "BAR",
               },
            },
         },
      },
      ["__comment"] = {
         ["type"] = "Comment",
         ["text"] = " comment 2",
      },
   },
   ["type"] = "Program",
}
  • Is it wanted ?
  • why not processing comment like any other shell command ?

I would like to get something like :

t = {
   ["body"] = {
      [1] = {type= "SimpleCommand", ...},
      [2] = {type= "Comment", ...},
      [3] = {type= "SimpleCommand", ...},
      [4] = {type= "Comment", ...},
   },
   ["type"] = "Program",
}

AST format

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,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.