@@ -156,7 +156,7 @@ export class RegExpMap extends AbstractTokenMap<string> {
156156 * @extends {AbstractTokenMap }
157157 * @param {string } name Name of the mapping.
158158 * @param {ParseMethod } parser The parser for the mappiong.
159- * @param {RegExp } regexp The regular expression.
159+ * @param {RegExp } _regExp The regular expression.
160160 */
161161 constructor ( name : string , parser : ParseMethod , private _regExp : RegExp ) {
162162 super ( name , parser ) ;
@@ -271,6 +271,8 @@ export class DelimiterMap extends CharacterMap {
271271}
272272
273273
274+ type ParseFunction = string | ParseMethod ;
275+
274276/**
275277 * Maps macros that all bring their own parsing method.
276278 *
@@ -283,18 +285,23 @@ export class MacroMap extends AbstractParseMap<Macro> {
283285 * @constructor
284286 * @param {string } name Name of the mapping.
285287 * @param {JSON } json The JSON representation of the macro map.
288+ * @param {{[key: string]: ParseMethod} } functionMap Optionally a collection
289+ * of parse functions for the single macros. Kept for backward compatibility.
286290 */
287291 constructor ( name : string ,
288- json : { [ index : string ] : ParseMethod | [ ParseMethod , ...Args [ ] ] } ) {
292+ json : { [ index : string ] : ParseFunction | [ ParseFunction , ...Args [ ] ] } ,
293+ functionMap : { [ key : string ] : ParseMethod } = { } ) {
289294 super ( name , null ) ;
295+ const getMethod = ( func : ParseFunction ) =>
296+ ( typeof func === 'string' ) ? functionMap [ func ] : func ;
290297 for ( const [ key , value ] of Object . entries ( json ) ) {
291- let func : ParseMethod ;
298+ let func : ParseFunction ;
292299 let args : Args [ ] ;
293300 if ( Array . isArray ( value ) ) {
294- func = value [ 0 ] ;
301+ func = getMethod ( value [ 0 ] ) ;
295302 args = value . slice ( 1 ) as Args [ ] ;
296303 } else {
297- func = value ;
304+ func = getMethod ( value ) ;
298305 args = [ ] ;
299306 }
300307 let character = new Macro ( key , func , args ) ;
@@ -369,11 +376,14 @@ export class EnvironmentMap extends MacroMap {
369376 * @param {string } name Name of the mapping.
370377 * @param {ParseMethod } parser The parser for the environments.
371378 * @param {JSON } json The JSON representation of the macro map.
379+ * @param {{[key: string]: ParseMethod} } functionMap Optionally a collection
380+ * of parse functions for the single macros. Kept for backward compatibility.
372381 */
373382 constructor ( name : string ,
374383 parser : ParseMethod ,
375- json : { [ index : string ] : ParseMethod | [ ParseMethod , ...Args [ ] ] } ) {
376- super ( name , json ) ;
384+ json : { [ index : string ] : ParseFunction | [ ParseFunction , ...Args [ ] ] } ,
385+ functionMap : { [ key : string ] : ParseMethod } = { } ) {
386+ super ( name , json , functionMap ) ;
377387 this . parser = parser ;
378388 }
379389
0 commit comments