"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/first-mate/lib/scope-selector-matchers.js" (7 Feb 2017, 8664 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 (function() {
    2   var AndMatcher, CompositeMatcher, GroupMatcher, NegateMatcher, OrMatcher, PathMatcher, ScopeMatcher, SegmentMatcher, TrueMatcher;
    3 
    4   SegmentMatcher = (function() {
    5     function SegmentMatcher(segments) {
    6       this.segment = segments[0].join('') + segments[1].join('');
    7     }
    8 
    9     SegmentMatcher.prototype.matches = function(scope) {
   10       return scope === this.segment;
   11     };
   12 
   13     SegmentMatcher.prototype.getPrefix = function(scope) {};
   14 
   15     SegmentMatcher.prototype.toCssSelector = function() {
   16       return this.segment.split('.').map(function(dotFragment) {
   17         return '.' + dotFragment.replace(/\+/g, '\\+');
   18       }).join('');
   19     };
   20 
   21     SegmentMatcher.prototype.toCssSyntaxSelector = function() {
   22       return this.segment.split('.').map(function(dotFragment) {
   23         return '.syntax--' + dotFragment.replace(/\+/g, '\\+');
   24       }).join('');
   25     };
   26 
   27     return SegmentMatcher;
   28 
   29   })();
   30 
   31   TrueMatcher = (function() {
   32     function TrueMatcher() {}
   33 
   34     TrueMatcher.prototype.matches = function() {
   35       return true;
   36     };
   37 
   38     TrueMatcher.prototype.getPrefix = function(scopes) {};
   39 
   40     TrueMatcher.prototype.toCssSelector = function() {
   41       return '*';
   42     };
   43 
   44     TrueMatcher.prototype.toCssSyntaxSelector = function() {
   45       return '*';
   46     };
   47 
   48     return TrueMatcher;
   49 
   50   })();
   51 
   52   ScopeMatcher = (function() {
   53     function ScopeMatcher(first, others) {
   54       var segment, _i, _len;
   55       this.segments = [first];
   56       for (_i = 0, _len = others.length; _i < _len; _i++) {
   57         segment = others[_i];
   58         this.segments.push(segment[1]);
   59       }
   60     }
   61 
   62     ScopeMatcher.prototype.matches = function(scope) {
   63       var index, scopeSegments, segment, _i, _len, _ref;
   64       scopeSegments = scope.split('.');
   65       if (scopeSegments.length < this.segments.length) {
   66         return false;
   67       }
   68       _ref = this.segments;
   69       for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) {
   70         segment = _ref[index];
   71         if (!segment.matches(scopeSegments[index])) {
   72           return false;
   73         }
   74       }
   75       return true;
   76     };
   77 
   78     ScopeMatcher.prototype.getPrefix = function(scope) {
   79       var index, scopeSegments, segment, _i, _len, _ref;
   80       scopeSegments = scope.split('.');
   81       if (scopeSegments.length < this.segments.length) {
   82         return false;
   83       }
   84       _ref = this.segments;
   85       for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) {
   86         segment = _ref[index];
   87         if (segment.matches(scopeSegments[index])) {
   88           if (segment.prefix != null) {
   89             return segment.prefix;
   90           }
   91         }
   92       }
   93     };
   94 
   95     ScopeMatcher.prototype.toCssSelector = function() {
   96       return this.segments.map(function(matcher) {
   97         return matcher.toCssSelector();
   98       }).join('');
   99     };
  100 
  101     ScopeMatcher.prototype.toCssSyntaxSelector = function() {
  102       return this.segments.map(function(matcher) {
  103         return matcher.toCssSyntaxSelector();
  104       }).join('');
  105     };
  106 
  107     return ScopeMatcher;
  108 
  109   })();
  110 
  111   GroupMatcher = (function() {
  112     function GroupMatcher(prefix, selector) {
  113       this.prefix = prefix != null ? prefix[0] : void 0;
  114       this.selector = selector;
  115     }
  116 
  117     GroupMatcher.prototype.matches = function(scopes) {
  118       return this.selector.matches(scopes);
  119     };
  120 
  121     GroupMatcher.prototype.getPrefix = function(scopes) {
  122       if (this.selector.matches(scopes)) {
  123         return this.prefix;
  124       }
  125     };
  126 
  127     GroupMatcher.prototype.toCssSelector = function() {
  128       return this.selector.toCssSelector();
  129     };
  130 
  131     GroupMatcher.prototype.toCssSyntaxSelector = function() {
  132       return this.selector.toCssSyntaxSelector();
  133     };
  134 
  135     return GroupMatcher;
  136 
  137   })();
  138 
  139   PathMatcher = (function() {
  140     function PathMatcher(prefix, first, others) {
  141       var matcher, _i, _len;
  142       this.prefix = prefix != null ? prefix[0] : void 0;
  143       this.matchers = [first];
  144       for (_i = 0, _len = others.length; _i < _len; _i++) {
  145         matcher = others[_i];
  146         this.matchers.push(matcher[1]);
  147       }
  148     }
  149 
  150     PathMatcher.prototype.matches = function(scopes) {
  151       var index, matcher, scope, _i, _len;
  152       index = 0;
  153       matcher = this.matchers[index];
  154       for (_i = 0, _len = scopes.length; _i < _len; _i++) {
  155         scope = scopes[_i];
  156         if (matcher.matches(scope)) {
  157           matcher = this.matchers[++index];
  158         }
  159         if (matcher == null) {
  160           return true;
  161         }
  162       }
  163       return false;
  164     };
  165 
  166     PathMatcher.prototype.getPrefix = function(scopes) {
  167       if (this.matches(scopes)) {
  168         return this.prefix;
  169       }
  170     };
  171 
  172     PathMatcher.prototype.toCssSelector = function() {
  173       return this.matchers.map(function(matcher) {
  174         return matcher.toCssSelector();
  175       }).join(' ');
  176     };
  177 
  178     PathMatcher.prototype.toCssSyntaxSelector = function() {
  179       return this.matchers.map(function(matcher) {
  180         return matcher.toCssSyntaxSelector();
  181       }).join(' ');
  182     };
  183 
  184     return PathMatcher;
  185 
  186   })();
  187 
  188   OrMatcher = (function() {
  189     function OrMatcher(left, right) {
  190       this.left = left;
  191       this.right = right;
  192     }
  193 
  194     OrMatcher.prototype.matches = function(scopes) {
  195       return this.left.matches(scopes) || this.right.matches(scopes);
  196     };
  197 
  198     OrMatcher.prototype.getPrefix = function(scopes) {
  199       return this.left.getPrefix(scopes) || this.right.getPrefix(scopes);
  200     };
  201 
  202     OrMatcher.prototype.toCssSelector = function() {
  203       return "" + (this.left.toCssSelector()) + ", " + (this.right.toCssSelector());
  204     };
  205 
  206     OrMatcher.prototype.toCssSyntaxSelector = function() {
  207       return "" + (this.left.toCssSyntaxSelector()) + ", " + (this.right.toCssSyntaxSelector());
  208     };
  209 
  210     return OrMatcher;
  211 
  212   })();
  213 
  214   AndMatcher = (function() {
  215     function AndMatcher(left, right) {
  216       this.left = left;
  217       this.right = right;
  218     }
  219 
  220     AndMatcher.prototype.matches = function(scopes) {
  221       return this.left.matches(scopes) && this.right.matches(scopes);
  222     };
  223 
  224     AndMatcher.prototype.getPrefix = function(scopes) {
  225       if (this.left.matches(scopes) && this.right.matches(scopes)) {
  226         return this.left.getPrefix(scopes);
  227       }
  228     };
  229 
  230     AndMatcher.prototype.toCssSelector = function() {
  231       if (this.right instanceof NegateMatcher) {
  232         return "" + (this.left.toCssSelector()) + (this.right.toCssSelector());
  233       } else {
  234         return "" + (this.left.toCssSelector()) + " " + (this.right.toCssSelector());
  235       }
  236     };
  237 
  238     AndMatcher.prototype.toCssSyntaxSelector = function() {
  239       if (this.right instanceof NegateMatcher) {
  240         return "" + (this.left.toCssSyntaxSelector()) + (this.right.toCssSyntaxSelector());
  241       } else {
  242         return "" + (this.left.toCssSyntaxSelector()) + " " + (this.right.toCssSyntaxSelector());
  243       }
  244     };
  245 
  246     return AndMatcher;
  247 
  248   })();
  249 
  250   NegateMatcher = (function() {
  251     function NegateMatcher(matcher) {
  252       this.matcher = matcher;
  253     }
  254 
  255     NegateMatcher.prototype.matches = function(scopes) {
  256       return !this.matcher.matches(scopes);
  257     };
  258 
  259     NegateMatcher.prototype.getPrefix = function(scopes) {};
  260 
  261     NegateMatcher.prototype.toCssSelector = function() {
  262       return ":not(" + (this.matcher.toCssSelector()) + ")";
  263     };
  264 
  265     NegateMatcher.prototype.toCssSyntaxSelector = function() {
  266       return ":not(" + (this.matcher.toCssSyntaxSelector()) + ")";
  267     };
  268 
  269     return NegateMatcher;
  270 
  271   })();
  272 
  273   CompositeMatcher = (function() {
  274     function CompositeMatcher(left, operator, right) {
  275       switch (operator) {
  276         case '|':
  277           this.matcher = new OrMatcher(left, right);
  278           break;
  279         case '&':
  280           this.matcher = new AndMatcher(left, right);
  281           break;
  282         case '-':
  283           this.matcher = new AndMatcher(left, new NegateMatcher(right));
  284       }
  285     }
  286 
  287     CompositeMatcher.prototype.matches = function(scopes) {
  288       return this.matcher.matches(scopes);
  289     };
  290 
  291     CompositeMatcher.prototype.getPrefix = function(scopes) {
  292       return this.matcher.getPrefix(scopes);
  293     };
  294 
  295     CompositeMatcher.prototype.toCssSelector = function() {
  296       return this.matcher.toCssSelector();
  297     };
  298 
  299     CompositeMatcher.prototype.toCssSyntaxSelector = function() {
  300       return this.matcher.toCssSyntaxSelector();
  301     };
  302 
  303     return CompositeMatcher;
  304 
  305   })();
  306 
  307   module.exports = {
  308     AndMatcher: AndMatcher,
  309     CompositeMatcher: CompositeMatcher,
  310     GroupMatcher: GroupMatcher,
  311     NegateMatcher: NegateMatcher,
  312     OrMatcher: OrMatcher,
  313     PathMatcher: PathMatcher,
  314     ScopeMatcher: ScopeMatcher,
  315     SegmentMatcher: SegmentMatcher,
  316     TrueMatcher: TrueMatcher
  317   };
  318 
  319 }).call(this);