Skip to content

Commit

Permalink
using the control ops directly from the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed May 13, 2013
1 parent 8c008b2 commit f535987
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ exports.quote = function (xs) {
}).join(' ');
};

var CONTROL = '(?:\\|\\||\\&\\&|;;|\\|\\&[&;()|])';
var CONTROL = '(?:' + [
'\\|\\|', '\\&\\&', ';;', '\\|\\&', '[&;()|]'
].join('|') + ')';
var META = '[|&;()<> \\t]';

exports.parse = function parse (s, env) {
var chunker = new RegExp([
'([\'"])((\\\\\\1|[^\\1])*?)\\1', // quotes
'(\\\\' + META + '|[^\\s&|])+', // barewords
'([&|])' // control chars
'(' + CONTROL + ')' // control chars
].join('|'), 'g');
var match = s.match(chunker);
if (!match) return [];
Expand Down

0 comments on commit f535987

Please sign in to comment.