Code coverage report for sc/lang/compiler/parser/series-expr.js

Statements: 100% (40 / 40)      Branches: 100% (14 / 14)      Functions: 100% (7 / 7)      Lines: 100% (40 / 40)      Ignored: none     

All files » sc/lang/compiler/parser/ » series-expr.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 811     1   1 1 1   1 39     1 39   1   1 39   39   39   38 15 15     38       38 38   38           34   34 3   31   30         1 38 13       25     1 35 10 10   25     1 34 34 23   11      
(function(sc) {
  "use strict";
 
  require("./parser");
 
  var Token = sc.lang.compiler.Token;
  var Node = sc.lang.compiler.Node;
  var Parser = sc.lang.compiler.Parser;
 
  Parser.addParseMethod("SeriesExpression", function() {
    return new SeriesExpressionParser(this).parse();
  });
 
  function SeriesExpressionParser(parent) {
    Parser.call(this, parent);
  }
  sc.libs.extend(SeriesExpressionParser, Parser);
 
  SeriesExpressionParser.prototype.parse = function() {
    var generator = false;
 
    var marker = this.createMarker();
 
    this.expect("(");
 
    if (this.match(":")) {
      this.lex();
      generator = true;
    }
 
    var method = this.createMarker().apply(
      Node.createIdentifier(generator ? "seriesIter" : "series")
    );
 
    var innerElements = this.state.innerElements;
    this.state.innerElements = true;
 
    var items = [
      this.parseFirstElement(),
      this.parseSecondElement(),
      this.parseLastElement()
    ];
 
    this.state.innerElements = innerElements;
 
    if (!generator && items[2] === null) {
      this.throwUnexpected(this.lookahead);
    }
    this.expect(")");
 
    return marker.update().apply(
      Node.createCallExpression(items.shift(), method, { list: items }, "(")
    );
  };
 
  SeriesExpressionParser.prototype.parseFirstElement = function() {
    if (this.match("..")) {
      return this.createMarker().apply(
        Node.createLiteral({ type: Token.IntegerLiteral, value: "0" })
      );
    }
    return this.parseExpressions();
  };
 
  SeriesExpressionParser.prototype.parseSecondElement = function() {
    if (this.match(",")) {
      this.lex();
      return this.parseExpressions();
    }
    return null;
  };
 
  SeriesExpressionParser.prototype.parseLastElement = function() {
    this.expect("..");
    if (!this.match(")")) {
      return this.parseExpressions();
    }
    return null;
  };
})(sc);