Skip to content

Commit

Permalink
[Refactor] parse: a bit of cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Apr 7, 2023
1 parent 227d474 commit 6780ec5
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
// '<(' is process substitution operator and
// can be parsed the same as control operator
var CONTROL = '(?:' + [
'\\|\\|', '\\&\\&', ';;', '\\|\\&', '\\<\\(', '\\<\\<\\<', '>>', '>\\&', '<\\&', '[&;()|<>]'
'\\|\\|',
'\\&\\&',
';;',
'\\|\\&',
'\\<\\(',
'\\<\\<\\<',
'>>',
'>\\&',
'<\\&',
'[&;()|<>]'
].join('|') + ')';
var controlRE = new RegExp('^' + CONTROL + '$');
var META = '|&;()<> \\t';
Expand Down Expand Up @@ -148,10 +157,11 @@ function parseInternal(s, env, opts) {
return { op: s };
} else if (hash.test(c)) {
commented = true;
var commentObj = { comment: s.slice(i + 1) + match.slice(j + 1).join(' ') };
if (out.length) {
return [out, { comment: s.slice(i + 1) + match.slice(j + 1).join(' ') }];
return [out, commentObj];
}
return [{ comment: s.slice(i + 1) + match.slice(j + 1).join(' ') }];
return [commentObj];
} else if (c === BS) {
esc = true;
} else if (c === DS) {
Expand All @@ -166,7 +176,7 @@ function parseInternal(s, env, opts) {
}

return out;
}).reduce(function (prev, arg) { // finalize parsed aruments
}).reduce(function (prev, arg) { // finalize parsed arguments
return typeof arg === 'undefined' ? prev : prev.concat(arg);
}, []);
}
Expand Down

0 comments on commit 6780ec5

Please sign in to comment.