3 var extglob = require('extglob');
4 var nanomatch = require('nanomatch');
5 var regexNot = require('regex-not');
6 var toRegex = require('to-regex');
10 * Characters to use in negation regex (we want to "not" match
11 * characters that are matched by other parsers)
14 var TEXT = '([!@*?+]?\\(|\\)|\\[:?(?=.*?:?\\])|:?\\]|[*+?!^$.\\\\/])+';
15 var createNotRegex = function(opts) {
16 return not || (not = textRegex(TEXT));
23 module.exports = function(snapdragon) {
24 var parsers = snapdragon.parser.parsers;
26 // register nanomatch parsers
27 snapdragon.use(nanomatch.parsers);
29 // get references to some specific nanomatch parsers before they
30 // are overridden by the extglob and/or parsers
31 var escape = parsers.escape;
32 var slash = parsers.slash;
33 var qmark = parsers.qmark;
34 var plus = parsers.plus;
35 var star = parsers.star;
36 var dot = parsers.dot;
38 // register extglob parsers
39 snapdragon.use(extglob.parsers);
41 // custom micromatch parsers
44 // override "notRegex" created in nanomatch parser
45 this.notRegex = /^\!+(?!\()/;
47 // reset the referenced parsers
48 .capture('escape', escape)
49 .capture('slash', slash)
50 .capture('qmark', qmark)
51 .capture('star', star)
52 .capture('plus', plus)
56 * Override `text` parser
59 .capture('text', function() {
60 if (this.isInside('bracket')) return;
61 var pos = this.position();
62 var m = this.match(createNotRegex(this.options));
63 if (!m || !m[0]) return;
65 // escape regex boundary characters and simple brackets
66 var val = m[0].replace(/([[\]^$])/g, '\\$1');
79 function textRegex(pattern) {
80 var notStr = regexNot.create(pattern, {contains: true, strictClose: false});
81 var prefix = '(?:[\\^]|\\\\|';
82 return toRegex(prefix + notStr + ')', {strictClose: false});