UNPKG

mathoid-texvcjs

Version:

A TeX/LaTeX validator for MediaWiki.

49 lines (46 loc) 1.29 kB
'use strict'; const TexNode = require('./texnode'); const TexUtil = require('../texutil'); const assert = require('assert'); const literals = Object.keys(TexUtil.is_literal); const extendedLiterals = literals.slice(0); extendedLiterals.push('\\infty', '\\emptyset'); class Literal extends TexNode { constructor(arg) { assert.strictEqual( arguments.length, 1, 'Incorrect number or arguments'); assert.ok( arg instanceof String || typeof arg === 'string', 'Incorrect argument type'); super(arg); this.arg = arg; } _getLiteral(lit, regexp) { const s = this.arg.trim(); if (regexp.test(s)) { return [s]; } else if (lit.includes(s)) { return [s]; } else { return []; } } extractIdentifiers() { return this._getLiteral(literals, /^([a-zA-Z']|\\int)$/); } extractSubscripts() { return this._getLiteral(extendedLiterals, /^([0-9a-zA-Z+',-])$/); } getModIdent() { if (this.arg === '\\ ') { return ['\\ ']; } return this._getLiteral(literals, /^([0-9a-zA-Z'])$/); } get name() { return 'LITERAL'; } } module.exports = Literal;