@drewsonne/maya-calculator-parser
Version:
Typescript package to parse plaintext calculations and create operators
66 lines • 3.48 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var base_1 = require("../base");
var space_token_1 = __importDefault(require("../layer-0/space-token"));
var word_token_1 = __importDefault(require("../layer-0/word-token"));
var number_token_1 = __importDefault(require("../layer-0/number-token"));
var wildcard_token_1 = __importDefault(require("../layer-0/wildcard-token"));
var calendar_round_1 = require("@drewsonne/maya-dates/lib/cr/calendar-round");
var tzolkin_1 = require("@drewsonne/maya-dates/lib/cr/tzolkin");
var haab_1 = require("@drewsonne/maya-dates/lib/cr/haab");
var coefficient_1 = require("@drewsonne/maya-dates/lib/cr/component/coefficient");
var tzolkinDay_1 = require("@drewsonne/maya-dates/lib/cr/component/tzolkinDay");
var haabMonth_1 = require("@drewsonne/maya-dates/lib/cr/component/haabMonth");
var CalendarRoundToken = (function (_super) {
__extends(CalendarRoundToken, _super);
function CalendarRoundToken() {
return _super !== null && _super.apply(this, arguments) || this;
}
CalendarRoundToken.parse = function (tokens) {
var spaceLess = tokens.filter(function (t) {
return !(t instanceof space_token_1.default) && (t instanceof word_token_1.default || t instanceof number_token_1.default || t instanceof wildcard_token_1.default);
});
return new CalendarRoundToken(spaceLess);
};
CalendarRoundToken.prototype.equal = function (otherToken) {
var _this = this;
if (this.value.length === otherToken.value.length) {
return otherToken.value.every(function (otherSubToken, index) { return otherSubToken.equal(_this.value[index]); }, this);
}
throw new Error("Could not parse: '" + otherToken + "'");
};
CalendarRoundToken.prototype.toString = function () {
return "[" + this.value.map(function (t) { return "" + t; }).join(',') + "]";
};
Object.defineProperty(CalendarRoundToken.prototype, "calendarRound", {
get: function () {
var tzolkin = tzolkin_1.getTzolkin(coefficient_1.coefficientParser(this.value[0].value), tzolkinDay_1.getTzolkinDay(this.value[1].value));
var haab = haab_1.getHaab(coefficient_1.coefficientParser(this.value[2].value), haabMonth_1.getHaabMonth(this.value[3].value));
return calendar_round_1.getCalendarRound(tzolkin, haab);
},
enumerable: false,
configurable: true
});
CalendarRoundToken.prototype.isPartial = function () {
return this.value.some(function (t) { return t instanceof wildcard_token_1.default; });
};
return CalendarRoundToken;
}(base_1.Token));
exports.default = CalendarRoundToken;
//# sourceMappingURL=calendar-round-token.js.map