Code coverage report for sc/lang/compiler/parser/list-indexer.js

Statements: 100% (41 / 41)      Branches: 100% (14 / 14)      Functions: 100% (8 / 8)      Lines: 100% (41 / 41)      Ignored: none     

All files » sc/lang/compiler/parser/ » list-indexer.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 891     1   1   1 68     1 68   1   1 68   67 67   11 11     56     64   63     1 56   53 8   8     45 12   12       33     1   11 4       7     1   8 4       4     1 12 10   10 6     4       2      
(function(sc) {
  "use strict";
 
  require("./parser");
 
  var Parser = sc.lang.compiler.Parser;
 
  Parser.addParseMethod("ListIndexer", function() {
    return new ListIndexerParser(this).parse();
  });
 
  function ListIndexerParser(parent) {
    Parser.call(this, parent);
  }
  sc.libs.extend(ListIndexerParser, Parser);
 
  ListIndexerParser.prototype.parse = function() {
    this.expect("[");
 
    var items;
    if (this.match("..")) {
      // [.. ???
      this.lex();
      items = this.parseListIndexerWithoutFirst();
    } else {
      // [first ???
      items = this.parseListIndexerWithFirst();
    }
 
    this.expect("]");
 
    return items;
  };
 
  ListIndexerParser.prototype.parseListIndexerWithFirst = function() {
    var first = this.parseExpressions();
 
    if (this.match("..")) {
      this.lex();
      // [first.. ???
      return this.parseListIndexerWithFirstWithoutSecond(first);
    }
 
    if (this.match(",")) {
      this.lex();
      // [first, second ???
      return this.parseListIndexerWithFirstAndSecond(first, this.parseExpressions());
    }
 
    // [first]
    return [ first ];
  };
 
  ListIndexerParser.prototype.parseListIndexerWithoutFirst = function() {
    // [..last]
    if (!this.match("]")) {
      return [ null, null, this.parseExpressions() ];
    }
 
    // [..]
    return [ null, null, null ];
  };
 
  ListIndexerParser.prototype.parseListIndexerWithFirstWithoutSecond = function(first) {
    // [first..last]
    if (!this.match("]")) {
      return [ first, null, this.parseExpressions() ];
    }
 
    // [first..]
    return [ first, null, null ];
  };
 
  ListIndexerParser.prototype.parseListIndexerWithFirstAndSecond = function(first, second) {
    if (this.match("..")) {
      this.lex();
      // [first, second..last]
      if (!this.match("]")) {
        return [ first, second, this.parseExpressions() ];
      }
      // [first, second..]
      return [ first, second, null ];
    }
 
    // [first, second] (the second is ignored)
    return [ first ];
  };
})(sc);