Skip to content

Commit 95f5da3

Browse files
committed
Parse comments. Fixes #8
hat-tip to @piranna for suggesting parsing comments before new lines
1 parent bb53c2d commit 95f5da3

File tree

4 files changed

+628
-468
lines changed

4 files changed

+628
-468
lines changed

grammar.pegjs

+6-5
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ argument "command argument"
6262
= commandName
6363
/ processSubstitution
6464

65-
concatenation
65+
concatenation "concatenation of strings and/or variables"
6666
= pieces:( glob
6767
/ bareword
6868
/ environmentVariable
@@ -72,8 +72,8 @@ concatenation
7272
/ doubleQuote
7373
)+
7474

75-
bareword
76-
= cs:barewordChar+
75+
bareword "bareword"
76+
= !'#' cs:barewordChar+
7777

7878
barewordChar
7979
= '\\' chr:barewordMeta { return chr }
@@ -157,8 +157,9 @@ pipe =
157157
space
158158
= " " / "\t"
159159

160-
spaceNL
161-
= space / "\n"
160+
spaceNL = space / "\n" / comment
161+
162+
comment = '#' [^\n]* ("\n" / EOF)
162163

163164
keyword
164165
= ( "while"

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
"description": "Parse bash scripts into AST's",
55
"main": "parser.js",
66
"dependencies": {
7+
"array-map": "0.0.0",
78
"isarray": "0.0.1",
8-
"array-map": "0.0.0"
9+
"parsimmon": "^0.7.0"
910
},
1011
"scripts": {
1112
"test": "tape tests/*.js",
@@ -34,8 +35,8 @@
3435
}
3536
},
3637
"devDependencies": {
37-
"pegjs": "~0.8.0",
38-
"pegjs-override-action": "0.0.7",
38+
"pegjs": "~0.9.0",
39+
"pegjs-override-action": "0.2.3",
3940
"tape": "^4.5.1",
4041
"markdown-code-blocks": "0.0.1",
4142
"xtend": "~2.1.1"

0 commit comments

Comments
 (0)