This project is licensed under MIT License. For the full text of the license, see the LICENSE file.
jirutka / sh-parser Goto Github PK
View Code? Open in Web Editor NEWParser of POSIX Shell Command Language
License: MIT License
Parser of POSIX Shell Command Language
License: MIT License
This project is licensed under MIT License. For the full text of the license, see the LICENSE file.
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",
}
I would like to get something like :
t = {
["body"] = {
[1] = {type= "SimpleCommand", ...},
[2] = {type= "Comment", ...},
[3] = {type= "SimpleCommand", ...},
[4] = {type= "Comment", ...},
},
["type"] = "Program",
}
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,
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.