Skip to content

Commit

Permalink
Merge pull request #982 from mathjax/issue3072
Browse files Browse the repository at this point in the history
Change Symbol to Token to avoid conflict with native Symbol in webpacked files. (mathjax/MathJax#3072)
  • Loading branch information
dpvc authored Aug 17, 2023
2 parents 2032f22 + 1b7784e commit 3f4c730
Show file tree
Hide file tree
Showing 52 changed files with 239 additions and 249 deletions.
2 changes: 1 addition & 1 deletion ts/input/tex/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class Configuration {
* @param {string} name The package name.
* @param {Object} config The configuration parameters:
* Configuration for the TexParser consist of the following:
* * _handler_ configuration mapping handler types to lists of symbol mappings.
* * _handler_ configuration mapping handler types to lists of token mappings.
* * _fallback_ configuration mapping handler types to fallback methods.
* * _items_ for the StackItem factory.
* * _tags_ mapping tagging configurations to tagging objects.
Expand Down
83 changes: 41 additions & 42 deletions ts/input/tex/MapHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
* @author v.sorge@mathjax.org (Volker Sorge)
*/

import {AbstractSymbolMap, SymbolMap} from './SymbolMap.js';
import {AbstractTokenMap, TokenMap} from './TokenMap.js';
import {ParseInput, ParseResult, ParseMethod} from './Types.js';
// import {ParserConfiguration} from './Configuration.js';
import {PrioritizedList} from '../../util/PrioritizedList.js';
import {FunctionList} from '../../util/FunctionList.js';

Expand All @@ -37,43 +36,43 @@ export type FallbackConfig = {[P in HandlerType]?: ParseMethod};

export namespace MapHandler {

let maps: Map<string, SymbolMap> = new Map();
let maps: Map<string, TokenMap> = new Map();

/**
* Adds a new symbol map to the map handler. Might overwrite an existing
* symbol map of the same name.
* Adds a new token map to the map handler. Might overwrite an existing
* token map of the same name.
*
* @param {SymbolMap} map Registers a new symbol map.
* @param {TokenMap} map Registers a new token map.
*/
export let register = function(map: SymbolMap): void {
export let register = function(map: TokenMap): void {
maps.set(map.name, map);
};


/**
* Looks up a symbol map if it exists.
* Looks up a token map if it exists.
*
* @param {string} name The name of the symbol map.
* @return {SymbolMap} The symbol map with the given name or null.
* @param {string} name The name of the token map.
* @return {TokenMap} The token map with the given name or null.
*/
export let getMap = function(name: string): SymbolMap {
export let getMap = function(name: string): TokenMap {
return maps.get(name);
};

}


/**
* Class of symbol mappings that are active in a configuration.
* Class of token mappings that are active in a configuration.
*/
export class SubHandler {

private _configuration: PrioritizedList<SymbolMap> = new PrioritizedList<SymbolMap>();
private _configuration: PrioritizedList<TokenMap> = new PrioritizedList<TokenMap>();
private _fallback: FunctionList = new FunctionList();

/**
* Adds a list of symbol maps to the handler.
* @param {string[]} maps The names of the symbol maps to add.
* Adds a list of token maps to the handler.
* @param {string[]} maps The names of the token maps to add.
* @param {ParseMethod} fallback A fallback method.
* @param {number} priority Optionally a priority.
*/
Expand All @@ -93,7 +92,7 @@ export class SubHandler {
}

/**
* Parses the given input with the first applicable symbol map.
* Parses the given input with the first applicable token map.
* @param {ParseInput} input The input for the parser.
* @return {ParseResult} The output of the parsing function.
*/
Expand All @@ -104,32 +103,32 @@ export class SubHandler {
return result;
}
}
let [env, symbol] = input;
Array.from(this._fallback)[0].item(env, symbol);
let [env, token] = input;
Array.from(this._fallback)[0].item(env, token);
}


/**
* Maps a symbol to its "parse value" if it exists.
* Maps a token to its "parse value" if it exists.
*
* @param {string} symbol The symbol to parse.
* @param {string} token The token to parse.
* @return {T} A boolean, Character, or Macro.
*/
public lookup<T>(symbol: string): T {
let map = this.applicable(symbol) as AbstractSymbolMap<T>;
return map ? map.lookup(symbol) : null;
public lookup<T>(token: string): T {
let map = this.applicable(token) as AbstractTokenMap<T>;
return map ? map.lookup(token) : null;
}


/**
* Checks if a symbol is contained in one of the symbol mappings of this
* Checks if a token is contained in one of the token mappings of this
* configuration.
*
* @param {string} symbol The symbol to parse.
* @return {boolean} True if the symbol is contained in the mapping.
* @param {string} token The token to parse.
* @return {boolean} True if the token is contained in the mapping.
*/
public contains(symbol: string): boolean {
return this.applicable(symbol) ? true : false;
public contains(token: string): boolean {
return this.applicable(token) ? true : false;
}


Expand All @@ -146,13 +145,13 @@ export class SubHandler {


/**
* Retrieves the first applicable symbol map in the configuration.
* @param {string} symbol The symbol to parse.
* @return {SymbolMap} A map that can parse the symbol.
* Retrieves the first applicable token map in the configuration.
* @param {string} token The token to parse.
* @return {TokenMap} A map that can parse the token.
*/
public applicable(symbol: string): SymbolMap {
public applicable(token: string): TokenMap {
for (let {item: map} of this._configuration) {
if (map.contains(symbol)) {
if (map.contains(token)) {
return map;
}
}
Expand All @@ -162,10 +161,10 @@ export class SubHandler {

/**
* Retrieves the map of the given name.
* @param {string} name Name of the symbol map.
* @return {SymbolMap} The map if it exists.
* @param {string} name Name of the token map.
* @return {TokenMap} The map if it exists.
*/
public retrieve(name: string): SymbolMap {
public retrieve(name: string): TokenMap {
for (let {item: map} of this._configuration) {
if (map.name === name) {
return map;
Expand All @@ -191,8 +190,8 @@ export class SubHandlers {
private map = new Map<HandlerType, SubHandler>();

/**
* Adds a symbol map to the configuration if it exists.
* @param {string} name of the symbol map.
* Adds a token map to the configuration if it exists.
* @param {string} name of the token map.
*/
public add(handlers: HandlerConfig, fallbacks: FallbackConfig,
priority: number = PrioritizedList.DEFAULTPRIORITY): void {
Expand Down Expand Up @@ -229,11 +228,11 @@ export class SubHandlers {


/**
* Retrieves a symbol map of the given name.
* @param {string} name Name of the symbol map.
* @return {SymbolMap} The map if it exists. O/w null.
* Retrieves a token map of the given name.
* @param {string} name Name of the token map.
* @return {TokenMap} The map if it exists. O/w null.
*/
public retrieve(name: string): SymbolMap {
public retrieve(name: string): TokenMap {
for (const handler of this.map.values()) {
let map = handler.retrieve(name);
if (map) {
Expand Down
26 changes: 13 additions & 13 deletions ts/input/tex/ParseMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @author v.sorge@mathjax.org (Volker Sorge)
*/

import {Symbol} from './Symbol.js';
import {Token} from './Token.js';
import TexParser from './TexParser.js';
import NodeUtil from './NodeUtil.js';
import {TexConstant} from './TexConstants.js';
Expand Down Expand Up @@ -98,9 +98,9 @@ namespace ParseMethods {
/**
* Handle lower-case Greek (as an mi).
* @param {TexParser} parser The current tex parser.
* @param {Symbol} mchar The parsed symbol.
* @param {Token} mchar The parsed token.
*/
export function lcGreek(parser: TexParser, mchar: Symbol) {
export function lcGreek(parser: TexParser, mchar: Token) {
const def = {mathvariant: parser.configuration.mathStyle(mchar.char) || MATHVARIANT.ITALIC};
// @test Greek
const node = parser.create('token', 'mi', def, mchar.char);
Expand All @@ -110,9 +110,9 @@ namespace ParseMethods {
/**
* Handle mathcharupper-case Greek in current family.
* @param {TexParser} parser The current tex parser.
* @param {Symbol} mchar The parsed symbol.
* @param {Token} mchar The parsed token.
*/
export function ucGreek(parser: TexParser, mchar: Symbol) {
export function ucGreek(parser: TexParser, mchar: Token) {
const def = {mathvariant: parser.stack.env['font'] ||
parser.configuration.mathStyle(mchar.char, true) ||
MATHVARIANT.NORMAL};
Expand All @@ -124,9 +124,9 @@ namespace ParseMethods {
/**
* Handle normal mathchar (as an mi).
* @param {TexParser} parser The current tex parser.
* @param {Symbol} mchar The parsed symbol.
* @param {Token} mchar The parsed token.
*/
export function mathchar0mi(parser: TexParser, mchar: Symbol) {
export function mathchar0mi(parser: TexParser, mchar: Token) {
const def = mchar.attributes || {mathvariant: MATHVARIANT.ITALIC};
const node = parser.create('token', 'mi', def, mchar.char);
parser.Push(node);
Expand All @@ -135,9 +135,9 @@ namespace ParseMethods {
/**
* Handle normal mathchar (as an mo).
* @param {TexParser} parser The current tex parser.
* @param {Symbol} mchar The parsed symbol.
* @param {Token} mchar The parsed token.
*/
export function mathchar0mo(parser: TexParser, mchar: Symbol) {
export function mathchar0mo(parser: TexParser, mchar: Token) {
const def = mchar.attributes || {};
def['stretchy'] = false;
// @test Large Set
Expand All @@ -151,9 +151,9 @@ namespace ParseMethods {
/**
* Handle mathchar in current family.
* @param {TexParser} parser The current tex parser.
* @param {Symbol} mchar The parsed symbol.
* @param {Token} mchar The parsed token.
*/
export function mathchar7(parser: TexParser, mchar: Symbol) {
export function mathchar7(parser: TexParser, mchar: Token) {
const def = mchar.attributes || {mathvariant: MATHVARIANT.NORMAL};
if (parser.stack.env['font']) {
// @test MathChar7 Single Font
Expand All @@ -167,9 +167,9 @@ namespace ParseMethods {
/**
* Handle delimiter.
* @param {TexParser} parser The current tex parser.
* @param {Symbol} delim The parsed delimiter symbol.
* @param {Token} delim The parsed delimiter token.
*/
export function delimiter(parser: TexParser, delim: Symbol) {
export function delimiter(parser: TexParser, delim: Token) {
let def = delim.attributes || {};
// @test Fenced2, Delimiter (AMS)
def = Object.assign({fence: false, stretchy: false}, def);
Expand Down
26 changes: 13 additions & 13 deletions ts/input/tex/TexParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {MmlNode, AbstractMmlNode} from '../../core/MmlTree/MmlNode.js';
import {ParseInput, ParseResult} from './Types.js';
import ParseOptions from './ParseOptions.js';
import {StackItem, EnvList} from './StackItem.js';
import {Symbol} from './Symbol.js';
import {Token} from './Token.js';
import {OptionList} from '../../util/Options.js';


Expand Down Expand Up @@ -140,26 +140,26 @@ export default class TexParser {


/**
* Maps a symbol to its "parse value" if it exists.
* Maps a token to its "parse value" if it exists.
* @param {HandlerType} kind Configuration name.
* @param {string} symbol The symbol to parse.
* @param {string} token The token to parse.
* @return {any} A boolean, Character, or Macro.
*/
public lookup(kind: HandlerType, symbol: string): any {
return this.configuration.handlers.get(kind).lookup(symbol);
public lookup(kind: HandlerType, token: string): any {
return this.configuration.handlers.get(kind).lookup(token);
}


/**
* Checks if a symbol is contained in one of the symbol mappings of the
* Checks if a token is contained in one of the token mappings of the
* specified kind.
* @param {HandlerType} kind Configuration name.
* @param {string} symbol The symbol to parse.
* @return {boolean} True if the symbol is contained in the given types of
* symbol mapping.
* @param {string} token The token to parse.
* @return {boolean} True if the token is contained in the given types of
* token mapping.
*/
public contains(kind: HandlerType, symbol: string): boolean {
return this.configuration.handlers.get(kind).contains(symbol);
public contains(kind: HandlerType, token: string): boolean {
return this.configuration.handlers.get(kind).contains(token);
}


Expand Down Expand Up @@ -237,8 +237,8 @@ export default class TexParser {
* @return {string} The corresponding character.
*/
public convertDelimiter(c: string): string {
const symbol = this.lookup('delimiter', c) as Symbol;
return symbol ? symbol.char : null;
const token = this.lookup('delimiter', c) as Token;
return token ? token.char : null;
}

/**
Expand Down
Loading

0 comments on commit 3f4c730

Please sign in to comment.