aboutsummaryrefslogtreecommitdiff
path: root/node_modules/extglob/lib/parsers.js
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2019-10-06 21:37:45 +0200
committerDimitri Staessens <dimitri@ouroboros.rocks>2019-10-06 21:37:45 +0200
commit3c51c3be85bb0d1bdb87ea0d6632f1c256912f27 (patch)
treec7ccc8279b12c4f7bdbbb4270d617e48f51722e4 /node_modules/extglob/lib/parsers.js
parent412c104bebc507bea9c94fd53b5bdc4b64cbfe31 (diff)
downloadwebsite-3c51c3be85bb0d1bdb87ea0d6632f1c256912f27.tar.gz
website-3c51c3be85bb0d1bdb87ea0d6632f1c256912f27.zip
build: Add some required modules for node
Diffstat (limited to 'node_modules/extglob/lib/parsers.js')
-rw-r--r--node_modules/extglob/lib/parsers.js156
1 files changed, 156 insertions, 0 deletions
diff --git a/node_modules/extglob/lib/parsers.js b/node_modules/extglob/lib/parsers.js
new file mode 100644
index 0000000..2ba7352
--- /dev/null
+++ b/node_modules/extglob/lib/parsers.js
@@ -0,0 +1,156 @@
+'use strict';
+
+var brackets = require('expand-brackets');
+var define = require('define-property');
+var utils = require('./utils');
+
+/**
+ * Characters to use in text regex (we want to "not" match
+ * characters that are matched by other parsers)
+ */
+
+var TEXT_REGEX = '([!@*?+]?\\(|\\)|[*?.+\\\\]|\\[:?(?=.*\\])|:?\\])+';
+var not = utils.createRegex(TEXT_REGEX);
+
+/**
+ * Extglob parsers
+ */
+
+function parsers(extglob) {
+ extglob.state = extglob.state || {};
+
+ /**
+ * Use `expand-brackets` parsers
+ */
+
+ extglob.use(brackets.parsers);
+ extglob.parser.sets.paren = extglob.parser.sets.paren || [];
+ extglob.parser
+
+ /**
+ * Extglob open: "*("
+ */
+
+ .capture('paren.open', function() {
+ var parsed = this.parsed;
+ var pos = this.position();
+ var m = this.match(/^([!@*?+])?\(/);
+ if (!m) return;
+
+ var prev = this.prev();
+ var prefix = m[1];
+ var val = m[0];
+
+ var open = pos({
+ type: 'paren.open',
+ parsed: parsed,
+ val: val
+ });
+
+ var node = pos({
+ type: 'paren',
+ prefix: prefix,
+ nodes: [open]
+ });
+
+ // if nested negation extglobs, just cancel them out to simplify
+ if (prefix === '!' && prev.type === 'paren' && prev.prefix === '!') {
+ prev.prefix = '@';
+ node.prefix = '@';
+ }
+
+ define(node, 'rest', this.input);
+ define(node, 'parsed', parsed);
+ define(node, 'parent', prev);
+ define(open, 'parent', node);
+
+ this.push('paren', node);
+ prev.nodes.push(node);
+ })
+
+ /**
+ * Extglob close: ")"
+ */
+
+ .capture('paren.close', function() {
+ var parsed = this.parsed;
+ var pos = this.position();
+ var m = this.match(/^\)/);
+ if (!m) return;
+
+ var parent = this.pop('paren');
+ var node = pos({
+ type: 'paren.close',
+ rest: this.input,
+ parsed: parsed,
+ val: m[0]
+ });
+
+ if (!this.isType(parent, 'paren')) {
+ if (this.options.strict) {
+ throw new Error('missing opening paren: "("');
+ }
+ node.escaped = true;
+ return node;
+ }
+
+ node.prefix = parent.prefix;
+ parent.nodes.push(node);
+ define(node, 'parent', parent);
+ })
+
+ /**
+ * Escape: "\\."
+ */
+
+ .capture('escape', function() {
+ var pos = this.position();
+ var m = this.match(/^\\(.)/);
+ if (!m) return;
+
+ return pos({
+ type: 'escape',
+ val: m[0],
+ ch: m[1]
+ });
+ })
+
+ /**
+ * Question marks: "?"
+ */
+
+ .capture('qmark', function() {
+ var parsed = this.parsed;
+ var pos = this.position();
+ var m = this.match(/^\?+(?!\()/);
+ if (!m) return;
+ extglob.state.metachar = true;
+ return pos({
+ type: 'qmark',
+ rest: this.input,
+ parsed: parsed,
+ val: m[0]
+ });
+ })
+
+ /**
+ * Character parsers
+ */
+
+ .capture('star', /^\*(?!\()/)
+ .capture('plus', /^\+(?!\()/)
+ .capture('dot', /^\./)
+ .capture('text', not);
+};
+
+/**
+ * Expose text regex string
+ */
+
+module.exports.TEXT_REGEX = TEXT_REGEX;
+
+/**
+ * Extglob parsers
+ */
+
+module.exports = parsers;