Skip to content

shell comment lost #1

@tst2005

Description

@tst2005

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions