Plato on Github
Report Home
lang/compiler/parser/parentheses.js
Maintainability
131.53
Lines of code
109
Difficulty
17.47
Estimated Errors
0.66
Function weight
By Complexity
By SLOC
(function(sc) { "use strict"; require("./parser"); var Token = sc.lang.compiler.Token; var Parser = sc.lang.compiler.Parser; /* (...) EventExpression SeriesExpression BlockExpression ( Expressions ) ( Expression ) */ Parser.addParseMethod("Parentheses", function() { return new ParenthesesParser(this).parse(); }); function ParenthesesParser(parent) { Parser.call(this, parent); } sc.libs.extend(ParenthesesParser, Parser); ParenthesesParser.prototype.parse = function() { var token = this.expect("("); if (this.match(":")) { this.lex(); } var delegate = this.selectParenthesesParseMethod(); this.unlex(token); return delegate.call(this); }; ParenthesesParser.prototype.selectParenthesesParseMethod = function() { if (this.lookahead.type === Token.Label || this.match(")")) { return function() { return this.parseEventExpression(); }; } if (this.match("var")) { return function() { return this.parseBlockExpression(); }; } if (this.match("..")) { return function() { return this.parseSeriesExpression(); }; } this.parseExpression(); if (this.matchAny([ ",", ".." ])) { return function() { return this.parseSeriesExpression(); }; } if (this.match(":")) { return function() { return this.parseEventExpression(); }; } if (this.match(";")) { this.lex(); this.parseExpressions(); if (this.matchAny([ ",", ".." ])) { return function() { return this.parseSeriesExpression(); }; } return function() { return this.parseExpressionsWithParentheses(); }; } return function() { return this.parsePartialExpressionWithParentheses(); }; }; ParenthesesParser.prototype.parseExpressionsWithParentheses = function() { return this.parseWithParentheses(function() { return this.parseExpressions(); }); }; ParenthesesParser.prototype.parsePartialExpressionWithParentheses = function() { return this.parseWithParentheses(function() { return this.parsePartialExpression(); }); }; ParenthesesParser.prototype.parseWithParentheses = function(delegate) { this.expect("("); var marker = this.createMarker(); var expr = delegate.call(this); expr = marker.update().apply(expr); this.expect(")"); return expr; }; })(sc);