tex2typst 0.5.7 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.ts CHANGED
@@ -7,6 +7,8 @@ import { symbolMap } from "./map";
7
7
  import { parseTypst } from "./typst-parser";
8
8
  import { TexWriter } from "./tex-writer";
9
9
  import { shorthandMap } from "./typst-shorthands";
10
+ import { expand_tex_predefined_macros } from "./tex-semantic-analysis";
11
+ import { expand_typst_predefined_variables } from "./typst-semantic-analyais";
10
12
 
11
13
 
12
14
  export function tex2typst(tex: string, options: Partial<Tex2TypstOptions> = {}): string {
@@ -30,7 +32,8 @@ export function tex2typst(tex: string, options: Partial<Tex2TypstOptions> = {}):
30
32
  }
31
33
 
32
34
  const texTree = parseTex(tex, opt.customTexMacros!);
33
- const typstTree = convert_tex_node_to_typst(texTree, opt);
35
+ const preprocessedTexTree = expand_tex_predefined_macros(texTree);
36
+ const typstTree = convert_tex_node_to_typst(preprocessedTexTree, opt);
34
37
  const writer = new TypstWriter(opt as TypstWriterOptions);
35
38
  writer.serialize(typstTree);
36
39
  return writer.finalize();
@@ -51,7 +54,8 @@ export function typst2tex(typst: string, options: Partial<Typst2TexOptions> = {}
51
54
  }
52
55
 
53
56
  const typstTree = parseTypst(typst);
54
- const texTree = convert_typst_node_to_tex(typstTree, opt);
57
+ const preprocessedTypstTree = expand_typst_predefined_variables(typstTree);
58
+ const texTree = convert_typst_node_to_tex(preprocessedTypstTree, opt);
55
59
  const writer = new TexWriter();
56
60
  writer.append(texTree);
57
61
  return writer.finalize();
@@ -1,16 +1,18 @@
1
1
  /**
2
+ * Last modified: 2026-04-09
2
3
  * Adapted from jslex - A lexer in JavaScript. https://github.com/jimbojw/jslex
3
4
  * Licensed under MIT license
4
5
  */
5
6
 
7
+ export type ScannerCallback<T> = (a: Scanner<T>) => T | T[];
6
8
 
7
9
  interface ILexSpec<T> {
8
- [key: string]: Map<string, (arg0: Scanner<T>) => T | T[]>;
10
+ [key: string]: Map<string, ScannerCallback<T>>;
9
11
  }
10
12
 
11
13
  interface IRule<T> {
12
14
  re: RegExp;
13
- action: (a: Scanner<T>) => T | T[];
15
+ action: ScannerCallback<T>;
14
16
  }
15
17
 
16
18
  interface IMatch<T> {
@@ -252,6 +254,9 @@ export class JSLex<T> {
252
254
  for (const [k,v] of rule_map.entries()) {
253
255
  let re: RegExp;
254
256
  try {
257
+ // FIXME: e.g. "neg|norm" becomes /^neg|norm/,
258
+ // but what we really want is /^(neg|norm)/ .
259
+ // This will cause error when tokenize input like "...norm..."
255
260
  re = new RegExp('^' + k);
256
261
  } catch (err) {
257
262
  throw "Invalid regexp '" + k + "' in state '" + s + "' (" + (err as Error).message + ")";
package/src/map.ts CHANGED
@@ -52,7 +52,6 @@ const symbolMap = new Map<string, string>([
52
52
  ['neq', 'eq.not'],
53
53
  ['dot', 'dot'],
54
54
  ['ddot', 'dot.double'],
55
- ['doteq', 'dot(eq)'],
56
55
  ['dots', 'dots.h'],
57
56
  ['vdots', 'dots.v'],
58
57
  ['ddots', 'dots.down'],
@@ -1136,7 +1135,6 @@ const reverseSymbolMap = new Map<string, string>();
1136
1135
  for(const [key, value] of Array.from(symbolMap.entries()).reverse()) {
1137
1136
  reverseSymbolMap.set(value, key);
1138
1137
  }
1139
- reverseSymbolMap.set('oo', 'infty');
1140
1138
 
1141
1139
  // force override some one-to-multiple mappings
1142
1140
  const typst_to_tex_map = new Map<string, string>([
@@ -0,0 +1,39 @@
1
+ import { parseTex } from "./tex-parser";
2
+ import { TexNode, TexTokenType } from "./tex-types";
3
+
4
+ const TEX_PREDEFINED_MACROS: Map<string, string> = new Map([
5
+ // https://github.com/KaTeX/KaTeX/blob/434d4b8aef4c3311ebfd3405a9f0cce18ead953b/src/macros.ts#L351-L367
6
+ ["\\varGamma", "\\mathit{\\Gamma}"],
7
+ ["\\varDelta", "\\mathit{\\Delta}"],
8
+ ["\\varTheta", "\\mathit{\\Theta}"],
9
+ ["\\varLambda", "\\mathit{\\Lambda}"],
10
+ ["\\varXi", "\\mathit{\\Xi}"],
11
+ ["\\varPi", "\\mathit{\\Pi}"],
12
+ ["\\varSigma", "\\mathit{\\Sigma}"],
13
+ ["\\varUpsilon", "\\mathit{\\Upsilon}"],
14
+ ["\\varPhi", "\\mathit{\\Phi}"],
15
+ ["\\varPsi", "\\mathit{\\Psi}"],
16
+ ["\\varOmega", "\\mathit{\\Omega}"],
17
+
18
+ ["\\doteq", "\\dot{=}"],
19
+ ]);
20
+
21
+ function _expand_tex_predefined_macros(node: TexNode): TexNode {
22
+ switch (node.type) {
23
+ case "terminal": {
24
+ if (node.head.type === TexTokenType.COMMAND) {
25
+ if (TEX_PREDEFINED_MACROS.has(node.head.value)) {
26
+ const target_str = TEX_PREDEFINED_MACROS.get(node.head.value)!;
27
+ return parseTex(target_str);
28
+ }
29
+ }
30
+ }
31
+ case "funcCall":
32
+ default:
33
+ return node;
34
+ }
35
+ }
36
+
37
+ export function expand_tex_predefined_macros(node: TexNode): TexNode {
38
+ return node.bottomTopTraversalTransform(_expand_tex_predefined_macros);
39
+ }
@@ -1,5 +1,5 @@
1
1
  import { TexToken, TexTokenType } from "./tex-types";
2
- import { JSLex, Scanner } from "./jslex";
2
+ import { JSLex, Scanner, ScannerCallback } from "./lex";
3
3
 
4
4
  export const TEX_UNARY_COMMANDS = [
5
5
  'sqrt',
@@ -70,7 +70,7 @@ function unescape(str: string): string {
70
70
  return str;
71
71
  }
72
72
 
73
- const rules_map = new Map<string, (a: Scanner<TexToken>) => TexToken | TexToken[]>([
73
+ const rules_map = new Map<string, ScannerCallback<TexToken>>([
74
74
  // match `\begin{array}{cc}`
75
75
  [
76
76
  String.raw`\\begin{(array|subarry)}{(.+?)}`, (s) => {
package/src/tex-types.ts CHANGED
@@ -85,6 +85,7 @@ export abstract class TexNode {
85
85
  }
86
86
 
87
87
  abstract serialize(): TexToken[];
88
+ abstract bottomTopTraversalTransform(operationFn: (n: TexNode) => TexNode): TexNode;
88
89
 
89
90
  // Note: toString() is expensive. Do not use it on performance-critical code path.
90
91
  public toString(): string {
@@ -129,6 +130,10 @@ export class TexTerminal extends TexNode {
129
130
  throw new Error(`Unknown terminal token type: ${this.head.type}`);
130
131
  }
131
132
  }
133
+
134
+ public bottomTopTraversalTransform(operationFn: (n: TexNode) => TexNode): TexNode {
135
+ return operationFn(this);
136
+ }
132
137
  }
133
138
 
134
139
  export class TexText extends TexNode {
@@ -146,6 +151,10 @@ export class TexText extends TexNode {
146
151
  new TexToken(TexTokenType.ELEMENT, '}'),
147
152
  ];
148
153
  }
154
+
155
+ public bottomTopTraversalTransform(operationFn: (n: TexNode) => TexNode): TexNode {
156
+ return operationFn(this);
157
+ }
149
158
  }
150
159
 
151
160
  export class TexGroup extends TexNode {
@@ -158,6 +167,11 @@ export class TexGroup extends TexNode {
158
167
  public serialize(): TexToken[] {
159
168
  return this.items.map((n) => n.serialize()).flat();
160
169
  }
170
+
171
+ public bottomTopTraversalTransform(operationFn: (n: TexNode) => TexNode): TexNode {
172
+ const g = new TexGroup(this.items.map((n) => n.bottomTopTraversalTransform(operationFn)));
173
+ return operationFn(g);
174
+ }
161
175
  }
162
176
 
163
177
  export class TexSupSub extends TexNode {
@@ -211,6 +225,15 @@ export class TexSupSub extends TexNode {
211
225
  }
212
226
  return tokens;
213
227
  }
228
+
229
+ public bottomTopTraversalTransform(operationFn: (n: TexNode) => TexNode): TexNode {
230
+ const s = new TexSupSub({
231
+ base: this.base.bottomTopTraversalTransform(operationFn),
232
+ sup: this.sup? this.sup.bottomTopTraversalTransform(operationFn): null,
233
+ sub: this.sub? this.sub.bottomTopTraversalTransform(operationFn): null,
234
+ });
235
+ return operationFn(s);
236
+ }
214
237
  }
215
238
 
216
239
  export class TexFuncCall extends TexNode {
@@ -244,6 +267,11 @@ export class TexFuncCall extends TexNode {
244
267
 
245
268
  return tokens;
246
269
  }
270
+
271
+ public bottomTopTraversalTransform(operationFn: (n: TexNode) => TexNode): TexNode {
272
+ const f = new TexFuncCall(this.head, this.args.map((n) => n.bottomTopTraversalTransform(operationFn)), this.data);
273
+ return operationFn(f);
274
+ }
247
275
  }
248
276
 
249
277
  export class TexLeftRight extends TexNode {
@@ -267,6 +295,15 @@ export class TexLeftRight extends TexNode {
267
295
  tokens.push(new TexToken(TexTokenType.ELEMENT, this.right? this.right.value: '.'));
268
296
  return tokens;
269
297
  }
298
+
299
+ public bottomTopTraversalTransform(operationFn: (n: TexNode) => TexNode): TexNode {
300
+ const l = new TexLeftRight({
301
+ body: this.body.bottomTopTraversalTransform(operationFn),
302
+ left: this.left,
303
+ right: this.right,
304
+ });
305
+ return operationFn(l);
306
+ }
270
307
  }
271
308
 
272
309
  export class TexBeginEnd extends TexNode {
@@ -311,6 +348,13 @@ export class TexBeginEnd extends TexNode {
311
348
  tokens.push(new TexToken(TexTokenType.ELEMENT, '}'));
312
349
  return tokens;
313
350
  }
351
+
352
+ public bottomTopTraversalTransform(operationFn: (n: TexNode) => TexNode): TexNode {
353
+ const m = this.matrix.map((row) => row.map((cell) => cell.bottomTopTraversalTransform(operationFn)));
354
+ const d = this.data? this.data.bottomTopTraversalTransform(operationFn): null;
355
+ const be = new TexBeginEnd(this.head, m, d);
356
+ return operationFn(be);
357
+ }
314
358
  }
315
359
 
316
360
  export function writeTexTokenBuffer(buffer: string, token: TexToken): string {
@@ -0,0 +1,38 @@
1
+ import { parseTypst } from "./typst-parser";
2
+ import { TypstNode, TypstTokenType } from "./typst-types";
3
+
4
+
5
+ const TEX_PREDEFINED_VARIABLES: Map<string, string> = new Map([
6
+ ["dif", "upright(d)"],
7
+ ["eq.def", 'limits(=)^"def"'],
8
+ ["oo", "infinity"],
9
+ ["comma", ","],
10
+ ["hyph", '"-"'],
11
+ ["hyph.minus", '"-"'],
12
+
13
+ /*
14
+ ["AA", "bb(A)"],
15
+ ["BB", "bb(B)"],
16
+ ["CC", "bb(C)"],
17
+ */
18
+ ]);
19
+
20
+ function _expand_typst_predefined_variables(node: TypstNode): TypstNode {
21
+ switch (node.type) {
22
+ case "terminal": {
23
+ if (node.head.type === TypstTokenType.SYMBOL) {
24
+ if (TEX_PREDEFINED_VARIABLES.has(node.head.value)) {
25
+ const target_str = TEX_PREDEFINED_VARIABLES.get(node.head.value)!;
26
+ return parseTypst(target_str);
27
+ }
28
+ }
29
+ }
30
+ case "funcCall":
31
+ default:
32
+ return node;
33
+ }
34
+ }
35
+
36
+ export function expand_typst_predefined_variables(node: TypstNode): TypstNode {
37
+ return node.bottomTopTraversalTransform(_expand_typst_predefined_variables);
38
+ }
@@ -1,7 +1,7 @@
1
1
  import { TypstToken } from "./typst-types";
2
2
  import { TypstTokenType } from "./typst-types";
3
3
  import { reverseShorthandMap } from "./typst-shorthands";
4
- import { JSLex, Scanner } from "./jslex";
4
+ import { JSLex, Scanner, ScannerCallback } from "./lex";
5
5
 
6
6
  const TYPST_SHORTHANDS = Array.from(reverseShorthandMap.keys());
7
7
 
@@ -20,7 +20,7 @@ function generate_regex_for_shorthands(): string {
20
20
 
21
21
  const REGEX_SHORTHANDS = generate_regex_for_shorthands();
22
22
 
23
- const rules_map = new Map<string, (a: Scanner<TypstToken>) => TypstToken | TypstToken[]>([
23
+ const rules_map = new Map<string, ScannerCallback<TypstToken>>([
24
24
  [String.raw`//[^\n]*`, (s) => new TypstToken(TypstTokenType.COMMENT, s.text()!.substring(2))],
25
25
  [String.raw`/`, (s) => new TypstToken(TypstTokenType.ELEMENT, s.text()!)],
26
26
  [String.raw`[_^&]`, (s) => new TypstToken(TypstTokenType.CONTROL, s.text()!)],
@@ -150,6 +150,9 @@ export abstract class TypstNode {
150
150
  // Serialize a tree of TypstNode into a list of TypstToken
151
151
  abstract serialize(env: TypstWriterEnvironment, options: TypstWriterOptions): TypstToken[];
152
152
 
153
+ abstract bottomTopTraversalTransform(transform: (node: TypstNode) => TypstNode): TypstNode;
154
+
155
+
153
156
  public setOptions(options: TypstNamedParams) {
154
157
  this.options = options;
155
158
  }
@@ -246,6 +249,10 @@ export class TypstTerminal extends TypstNode {
246
249
  }
247
250
  return [this.head];
248
251
  }
252
+
253
+ public bottomTopTraversalTransform(transform: (node: TypstNode) => TypstNode): TypstNode {
254
+ return transform(this);
255
+ }
249
256
  }
250
257
 
251
258
  class TypstTokenQueue {
@@ -340,6 +347,11 @@ export class TypstGroup extends TypstNode {
340
347
  }
341
348
  return queue;
342
349
  }
350
+
351
+ public bottomTopTraversalTransform(transform: (node: TypstNode) => TypstNode): TypstNode {
352
+ const g = new TypstGroup(this.items.map((n) => n.bottomTopTraversalTransform(transform)));
353
+ return transform(g);
354
+ }
343
355
  }
344
356
 
345
357
 
@@ -392,6 +404,15 @@ export class TypstSupsub extends TypstNode {
392
404
  }
393
405
  return queue;
394
406
  }
407
+
408
+ public bottomTopTraversalTransform(transform: (node: TypstNode) => TypstNode): TypstNode {
409
+ const s = new TypstSupsub({
410
+ base: this.base.bottomTopTraversalTransform(transform),
411
+ sup: this.sup?.bottomTopTraversalTransform(transform) || null,
412
+ sub: this.sub?.bottomTopTraversalTransform(transform) || null
413
+ });
414
+ return transform(s);
415
+ }
395
416
  }
396
417
 
397
418
  export class TypstFuncCall extends TypstNode {
@@ -439,6 +460,12 @@ export class TypstFuncCall extends TypstNode {
439
460
  env.insideFunctionDepth--;
440
461
  return queue;
441
462
  }
463
+
464
+ public bottomTopTraversalTransform(transform: (node: TypstNode) => TypstNode): TypstNode {
465
+ const f = new TypstFuncCall(this.head, this.args.map((n) => n.bottomTopTraversalTransform(transform)));
466
+ f.options = this.options;
467
+ return transform(f);
468
+ }
442
469
  }
443
470
 
444
471
  export class TypstFraction extends TypstNode {
@@ -470,6 +497,11 @@ export class TypstFraction extends TypstNode {
470
497
  queue.push(...denominator.serialize(env, options));
471
498
  return queue;
472
499
  }
500
+
501
+ public bottomTopTraversalTransform(transform: (node: TypstNode) => TypstNode): TypstNode {
502
+ const f = new TypstFraction(this.args.map((n) => n.bottomTopTraversalTransform(transform)));
503
+ return transform(f);
504
+ }
473
505
  }
474
506
 
475
507
  const TYPST_LEFT_PARENTHESIS: TypstToken = new TypstToken(TypstTokenType.ELEMENT, '(');
@@ -529,6 +561,16 @@ export class TypstLeftright extends TypstNode {
529
561
  }
530
562
  return queue;
531
563
  }
564
+
565
+
566
+ public bottomTopTraversalTransform(transform: (node: TypstNode) => TypstNode): TypstNode {
567
+ const l = new TypstLeftright(this.head, {
568
+ body: this.body.bottomTopTraversalTransform(transform),
569
+ left: this.left,
570
+ right: this.right,
571
+ });
572
+ return transform(l);
573
+ }
532
574
  }
533
575
 
534
576
 
@@ -609,6 +651,13 @@ export class TypstMatrixLike extends TypstNode {
609
651
  return queue;
610
652
  }
611
653
 
654
+ public bottomTopTraversalTransform(transform: (node: TypstNode) => TypstNode): TypstNode {
655
+ const m = this.matrix.map((row) => row.map((cell) => cell.bottomTopTraversalTransform(transform)));
656
+ const ml = new TypstMatrixLike(this.head, m);
657
+ ml.options = this.options;
658
+ return transform(ml);
659
+ }
660
+
612
661
  static readonly MAT = new TypstToken(TypstTokenType.SYMBOL, 'mat');
613
662
  static readonly CASES = new TypstToken(TypstTokenType.SYMBOL, 'cases');
614
663
  }
@@ -667,4 +716,10 @@ export class TypstMarkupFunc extends TypstNode {
667
716
  queue.push(new TypstToken(TypstTokenType.LITERAL, ']'));
668
717
  return queue;
669
718
  }
719
+
720
+ public bottomTopTraversalTransform(transform: (node: TypstNode) => TypstNode): TypstNode {
721
+ const mf = new TypstMarkupFunc(this.head, this.fragments.map((n) => n.bottomTopTraversalTransform(transform)));
722
+ mf.options = this.options;
723
+ return transform(mf);
724
+ }
670
725
  }
package/dist/parser.js DELETED
@@ -1,23 +0,0 @@
1
- "use strict";class M{constructor(o,n,t=[]){this.type=o,this.value=n,this.args=t}}function U(l,o){Object.defineProperty(this,"name",{enumerable:!1,writable:!1,value:"JisonParserError"}),l==null&&(l="???"),Object.defineProperty(this,"message",{enumerable:!1,writable:!0,value:l}),this.hash=o;var n;if(o&&o.exception instanceof Error){var t=o.exception;this.message=t.message||l,n=t.stack}n||(Error.hasOwnProperty("captureStackTrace")?Error.captureStackTrace(this,this.constructor):n=new Error(l).stack),n&&Object.defineProperty(this,"stack",{enumerable:!1,writable:!1,value:n})}typeof Object.setPrototypeOf=="function"?Object.setPrototypeOf(U.prototype,Error.prototype):U.prototype=Object.create(Error.prototype),U.prototype.constructor=U,U.prototype.name="JisonParserError";function V(l){for(var o=[],n=l.pop,t=l.rule,i=0,r=n.length;i<r;i++)o.push([n[i],t[i]]);return o}function z(l){for(var o=[],n=l.len,t=l.symbol,i=l.type,r=l.state,s=l.mode,e=l.goto,h=0,_=n.length;h<_;h++){for(var v=n[h],u={},d=0;d<v;d++){var a=t.shift();switch(i.shift()){case 2:u[a]=[s.shift(),e.shift()];break;case 0:u[a]=r.shift();break;default:u[a]=[3]}}o.push(u)}return o}function g(l,o,n){n=n||0;for(var t=0;t<o;t++)this.push(l),l+=n}function T(l,o){for(l=this.length-l,o+=l;l<o;l++)this.push(this[l])}function N(l){for(var o=[],n=0,t=l.length;n<t;n++){var i=l[n];typeof i=="function"?(n++,i.apply(o,l[n])):o.push(i)}return o}var I={trace:function(){},JisonParserError:U,yy:{},options:{type:"lalr",hasPartialLrUpgradeOnConflict:!0,errorRecoveryTokenDiscardCount:3},symbols_:{$accept:0,$end:1,"*":5,"+":3,"-":4,"/":6,EOF:1,IDENTIFIER:7,NUMBER:8,error:2,expression:10,typinput:9},terminals_:{1:"EOF",2:"error",3:"+",4:"-",5:"*",6:"/",7:"IDENTIFIER",8:"NUMBER"},TERROR:2,EOF:1,originalQuoteName:null,originalParseError:null,cleanupAfterParse:null,constructParseErrorInfo:null,yyMergeLocationInfo:null,__reentrant_call_depth:0,__error_infos:[],__error_recovery_infos:[],quoteName:function(o){return'"'+o+'"'},getSymbolName:function(o){if(this.terminals_[o])return this.terminals_[o];var n=this.symbols_;for(var t in n)if(n[t]===o)return t;return null},describeSymbol:function(o){if(o!==this.EOF&&this.terminal_descriptions_&&this.terminal_descriptions_[o])return this.terminal_descriptions_[o];if(o===this.EOF)return"end of input";var n=this.getSymbolName(o);return n?this.quoteName(n):null},collect_expected_token_set:function(o,n){var t=this.TERROR,i=[],r={};if(!n&&this.state_descriptions_&&this.state_descriptions_[o])return[this.state_descriptions_[o]];for(var s in this.table[o])if(s=+s,s!==t){var e=n?s:this.describeSymbol(s);e&&!r[e]&&(i.push(e),r[e]=!0)}return i},productions_:V({pop:N([9,g,[10,6]]),rule:N([2,1,1,g,[3,4]])}),performAction:function(o,n,t){var i=this.yy,r=i.parser,s=i.lexer;switch(o){case 0:this.$=t[n-1];break;case 1:return this.$=t[n-1],t[n-1];break;case 2:this.$=new M("IDENTIFIER",t[n]);break;case 3:this.$=new M("NUMBER",t[n]);break;case 4:this.$=new M("ADD",t[n-1],[t[n-2],t[n]]);break;case 5:this.$=new M("SUB",t[n-1],[t[n-2],t[n]]);break;case 6:this.$=new M("MUL",t[n-1],[t[n-2],t[n]]);break;case 7:this.$=new M("DIV",t[n-1],[t[n-2],t[n]]);break}},table:z({len:N([4,1,5,g,[0,3],g,[3,4],5,T,[9,3]]),symbol:N([g,[7,4,1],1,1,g,[3,6,1],10,T,[3,9],T,[17,5],T,[5,5]]),type:N([2,2,0,0,1,g,[2,7],0,T,[3,11],g,[2,8]]),state:N([1,2,g,[10,4,1]]),mode:N([g,[1,15],g,[2,3],T,[5,7]]),goto:N([g,[3,7,1],3,4,3,4,T,[4,4],g,[4,3],8,9,g,[5,3],8,9])}),defaultActions:{3:2,4:3,5:1,12:6,13:7},parseError:function(o,n,t){if(n.recoverable)typeof this.trace=="function"&&this.trace(o),n.destroy();else throw typeof this.trace=="function"&&this.trace(o),t||(t=this.JisonParserError),new t(o,n)},parse:function(o){var n=this,t=new Array(128),i=new Array(128),r=new Array(128),s=this.table,e=0,h=0,_=this.TERROR,v=this.EOF,u=this.options.errorRecoveryTokenDiscardCount|0||3,d=[0,14],a;this.__lexer__?a=this.__lexer__:a=this.__lexer__=Object.create(this.lexer);var f={parseError:void 0,quoteName:void 0,lexer:void 0,parser:void 0,pre_parse:void 0,post_parse:void 0,pre_lex:void 0,post_lex:void 0},x;typeof assert!="function"?x=function(y,R){if(!y)throw new Error("assertion failed: "+(R||"***"))}:x=assert,this.yyGetSharedState=function(){return f};function j(c,y){for(var R in y)typeof c[R]>"u"&&Object.prototype.hasOwnProperty.call(y,R)&&(c[R]=y[R])}j(f,this.yy),f.lexer=a,f.parser=this,typeof f.parseError=="function"?this.parseError=function(y,R,w){return w||(w=this.JisonParserError),f.parseError.call(this,y,R,w)}:this.parseError=this.originalParseError,typeof f.quoteName=="function"?this.quoteName=function(y){return f.quoteName.call(this,y)}:this.quoteName=this.originalQuoteName,this.cleanupAfterParse=function(y,R,w){var A;if(R){var S;(f.post_parse||this.post_parse)&&(S=this.constructParseErrorInfo(null,null,null,!1)),f.post_parse&&(A=f.post_parse.call(this,f,y,S),typeof A<"u"&&(y=A)),this.post_parse&&(A=this.post_parse.call(this,f,y,S),typeof A<"u"&&(y=A)),S&&S.destroy&&S.destroy()}if(this.__reentrant_call_depth>1)return y;if(a.cleanupAfterLex&&a.cleanupAfterLex(w),f&&(f.lexer=void 0,f.parser=void 0,a.yy===f&&(a.yy=void 0)),f=void 0,this.parseError=this.originalParseError,this.quoteName=this.originalQuoteName,t.length=0,i.length=0,r.length=0,e=0,!w){for(var Y=this.__error_infos.length-1;Y>=0;Y--){var C=this.__error_infos[Y];C&&typeof C.destroy=="function"&&C.destroy()}this.__error_infos.length=0}return y},this.constructParseErrorInfo=function(y,R,w,A){var S={errStr:y,exception:R,text:a.match,value:a.yytext,token:this.describeSymbol(h)||h,token_id:h,line:a.yylineno,expected:w,recoverable:A,state:E,action:P,new_state:k,symbol_stack:t,state_stack:i,value_stack:r,stack_pointer:e,yy:f,lexer:a,parser:this,destroy:function(){var C=!!this.recoverable;for(var X in this)this.hasOwnProperty(X)&&typeof X=="object"&&(this[X]=void 0);this.recoverable=C}};return this.__error_infos.push(S),S};function q(c){var y=n.getSymbolName(c);return y||(y=c),y}function B(){var c=a.lex();return typeof c!="number"&&(c=n.symbols_[c]||c),c||v}function $(){var c=a.fastLex();return typeof c!="number"&&(c=n.symbols_[c]||c),c||v}var Q=B,E,P,p,F,L={$:!0,_$:void 0,yy:f},m,D,O,k,b=!1;try{if(this.__reentrant_call_depth++,a.setInput(o,f),typeof a.canIUse=="function"){var Z=a.canIUse();Z.fastLex&&typeof $=="function"&&(Q=$)}for(r[e]=null,i[e]=0,t[e]=0,++e,this.pre_parse&&this.pre_parse.call(this,f),f.pre_parse&&f.pre_parse.call(this,f),k=i[e-1];;){if(E=k,this.defaultActions[E])P=2,k=this.defaultActions[E];else if(h||(h=Q()),F=s[E]&&s[E][h]||d,k=F[1],P=F[0],!P){var J,W=this.describeSymbol(h)||h,G=this.collect_expected_token_set(E);typeof a.yylineno=="number"?J="Parse error on line "+(a.yylineno+1)+": ":J="Parse error: ",typeof a.showPosition=="function"&&(J+=`
2
- `+a.showPosition(69,10)+`
3
- `),G.length?J+="Expecting "+G.join(", ")+", got unexpected "+W:J+="Unexpected "+W,m=this.constructParseErrorInfo(J,null,G,!1),p=this.parseError(m.errStr,m,this.JisonParserError),typeof p<"u"&&(b=p);break}switch(P){default:if(P instanceof Array){m=this.constructParseErrorInfo("Parse Error: multiple actions possible at state: "+E+", token: "+h,null,null,!1),p=this.parseError(m.errStr,m,this.JisonParserError),typeof p<"u"&&(b=p);break}m=this.constructParseErrorInfo("Parsing halted. No viable error recovery approach available due to internal system failure.",null,null,!1),p=this.parseError(m.errStr,m,this.JisonParserError),typeof p<"u"&&(b=p);break;case 1:t[e]=h,r[e]=a.yytext,i[e]=k,++e,h=0;continue;case 2:if(O=this.productions_[k-1],D=O[1],p=this.performAction.call(L,k,e-1,r),typeof p<"u"){b=p;break}e-=D;var H=O[0];t[e]=H,r[e]=L.$,k=s[i[e-1]][H],i[e]=k,++e;continue;case 3:e!==-2&&(b=!0,e--,typeof r[e]<"u"&&(b=r[e]));break}break}}catch(c){if(c instanceof this.JisonParserError)throw c;if(a&&typeof a.JisonLexerError=="function"&&c instanceof a.JisonLexerError)throw c;m=this.constructParseErrorInfo("Parsing aborted due to exception.",c,null,!1),b=!1,p=this.parseError(m.errStr,m,this.JisonParserError),typeof p<"u"&&(b=p)}finally{b=this.cleanupAfterParse(b,!0,!0),this.__reentrant_call_depth--}return b}};I.originalParseError=I.parseError,I.originalQuoteName=I.quoteName;var tt=function(){function l(n,t){Object.defineProperty(this,"name",{enumerable:!1,writable:!1,value:"JisonLexerError"}),n==null&&(n="???"),Object.defineProperty(this,"message",{enumerable:!1,writable:!0,value:n}),this.hash=t;var i;if(t&&t.exception instanceof Error){var r=t.exception;this.message=r.message||n,i=r.stack}i||(Error.hasOwnProperty("captureStackTrace")?Error.captureStackTrace(this,this.constructor):i=new Error(n).stack),i&&Object.defineProperty(this,"stack",{enumerable:!1,writable:!1,value:i})}typeof Object.setPrototypeOf=="function"?Object.setPrototypeOf(l.prototype,Error.prototype):l.prototype=Object.create(Error.prototype),l.prototype.constructor=l,l.prototype.name="JisonLexerError";var o={EOF:1,ERROR:2,__currentRuleSet__:null,__error_infos:[],__decompressed:!1,done:!1,_backtrack:!1,_input:"",_more:!1,_signaled_error_token:!1,conditionStack:[],match:"",matched:"",matches:!1,yytext:"",offset:0,yyleng:0,yylineno:0,yylloc:null,constructLexErrorInfo:function(t,i,r){if(t=""+t,r==null&&(r=!(t.indexOf(`
4
- `)>0&&t.indexOf("^")>0)),this.yylloc&&r){if(typeof this.prettyPrintRange=="function"){var s=this.prettyPrintRange(this.yylloc);/\n\s*$/.test(t)||(t+=`
5
- `),t+=`
6
- Erroneous area:
7
- `+this.prettyPrintRange(this.yylloc)}else if(typeof this.showPosition=="function"){var e=this.showPosition();e&&(t.length&&t[t.length-1]!==`
8
- `&&e[0]!==`
9
- `?t+=`
10
- `+e:t+=e)}}var h={errStr:t,recoverable:!!i,text:this.match,token:null,line:this.yylineno,loc:this.yylloc,yy:this.yy,lexer:this,destroy:function(){var v=!!this.recoverable;for(var u in this)this.hasOwnProperty(u)&&typeof u=="object"&&(this[u]=void 0);this.recoverable=v}};return this.__error_infos.push(h),h},parseError:function(t,i,r){if(r||(r=this.JisonLexerError),this.yy){if(this.yy.parser&&typeof this.yy.parser.parseError=="function")return this.yy.parser.parseError.call(this,t,i,r)||this.ERROR;if(typeof this.yy.parseError=="function")return this.yy.parseError.call(this,t,i,r)||this.ERROR}throw new r(t,i)},yyerror:function(t){var i="";this.yylloc&&(i=" on line "+(this.yylineno+1));var r=this.constructLexErrorInfo("Lexical error"+i+": "+t,this.options.lexerErrorsAreRecoverable),s=Array.prototype.slice.call(arguments,1);return s.length&&(r.extra_error_attributes=s),this.parseError(r.errStr,r,this.JisonLexerError)||this.ERROR},cleanupAfterLex:function(t){if(this.setInput("",{}),!t){for(var i=this.__error_infos.length-1;i>=0;i--){var r=this.__error_infos[i];r&&typeof r.destroy=="function"&&r.destroy()}this.__error_infos.length=0}return this},clear:function(){this.yytext="",this.yyleng=0,this.match="",this.matches=!1,this._more=!1,this._backtrack=!1;var t=this.yylloc?this.yylloc.last_column:0;this.yylloc={first_line:this.yylineno+1,first_column:t,last_line:this.yylineno+1,last_column:t,range:[this.offset,this.offset]}},setInput:function(t,i){if(this.yy=i||this.yy||{},!this.__decompressed){for(var r=this.rules,s=0,e=r.length;s<e;s++){var h=r[s];typeof h=="number"&&(r[s]=r[h])}var _=this.conditions;for(var v in _){for(var u=_[v],d=u.rules,e=d.length,a=new Array(e+1),f=new Array(e+1),s=0;s<e;s++){var x=d[s],h=r[x];a[s+1]=h,f[s+1]=x}u.rules=f,u.__rule_regexes=a,u.__rule_count=e}this.__decompressed=!0}return this._input=t||"",this.clear(),this._signaled_error_token=!1,this.done=!1,this.yylineno=0,this.matched="",this.conditionStack=["INITIAL"],this.__currentRuleSet__=null,this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0,range:[0,0]},this.offset=0,this},editRemainingInput:function(t,i){var r=t.call(this,this._input,i);return typeof r!="string"?r&&(this._input=""+r):this._input=r,this},input:function(){if(!this._input)return null;var t=this._input[0];this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t;var i=1,r=!1;if(t===`
11
- `)r=!0;else if(t==="\r"){r=!0;var s=this._input[1];s===`
12
- `&&(i++,t+=s,this.yytext+=s,this.yyleng++,this.offset++,this.match+=s,this.matched+=s,this.yylloc.range[1]++)}return r?(this.yylineno++,this.yylloc.last_line++,this.yylloc.last_column=0):this.yylloc.last_column++,this.yylloc.range[1]++,this._input=this._input.slice(i),t},unput:function(t){var i=t.length,r=t.split(/(?:\r\n?|\n)/g);if(this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-i),this.yyleng=this.yytext.length,this.offset-=i,this.match=this.match.substr(0,this.match.length-i),this.matched=this.matched.substr(0,this.matched.length-i),r.length>1){this.yylineno-=r.length-1,this.yylloc.last_line=this.yylineno+1;var s=this.match,e=s.split(/(?:\r\n?|\n)/g);e.length===1&&(s=this.matched,e=s.split(/(?:\r\n?|\n)/g)),this.yylloc.last_column=e[e.length-1].length}else this.yylloc.last_column-=i;return this.yylloc.range[1]=this.yylloc.range[0]+this.yyleng,this.done=!1,this},more:function(){return this._more=!0,this},reject:function(){if(this.options.backtrack_lexer)this._backtrack=!0;else{var t="";this.yylloc&&(t=" on line "+(this.yylineno+1));var i=this.constructLexErrorInfo("Lexical error"+t+": You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).",!1);this._signaled_error_token=this.parseError(i.errStr,i,this.JisonLexerError)||this.ERROR}return this},less:function(t){return this.unput(this.match.slice(t))},pastInput:function(t,i){var r=this.matched.substring(0,this.matched.length-this.match.length);t<0?t=r.length:t||(t=20),i<0?i=r.length:i||(i=1),r=r.substr(-t*2-2);var s=r.replace(/\r\n|\r/g,`
13
- `).split(`
14
- `);return s=s.slice(-i),r=s.join(`
15
- `),r.length>t&&(r="..."+r.substr(-t)),r},upcomingInput:function(t,i){var r=this.match;t<0?t=r.length+this._input.length:t||(t=20),i<0?i=t:i||(i=1),r.length<t*2+2&&(r+=this._input.substring(0,t*2+2));var s=r.replace(/\r\n|\r/g,`
16
- `).split(`
17
- `);return s=s.slice(0,i),r=s.join(`
18
- `),r.length>t&&(r=r.substring(0,t)+"..."),r},showPosition:function(t,i){var r=this.pastInput(t).replace(/\s/g," "),s=new Array(r.length+1).join("-");return r+this.upcomingInput(i).replace(/\s/g," ")+`
19
- `+s+"^"},deriveLocationInfo:function(t,i,r,s){var e={first_line:1,first_column:0,last_line:1,last_column:0,range:[0,0]};return t&&(e.first_line=t.first_line|0,e.last_line=t.last_line|0,e.first_column=t.first_column|0,e.last_column=t.last_column|0,t.range&&(e.range[0]=t.range[0]|0,e.range[1]=t.range[1]|0)),(e.first_line<=0||e.last_line<e.first_line)&&(e.first_line<=0&&i&&(e.first_line=i.last_line|0,e.first_column=i.last_column|0,i.range&&(e.range[0]=t.range[1]|0)),(e.last_line<=0||e.last_line<e.first_line)&&r&&(e.last_line=r.first_line|0,e.last_column=r.first_column|0,r.range&&(e.range[1]=t.range[0]|0)),e.first_line<=0&&s&&(e.last_line<=0||s.last_line<=e.last_line)&&(e.first_line=s.first_line|0,e.first_column=s.first_column|0,s.range&&(e.range[0]=s.range[0]|0)),e.last_line<=0&&s&&(e.first_line<=0||s.first_line>=e.first_line)&&(e.last_line=s.last_line|0,e.last_column=s.last_column|0,s.range&&(e.range[1]=s.range[1]|0))),e.last_line<=0&&(e.first_line<=0?(e.first_line=this.yylloc.first_line,e.last_line=this.yylloc.last_line,e.first_column=this.yylloc.first_column,e.last_column=this.yylloc.last_column,e.range[0]=this.yylloc.range[0],e.range[1]=this.yylloc.range[1]):(e.last_line=this.yylloc.last_line,e.last_column=this.yylloc.last_column,e.range[1]=this.yylloc.range[1])),e.first_line<=0&&(e.first_line=e.last_line,e.first_column=0,e.range[1]=e.range[0]),e.first_column<0&&(e.first_column=0),e.last_column<0&&(e.last_column=e.first_column>0?e.first_column:80),e},prettyPrintRange:function(t,i,r){t=this.deriveLocationInfo(t,i,r);const s=3,e=1,h=2;var _=this.matched+this._input,v=_.split(`
20
- `),u=Math.max(1,i?i.first_line:t.first_line-s),d=Math.max(1,r?r.last_line:t.last_line+e),a=1+Math.log10(d|1)|0,f=new Array(a).join(" "),x=[],j=v.slice(u-1,d+1).map(function(E,P){var p=P+u,F=(f+p).substr(-a),L=F+": "+E,m=new Array(a+1).join("^"),D=3,O=0;if(p===t.first_line?(D+=t.first_column,O=Math.max(2,(p===t.last_line?t.last_column:E.length)-t.first_column+1)):p===t.last_line?O=Math.max(2,t.last_column+1):p>t.first_line&&p<t.last_line&&(O=Math.max(2,E.length+1)),O){var k=new Array(D).join("."),b=new Array(O).join("^");L+=`
21
- `+m+k+b,E.trim().length>0&&x.push(P)}return L=L.replace(/\t/g," "),L});if(x.length>2*h){var q=x[h-1]+1,B=x[x.length-h]-1,$=new Array(a+1).join(" ")+" (...continued...)";$+=`
22
- `+new Array(a+1).join("-")+" (---------------)",j.splice(q,B-q+1,$)}return j.join(`
23
- `)},describeYYLLOC:function(t,i){var r=t.first_line,s=t.last_line,e=t.first_column,h=t.last_column,_=s-r,v=h-e,u;if(_===0?(u="line "+r+", ",v<=1?u+="column "+e:u+="columns "+e+" .. "+h):u="lines "+r+"(column "+e+") .. "+s+"(column "+h+")",t.range&&i){var d=t.range[0],a=t.range[1]-1;a<=d?u+=" {String Offset: "+d+"}":u+=" {String Offset range: "+d+" .. "+a+"}"}return u},test_match:function(t,i){var r,s,e,h,_;if(this.options.backtrack_lexer&&(e={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.yylloc.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column,range:this.yylloc.range.slice(0)},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done}),h=t[0],_=h.length,s=h.split(/(?:\r\n?|\n)/g),s.length>1?(this.yylineno+=s.length-1,this.yylloc.last_line=this.yylineno+1,this.yylloc.last_column=s[s.length-1].length):this.yylloc.last_column+=_,this.yytext+=h,this.match+=h,this.matched+=h,this.matches=t,this.yyleng=this.yytext.length,this.yylloc.range[1]+=_,this.offset+=_,this._more=!1,this._backtrack=!1,this._input=this._input.slice(_),r=this.performAction.call(this,this.yy,i,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),r)return r;if(this._backtrack){for(var v in e)this[v]=e[v];return this.__currentRuleSet__=null,!1}else if(this._signaled_error_token)return r=this._signaled_error_token,this._signaled_error_token=!1,r;return!1},next:function(){if(this.done)return this.clear(),this.EOF;this._input||(this.done=!0);var t,i,r,s;this._more||this.clear();var e=this.__currentRuleSet__;if(!e&&(e=this.__currentRuleSet__=this._currentRules(),!e||!e.rules)){var h="";this.options.trackPosition&&(h=" on line "+(this.yylineno+1));var _=this.constructLexErrorInfo("Internal lexer engine error"+h+': The lex grammar programmer pushed a non-existing condition name "'+this.topState()+'"; this is a fatal error and should be reported to the application programmer team!',!1);return this.parseError(_.errStr,_,this.JisonLexerError)||this.ERROR}for(var v=e.rules,u=e.__rule_regexes,d=e.__rule_count,a=1;a<=d;a++)if(r=this._input.match(u[a]),r&&(!i||r[0].length>i[0].length)){if(i=r,s=a,this.options.backtrack_lexer){if(t=this.test_match(r,v[a]),t!==!1)return t;if(this._backtrack){i=void 0;continue}else return!1}else if(!this.options.flex)break}if(i)return t=this.test_match(i,v[s]),t!==!1?t:!1;if(this._input){var h="";this.options.trackPosition&&(h=" on line "+(this.yylineno+1));var _=this.constructLexErrorInfo("Lexical error"+h+": Unrecognized text.",this.options.lexerErrorsAreRecoverable),f=this._input,x=this.topState(),j=this.conditionStack.length;return t=this.parseError(_.errStr,_,this.JisonLexerError)||this.ERROR,t===this.ERROR&&!this.matches&&f===this._input&&x===this.topState()&&j===this.conditionStack.length&&this.input(),t}else return this.done=!0,this.clear(),this.EOF},lex:function(){var t;for(typeof this.pre_lex=="function"&&(t=this.pre_lex.call(this,0)),typeof this.options.pre_lex=="function"&&(t=this.options.pre_lex.call(this,t)||t),this.yy&&typeof this.yy.pre_lex=="function"&&(t=this.yy.pre_lex.call(this,t)||t);!t;)t=this.next();return this.yy&&typeof this.yy.post_lex=="function"&&(t=this.yy.post_lex.call(this,t)||t),typeof this.options.post_lex=="function"&&(t=this.options.post_lex.call(this,t)||t),typeof this.post_lex=="function"&&(t=this.post_lex.call(this,t)||t),t},fastLex:function(){for(var t;!t;)t=this.next();return t},canIUse:function(){var t={fastLex:!(typeof this.pre_lex=="function"||typeof this.options.pre_lex=="function"||this.yy&&typeof this.yy.pre_lex=="function"||this.yy&&typeof this.yy.post_lex=="function"||typeof this.options.post_lex=="function"||typeof this.post_lex=="function")&&typeof this.fastLex=="function"};return t},begin:function(t){return this.pushState(t)},pushState:function(t){return this.conditionStack.push(t),this.__currentRuleSet__=null,this},popState:function(){var t=this.conditionStack.length-1;return t>0?(this.__currentRuleSet__=null,this.conditionStack.pop()):this.conditionStack[0]},topState:function(t){return t=this.conditionStack.length-1-Math.abs(t||0),t>=0?this.conditionStack[t]:"INITIAL"},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]]:this.conditions.INITIAL},stateStackSize:function(){return this.conditionStack.length},options:{trackPosition:!0},JisonLexerError:l,performAction:function(t,i,r){var s=this,e=r;switch(i){case 0:break;default:return this.simpleCaseActionClusters[i]}},simpleCaseActionClusters:{1:8,2:5,3:6,4:3,5:4,6:7,7:1,8:"INVALID"},rules:[/^(?:\s+)/,/^(?:\d+(\.\d+)?\b)/,/^(?:\*)/,/^(?:\/)/,/^(?:\+)/,/^(?:-)/,/^(?:[^\W\d]+)/,/^(?:$)/,/^(?:.)/],conditions:{INITIAL:{rules:[0,1,2,3,4,5,6,7,8],inclusive:!0}}};return o}();I.lexer=tt;function K(){this.yy={}}K.prototype=I,I.Parser=K;function et(){return I.parse.apply(I,arguments)}export default{parser:I,Parser:K,parse:et};