123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- "use strict";
- 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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
- return extendStatics(d, b);
- };
- return function (d, b) {
- if (typeof b !== "function" && b !== null)
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- var __read = (this && this.__read) || function (o, n) {
- var m = typeof Symbol === "function" && o[Symbol.iterator];
- if (!m) return o;
- var i = m.call(o), r, ar = [], e;
- try {
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
- }
- catch (error) { e = { error: error }; }
- finally {
- try {
- if (r && !r.done && (m = i["return"])) m.call(i);
- }
- finally { if (e) throw e.error; }
- }
- return ar;
- };
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
- if (ar || !(i in from)) {
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
- ar[i] = from[i];
- }
- }
- return to.concat(ar || Array.prototype.slice.call(from));
- };
- var __values = (this && this.__values) || function(o) {
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
- if (m) return m.call(o);
- if (o && typeof o.length === "number") return {
- next: function () {
- if (o && i >= o.length) o = void 0;
- return { value: o && o[i++], done: !o };
- }
- };
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
- };
- var __importDefault = (this && this.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.BaseItem = exports.MmlStack = void 0;
- var TexError_js_1 = __importDefault(require("./TexError.js"));
- var MmlStack = (function () {
- function MmlStack(_nodes) {
- this._nodes = _nodes;
- }
- Object.defineProperty(MmlStack.prototype, "nodes", {
- get: function () {
- return this._nodes;
- },
- enumerable: false,
- configurable: true
- });
- MmlStack.prototype.Push = function () {
- var _a;
- var nodes = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- nodes[_i] = arguments[_i];
- }
- (_a = this._nodes).push.apply(_a, __spreadArray([], __read(nodes), false));
- };
- MmlStack.prototype.Pop = function () {
- return this._nodes.pop();
- };
- Object.defineProperty(MmlStack.prototype, "First", {
- get: function () {
- return this._nodes[this.Size() - 1];
- },
- set: function (node) {
- this._nodes[this.Size() - 1] = node;
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(MmlStack.prototype, "Last", {
- get: function () {
- return this._nodes[0];
- },
- set: function (node) {
- this._nodes[0] = node;
- },
- enumerable: false,
- configurable: true
- });
- MmlStack.prototype.Peek = function (n) {
- if (n == null) {
- n = 1;
- }
- return this._nodes.slice(this.Size() - n);
- };
- MmlStack.prototype.Size = function () {
- return this._nodes.length;
- };
- MmlStack.prototype.Clear = function () {
- this._nodes = [];
- };
- MmlStack.prototype.toMml = function (inferred, forceRow) {
- if (inferred === void 0) { inferred = true; }
- if (this._nodes.length === 1 && !forceRow) {
- return this.First;
- }
- return this.create('node', inferred ? 'inferredMrow' : 'mrow', this._nodes, {});
- };
- MmlStack.prototype.create = function (kind) {
- var _a;
- var rest = [];
- for (var _i = 1; _i < arguments.length; _i++) {
- rest[_i - 1] = arguments[_i];
- }
- return (_a = this.factory.configuration.nodeFactory).create.apply(_a, __spreadArray([kind], __read(rest), false));
- };
- return MmlStack;
- }());
- exports.MmlStack = MmlStack;
- var BaseItem = (function (_super) {
- __extends(BaseItem, _super);
- function BaseItem(factory) {
- var nodes = [];
- for (var _i = 1; _i < arguments.length; _i++) {
- nodes[_i - 1] = arguments[_i];
- }
- var _this = _super.call(this, nodes) || this;
- _this.factory = factory;
- _this.global = {};
- _this._properties = {};
- if (_this.isOpen) {
- _this._env = {};
- }
- return _this;
- }
- Object.defineProperty(BaseItem.prototype, "kind", {
- get: function () {
- return 'base';
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(BaseItem.prototype, "env", {
- get: function () {
- return this._env;
- },
- set: function (value) {
- this._env = value;
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(BaseItem.prototype, "copyEnv", {
- get: function () {
- return true;
- },
- enumerable: false,
- configurable: true
- });
- BaseItem.prototype.getProperty = function (key) {
- return this._properties[key];
- };
- BaseItem.prototype.setProperty = function (key, value) {
- this._properties[key] = value;
- return this;
- };
- Object.defineProperty(BaseItem.prototype, "isOpen", {
- get: function () {
- return false;
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(BaseItem.prototype, "isClose", {
- get: function () {
- return false;
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(BaseItem.prototype, "isFinal", {
- get: function () {
- return false;
- },
- enumerable: false,
- configurable: true
- });
- BaseItem.prototype.isKind = function (kind) {
- return kind === this.kind;
- };
- BaseItem.prototype.checkItem = function (item) {
- if (item.isKind('over') && this.isOpen) {
- item.setProperty('num', this.toMml(false));
- this.Clear();
- }
- if (item.isKind('cell') && this.isOpen) {
- if (item.getProperty('linebreak')) {
- return BaseItem.fail;
- }
- throw new TexError_js_1.default('Misplaced', 'Misplaced %1', item.getName());
- }
- if (item.isClose && this.getErrors(item.kind)) {
- var _a = __read(this.getErrors(item.kind), 2), id = _a[0], message = _a[1];
- throw new TexError_js_1.default(id, message, item.getName());
- }
- if (!item.isFinal) {
- return BaseItem.success;
- }
- this.Push(item.First);
- return BaseItem.fail;
- };
- BaseItem.prototype.clearEnv = function () {
- var e_1, _a;
- try {
- for (var _b = __values(Object.keys(this.env)), _c = _b.next(); !_c.done; _c = _b.next()) {
- var id = _c.value;
- delete this.env[id];
- }
- }
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
- finally {
- try {
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
- }
- finally { if (e_1) throw e_1.error; }
- }
- };
- BaseItem.prototype.setProperties = function (def) {
- Object.assign(this._properties, def);
- return this;
- };
- BaseItem.prototype.getName = function () {
- return this.getProperty('name');
- };
- BaseItem.prototype.toString = function () {
- return this.kind + '[' + this.nodes.join('; ') + ']';
- };
- BaseItem.prototype.getErrors = function (kind) {
- var CLASS = this.constructor;
- return (CLASS.errors || {})[kind] || BaseItem.errors[kind];
- };
- BaseItem.fail = [null, false];
- BaseItem.success = [null, true];
- BaseItem.errors = {
- end: ['MissingBeginExtraEnd', 'Missing \\begin{%1} or extra \\end{%1}'],
- close: ['ExtraCloseMissingOpen', 'Extra close brace or missing open brace'],
- right: ['MissingLeftExtraRight', 'Missing \\left or extra \\right'],
- middle: ['ExtraMiddle', 'Extra \\middle']
- };
- return BaseItem;
- }(MmlStack));
- exports.BaseItem = BaseItem;
- //# sourceMappingURL=StackItem.js.map
|