"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/first-mate/lib/scanner.js" (11 Apr 2017, 2667 Bytes) of package /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 OnigScanner, Scanner;
    3 
    4   OnigScanner = require('oniguruma').OnigScanner;
    5 
    6   module.exports = Scanner = (function() {
    7     function Scanner(patterns) {
    8       var pattern, _i, _len, _ref;
    9       this.patterns = patterns != null ? patterns : [];
   10       this.anchored = false;
   11       _ref = this.patterns;
   12       for (_i = 0, _len = _ref.length; _i < _len; _i++) {
   13         pattern = _ref[_i];
   14         if (!pattern.anchored) {
   15           continue;
   16         }
   17         this.anchored = true;
   18         break;
   19       }
   20       this.anchoredScanner = null;
   21       this.firstLineAnchoredScanner = null;
   22       this.firstLineScanner = null;
   23       this.scanner = null;
   24     }
   25 
   26     Scanner.prototype.createScanner = function(firstLine, position, anchorPosition) {
   27       var patterns, scanner;
   28       patterns = this.patterns.map(function(pattern) {
   29         return pattern.getRegex(firstLine, position, anchorPosition);
   30       });
   31       return scanner = new OnigScanner(patterns);
   32     };
   33 
   34     Scanner.prototype.getScanner = function(firstLine, position, anchorPosition) {
   35       if (!this.anchored) {
   36         if (this.scanner == null) {
   37           this.scanner = this.createScanner(firstLine, position, anchorPosition);
   38         }
   39         return this.scanner;
   40       }
   41       if (firstLine) {
   42         if (position === anchorPosition) {
   43           return this.firstLineAnchoredScanner != null ? this.firstLineAnchoredScanner : this.firstLineAnchoredScanner = this.createScanner(firstLine, position, anchorPosition);
   44         } else {
   45           return this.firstLineScanner != null ? this.firstLineScanner : this.firstLineScanner = this.createScanner(firstLine, position, anchorPosition);
   46         }
   47       } else if (position === anchorPosition) {
   48         return this.anchoredScanner != null ? this.anchoredScanner : this.anchoredScanner = this.createScanner(firstLine, position, anchorPosition);
   49       } else {
   50         return this.scanner != null ? this.scanner : this.scanner = this.createScanner(firstLine, position, anchorPosition);
   51       }
   52     };
   53 
   54     Scanner.prototype.findNextMatch = function(line, firstLine, position, anchorPosition) {
   55       var match, scanner;
   56       scanner = this.getScanner(firstLine, position, anchorPosition);
   57       match = scanner.findNextMatchSync(line, position);
   58       if (match != null) {
   59         match.scanner = this;
   60       }
   61       return match;
   62     };
   63 
   64     Scanner.prototype.handleMatch = function(match, stack, line, rule, endPatternMatch) {
   65       var pattern;
   66       pattern = this.patterns[match.index];
   67       return pattern.handleMatch(stack, line, match.captureIndices, rule, endPatternMatch);
   68     };
   69 
   70     return Scanner;
   71 
   72   })();
   73 
   74 }).call(this);