@khanacademy/kas 0.2.3

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.
@@ -0,0 +1,840 @@
1
+ // This is a @generated file
2
+ import _ from "underscore";
3
+
4
+ /* parser generated by jison 0.4.15 */
5
+ /*
6
+ Returns a Parser object of the following structure:
7
+
8
+ Parser: {
9
+ yy: {}
10
+ }
11
+
12
+ Parser.prototype: {
13
+ yy: {},
14
+ trace: function(),
15
+ symbols_: {associative list: name ==> number},
16
+ terminals_: {associative list: number ==> name},
17
+ productions_: [...],
18
+ performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$),
19
+ table: [...],
20
+ defaultActions: {...},
21
+ parseError: function(str, hash),
22
+ parse: function(input),
23
+
24
+ lexer: {
25
+ EOF: 1,
26
+ parseError: function(str, hash),
27
+ setInput: function(input),
28
+ input: function(),
29
+ unput: function(str),
30
+ more: function(),
31
+ less: function(n),
32
+ pastInput: function(),
33
+ upcomingInput: function(),
34
+ showPosition: function(),
35
+ test_match: function(regex_match_array, rule_index),
36
+ next: function(),
37
+ lex: function(),
38
+ begin: function(condition),
39
+ popState: function(),
40
+ _currentRules: function(),
41
+ topState: function(),
42
+ pushState: function(condition),
43
+
44
+ options: {
45
+ ranges: boolean (optional: true ==> token location info will include a .range[] member)
46
+ flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match)
47
+ backtrack_lexer: boolean (optional: true ==> lexer regexes are tested in order and for each matching regex the action code is invoked; the lexer terminates the scan when a token is returned by the action code)
48
+ },
49
+
50
+ performAction: function(yy, yy_, $avoiding_name_collisions, YY_START),
51
+ rules: [...],
52
+ conditions: {associative list: name ==> set},
53
+ }
54
+ }
55
+
56
+
57
+ token location info (@$, _$, etc.): {
58
+ first_line: n,
59
+ last_line: n,
60
+ first_column: n,
61
+ last_column: n,
62
+ range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based)
63
+ }
64
+
65
+
66
+ the parseError function receives a 'hash' object with these members for lexer and parser errors: {
67
+ text: (matched text)
68
+ token: (the produced terminal token, if any)
69
+ line: (yylineno)
70
+ }
71
+ while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: {
72
+ loc: (yylloc)
73
+ expected: (string describing the set of expected tokens)
74
+ recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error)
75
+ }
76
+ */
77
+ var parser = (function(){
78
+ var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[1,7],$V1=[1,17],$V2=[1,13],$V3=[1,14],$V4=[1,15],$V5=[1,32],$V6=[1,22],$V7=[1,23],$V8=[1,24],$V9=[1,25],$Va=[1,26],$Vb=[1,33],$Vc=[1,27],$Vd=[1,28],$Ve=[1,29],$Vf=[1,30],$Vg=[1,20],$Vh=[1,36],$Vi=[1,37],$Vj=[5,6,8,10,33,35,41,43,45],$Vk=[1,39],$Vl=[1,40],$Vm=[5,6,8,10,12,14,16,19,21,22,28,29,30,31,32,33,34,35,37,39,41,42,43,44,45,46],$Vn=[10,16,19,21,22,28,29,30,31,32,34,37,39,42,43,44,46],$Vo=[5,6,8,10,12,14,16,18,19,21,22,28,29,30,31,32,33,34,35,37,39,41,42,43,44,45,46];
79
+ var parser = {trace: function trace () { },
80
+ yy: {},
81
+ symbols_: {"error":2,"equation":3,"expression":4,"SIGN":5,"EOF":6,"additive":7,"+":8,"multiplicative":9,"-":10,"triglog":11,"*":12,"negative":13,"/":14,"trig":15,"TRIG":16,"trigfunc":17,"^":18,"TRIGINV":19,"logbase":20,"ln":21,"log":22,"_":23,"subscriptable":24,"power":25,"primitive":26,"variable":27,"VAR":28,"CONST":29,"INT":30,"FLOAT":31,"{":32,"}":33,"(":34,")":35,"function":36,"FUNC":37,"invocation":38,"sqrt":39,"[":40,"]":41,"abs":42,"|":43,"LEFT|":44,"RIGHT|":45,"FRAC":46,"$accept":0,"$end":1},
82
+ terminals_: {2:"error",5:"SIGN",6:"EOF",8:"+",10:"-",12:"*",14:"/",16:"TRIG",18:"^",19:"TRIGINV",21:"ln",22:"log",23:"_",28:"VAR",29:"CONST",30:"INT",31:"FLOAT",32:"{",33:"}",34:"(",35:")",37:"FUNC",39:"sqrt",40:"[",41:"]",42:"abs",43:"|",44:"LEFT|",45:"RIGHT|",46:"FRAC"},
83
+ productions_: [0,[3,4],[3,2],[3,1],[4,1],[7,3],[7,3],[7,1],[9,2],[9,3],[9,3],[9,1],[13,2],[13,1],[15,1],[17,1],[17,3],[17,1],[20,1],[20,1],[20,3],[11,2],[11,2],[11,1],[25,3],[25,1],[27,1],[24,3],[24,1],[24,1],[24,1],[24,1],[24,3],[24,3],[36,1],[38,4],[38,4],[38,7],[38,4],[38,3],[38,3],[38,4],[26,1],[26,1],[26,7]],
84
+ performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) {
85
+ /* this == yyval */
86
+
87
+ var $0 = $$.length - 1;
88
+ switch (yystate) {
89
+ case 1:
90
+ return new yy.Eq($$[$0-3], $$[$0-2], $$[$0-1]);
91
+ break;
92
+ case 2:
93
+ return $$[$0-1];
94
+ break;
95
+ case 3:
96
+ return new yy.Add([]);
97
+ break;
98
+ case 4: case 7: case 11: case 13: case 15: case 20: case 23: case 25: case 42: case 43:
99
+ this.$ = $$[$0];
100
+ break;
101
+ case 5:
102
+ this.$ = yy.Add.createOrAppend($$[$0-2], $$[$0]);
103
+ break;
104
+ case 6:
105
+ this.$ = yy.Add.createOrAppend($$[$0-2], yy.Mul.handleNegative($$[$0], "subtract"));
106
+ break;
107
+ case 8:
108
+ this.$ = yy.Mul.fold(yy.Mul.createOrAppend($$[$0-1], $$[$0]));
109
+ break;
110
+ case 9:
111
+ this.$ = yy.Mul.fold(yy.Mul.createOrAppend($$[$0-2], $$[$0]));
112
+ break;
113
+ case 10:
114
+ this.$ = yy.Mul.fold(yy.Mul.handleDivide($$[$0-2], $$[$0]));
115
+ break;
116
+ case 12:
117
+ this.$ = yy.Mul.handleNegative($$[$0]);
118
+ break;
119
+ case 14: case 17:
120
+ this.$ = [yytext];
121
+ break;
122
+ case 16:
123
+ this.$ = $$[$0-2].concat($$[$0]);
124
+ break;
125
+ case 18:
126
+ this.$ = yy.Log.natural();
127
+ break;
128
+ case 19:
129
+ this.$ = yy.Log.common();
130
+ break;
131
+ case 21:
132
+ this.$ = yy.Trig.create($$[$0-1], $$[$0]);
133
+ break;
134
+ case 22:
135
+ this.$ = yy.Log.create($$[$0-1], $$[$0]);
136
+ break;
137
+ case 24:
138
+ this.$ = new yy.Pow($$[$0-2], $$[$0]);
139
+ break;
140
+ case 26: case 34:
141
+ this.$ = yytext;
142
+ break;
143
+ case 27:
144
+ this.$ = new yy.Var($$[$0-2], $$[$0]);
145
+ break;
146
+ case 28:
147
+ this.$ = new yy.Var($$[$0]);
148
+ break;
149
+ case 29:
150
+ this.$ = new yy.Const(yytext.toLowerCase());
151
+ break;
152
+ case 30:
153
+ this.$ = yy.Int.create(Number(yytext));
154
+ break;
155
+ case 31:
156
+ this.$ = yy.Float.create(Number(yytext));
157
+ break;
158
+ case 32:
159
+ this.$ = $$[$0-1].completeParse();
160
+ break;
161
+ case 33:
162
+ this.$ = $$[$0-1].completeParse().addHint('parens');
163
+ break;
164
+ case 35: case 36:
165
+ this.$ = yy.Pow.sqrt($$[$0-1]);
166
+ break;
167
+ case 37:
168
+ this.$ = new yy.Pow.nthroot($$[$0-1], $$[$0-4]);
169
+ break;
170
+ case 38: case 39: case 40:
171
+ this.$ = new yy.Abs($$[$0-1]);
172
+ break;
173
+ case 41:
174
+ this.$ = new yy.Func($$[$0-3], $$[$0-1]);
175
+ break;
176
+ case 44:
177
+ this.$ = yy.Mul.handleDivide($$[$0-4], $$[$0-1]);
178
+ break;
179
+ }
180
+ },
181
+ table: [{3:1,4:2,6:[1,3],7:4,9:5,10:$V0,11:8,13:6,15:12,16:$V1,17:9,19:$V2,20:10,21:$V3,22:$V4,24:18,25:11,26:16,27:21,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,36:31,37:$Vb,38:19,39:$Vc,42:$Vd,43:$Ve,44:$Vf,46:$Vg},{1:[3]},{5:[1,34],6:[1,35]},{1:[2,3]},o([5,6],[2,4],{8:$Vh,10:$Vi}),o($Vj,[2,7],{17:9,20:10,25:11,15:12,26:16,24:18,38:19,27:21,36:31,11:38,12:$Vk,14:$Vl,16:$V1,19:$V2,21:$V3,22:$V4,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,37:$Vb,39:$Vc,42:$Vd,44:$Vf,46:$Vg}),o($Vm,[2,11]),{10:$V0,11:8,13:41,15:12,16:$V1,17:9,19:$V2,20:10,21:$V3,22:$V4,24:18,25:11,26:16,27:21,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,36:31,37:$Vb,38:19,39:$Vc,42:$Vd,43:$Ve,44:$Vf,46:$Vg},o($Vm,[2,13]),{10:$V0,11:8,13:42,15:12,16:$V1,17:9,19:$V2,20:10,21:$V3,22:$V4,24:18,25:11,26:16,27:21,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,36:31,37:$Vb,38:19,39:$Vc,42:$Vd,43:$Ve,44:$Vf,46:$Vg},{10:$V0,11:8,13:43,15:12,16:$V1,17:9,19:$V2,20:10,21:$V3,22:$V4,24:18,25:11,26:16,27:21,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,36:31,37:$Vb,38:19,39:$Vc,42:$Vd,43:$Ve,44:$Vf,46:$Vg},o($Vm,[2,23]),o($Vn,[2,15],{18:[1,44]}),o($Vn,[2,17]),o($Vn,[2,18]),o($Vn,[2,19],{23:[1,45]}),o($Vm,[2,25],{18:[1,46]}),o([10,16,18,19,21,22,28,29,30,31,32,34,37,39,42,43,44,46],[2,14]),o($Vo,[2,42]),o($Vo,[2,43]),{32:[1,47]},o($Vo,[2,28],{23:[1,48]}),o($Vo,[2,29]),o($Vo,[2,30]),o($Vo,[2,31]),{7:49,9:5,10:$V0,11:8,13:6,15:12,16:$V1,17:9,19:$V2,20:10,21:$V3,22:$V4,24:18,25:11,26:16,27:21,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,36:31,37:$Vb,38:19,39:$Vc,42:$Vd,43:$Ve,44:$Vf,46:$Vg},{7:50,9:5,10:$V0,11:8,13:6,15:12,16:$V1,17:9,19:$V2,20:10,21:$V3,22:$V4,24:18,25:11,26:16,27:21,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,36:31,37:$Vb,38:19,39:$Vc,42:$Vd,43:$Ve,44:$Vf,46:$Vg},{32:[1,52],34:[1,51],40:[1,53]},{34:[1,54]},{7:55,9:5,10:$V0,11:8,13:6,15:12,16:$V1,17:9,19:$V2,20:10,21:$V3,22:$V4,24:18,25:11,26:16,27:21,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,36:31,37:$Vb,38:19,39:$Vc,42:$Vd,43:$Ve,44:$Vf,46:$Vg},{7:56,9:5,10:$V0,11:8,13:6,15:12,16:$V1,17:9,19:$V2,20:10,21:$V3,22:$V4,24:18,25:11,26:16,27:21,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,36:31,37:$Vb,38:19,39:$Vc,42:$Vd,43:$Ve,44:$Vf,46:$Vg},{34:[1,57]},o([5,6,8,10,12,14,16,18,19,21,22,23,28,29,30,31,32,33,34,35,37,39,41,42,43,44,45,46],[2,26]),{34:[2,34]},{4:58,7:4,9:5,10:$V0,11:8,13:6,15:12,16:$V1,17:9,19:$V2,20:10,21:$V3,22:$V4,24:18,25:11,26:16,27:21,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,36:31,37:$Vb,38:19,39:$Vc,42:$Vd,43:$Ve,44:$Vf,46:$Vg},{1:[2,2]},{9:59,10:$V0,11:8,13:6,15:12,16:$V1,17:9,19:$V2,20:10,21:$V3,22:$V4,24:18,25:11,26:16,27:21,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,36:31,37:$Vb,38:19,39:$Vc,42:$Vd,43:$Ve,44:$Vf,46:$Vg},{9:60,10:$V0,11:8,13:6,15:12,16:$V1,17:9,19:$V2,20:10,21:$V3,22:$V4,24:18,25:11,26:16,27:21,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,36:31,37:$Vb,38:19,39:$Vc,42:$Vd,43:$Ve,44:$Vf,46:$Vg},o($Vm,[2,8]),{10:$V0,11:8,13:61,15:12,16:$V1,17:9,19:$V2,20:10,21:$V3,22:$V4,24:18,25:11,26:16,27:21,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,36:31,37:$Vb,38:19,39:$Vc,42:$Vd,43:$Ve,44:$Vf,46:$Vg},{10:$V0,11:8,13:62,15:12,16:$V1,17:9,19:$V2,20:10,21:$V3,22:$V4,24:18,25:11,26:16,27:21,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,36:31,37:$Vb,38:19,39:$Vc,42:$Vd,43:$Ve,44:$Vf,46:$Vg},o($Vm,[2,12]),o($Vm,[2,21]),o($Vm,[2,22]),{10:$V0,11:8,13:63,15:12,16:$V1,17:9,19:$V2,20:10,21:$V3,22:$V4,24:18,25:11,26:16,27:21,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,36:31,37:$Vb,38:19,39:$Vc,42:$Vd,43:$Ve,44:$Vf,46:$Vg},{24:64,27:21,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va},{10:$V0,11:8,13:65,15:12,16:$V1,17:9,19:$V2,20:10,21:$V3,22:$V4,24:18,25:11,26:16,27:21,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,36:31,37:$Vb,38:19,39:$Vc,42:$Vd,43:$Ve,44:$Vf,46:$Vg},{7:66,9:5,10:$V0,11:8,13:6,15:12,16:$V1,17:9,19:$V2,20:10,21:$V3,22:$V4,24:18,25:11,26:16,27:21,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,36:31,37:$Vb,38:19,39:$Vc,42:$Vd,43:$Ve,44:$Vf,46:$Vg},{24:67,27:21,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va},{8:$Vh,10:$Vi,33:[1,68]},{8:$Vh,10:$Vi,35:[1,69]},{7:70,9:5,10:$V0,11:8,13:6,15:12,16:$V1,17:9,19:$V2,20:10,21:$V3,22:$V4,24:18,25:11,26:16,27:21,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,36:31,37:$Vb,38:19,39:$Vc,42:$Vd,43:$Ve,44:$Vf,46:$Vg},{7:71,9:5,10:$V0,11:8,13:6,15:12,16:$V1,17:9,19:$V2,20:10,21:$V3,22:$V4,24:18,25:11,26:16,27:21,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,36:31,37:$Vb,38:19,39:$Vc,42:$Vd,43:$Ve,44:$Vf,46:$Vg},{7:72,9:5,10:$V0,11:8,13:6,15:12,16:$V1,17:9,19:$V2,20:10,21:$V3,22:$V4,24:18,25:11,26:16,27:21,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,36:31,37:$Vb,38:19,39:$Vc,42:$Vd,43:$Ve,44:$Vf,46:$Vg},{7:73,9:5,10:$V0,11:8,13:6,15:12,16:$V1,17:9,19:$V2,20:10,21:$V3,22:$V4,24:18,25:11,26:16,27:21,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,36:31,37:$Vb,38:19,39:$Vc,42:$Vd,43:$Ve,44:$Vf,46:$Vg},{8:$Vh,10:$Vi,43:[1,74]},{8:$Vh,10:$Vi,45:[1,75]},{7:76,9:5,10:$V0,11:8,13:6,15:12,16:$V1,17:9,19:$V2,20:10,21:$V3,22:$V4,24:18,25:11,26:16,27:21,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,36:31,37:$Vb,38:19,39:$Vc,42:$Vd,43:$Ve,44:$Vf,46:$Vg},{6:[1,77]},o($Vj,[2,5],{17:9,20:10,25:11,15:12,26:16,24:18,38:19,27:21,36:31,11:38,12:$Vk,14:$Vl,16:$V1,19:$V2,21:$V3,22:$V4,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,37:$Vb,39:$Vc,42:$Vd,44:$Vf,46:$Vg}),o($Vj,[2,6],{17:9,20:10,25:11,15:12,26:16,24:18,38:19,27:21,36:31,11:38,12:$Vk,14:$Vl,16:$V1,19:$V2,21:$V3,22:$V4,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,37:$Vb,39:$Vc,42:$Vd,44:$Vf,46:$Vg}),o($Vm,[2,9]),o($Vm,[2,10]),o($Vn,[2,16]),o($Vn,[2,20]),o($Vm,[2,24]),{8:$Vh,10:$Vi,33:[1,78]},o($Vo,[2,27]),o($Vo,[2,32]),o($Vo,[2,33]),{8:$Vh,10:$Vi,35:[1,79]},{8:$Vh,10:$Vi,33:[1,80]},{8:$Vh,10:$Vi,41:[1,81]},{8:$Vh,10:$Vi,35:[1,82]},o($Vo,[2,39]),o($Vo,[2,40]),{8:$Vh,10:$Vi,35:[1,83]},{1:[2,1]},{32:[1,84]},o($Vo,[2,35]),o($Vo,[2,36]),{32:[1,85]},o($Vo,[2,38]),o($Vo,[2,41]),{7:86,9:5,10:$V0,11:8,13:6,15:12,16:$V1,17:9,19:$V2,20:10,21:$V3,22:$V4,24:18,25:11,26:16,27:21,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,36:31,37:$Vb,38:19,39:$Vc,42:$Vd,43:$Ve,44:$Vf,46:$Vg},{7:87,9:5,10:$V0,11:8,13:6,15:12,16:$V1,17:9,19:$V2,20:10,21:$V3,22:$V4,24:18,25:11,26:16,27:21,28:$V5,29:$V6,30:$V7,31:$V8,32:$V9,34:$Va,36:31,37:$Vb,38:19,39:$Vc,42:$Vd,43:$Ve,44:$Vf,46:$Vg},{8:$Vh,10:$Vi,33:[1,88]},{8:$Vh,10:$Vi,33:[1,89]},o($Vo,[2,44]),o($Vo,[2,37])],
182
+ defaultActions: {3:[2,3],33:[2,34],35:[2,2],77:[2,1]},
183
+ parseError: function parseError (str, hash) {
184
+ if (hash.recoverable) {
185
+ this.trace(str);
186
+ } else {
187
+ throw new Error(str);
188
+ }
189
+ },
190
+ parse: function parse(input) {
191
+ var self = this, stack = [0], tstack = [], vstack = [null], lstack = [], table = this.table, yytext = '', yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1;
192
+ var args = lstack.slice.call(arguments, 1);
193
+ var lexer = Object.create(this.lexer);
194
+ var sharedState = { yy: {} };
195
+ for (var k in this.yy) {
196
+ if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
197
+ sharedState.yy[k] = this.yy[k];
198
+ }
199
+ }
200
+ lexer.setInput(input, sharedState.yy);
201
+ sharedState.yy.lexer = lexer;
202
+ sharedState.yy.parser = this;
203
+ if (typeof lexer.yylloc == 'undefined') {
204
+ lexer.yylloc = {};
205
+ }
206
+ var yyloc = lexer.yylloc;
207
+ lstack.push(yyloc);
208
+ var ranges = lexer.options && lexer.options.ranges;
209
+ if (typeof sharedState.yy.parseError === 'function') {
210
+ this.parseError = sharedState.yy.parseError;
211
+ } else {
212
+ this.parseError = Object.getPrototypeOf(this).parseError;
213
+ }
214
+ function popStack(n) {
215
+ stack.length = stack.length - 2 * n;
216
+ vstack.length = vstack.length - n;
217
+ lstack.length = lstack.length - n;
218
+ }
219
+ //_token_stack:
220
+ function lex() {
221
+ var token;
222
+ token = lexer.lex() || EOF;
223
+ if (typeof token !== 'number') {
224
+ token = self.symbols_[token] || token;
225
+ }
226
+ return token;
227
+ }
228
+ var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected;
229
+ while (true) {
230
+ state = stack[stack.length - 1];
231
+ if (this.defaultActions[state]) {
232
+ action = this.defaultActions[state];
233
+ } else {
234
+ if (symbol === null || typeof symbol == 'undefined') {
235
+ symbol = lex();
236
+ }
237
+ action = table[state] && table[state][symbol];
238
+ }
239
+ if (typeof action === 'undefined' || !action.length || !action[0]) {
240
+ var errStr = '';
241
+ expected = [];
242
+ for (p in table[state]) {
243
+ if (this.terminals_[p] && p > TERROR) {
244
+ expected.push('\'' + this.terminals_[p] + '\'');
245
+ }
246
+ }
247
+ if (lexer.showPosition) {
248
+ errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\'';
249
+ } else {
250
+ errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\'');
251
+ }
252
+ this.parseError(errStr, {
253
+ text: lexer.match,
254
+ token: this.terminals_[symbol] || symbol,
255
+ line: lexer.yylineno,
256
+ loc: yyloc,
257
+ expected: expected
258
+ });
259
+ }
260
+ if (action[0] instanceof Array && action.length > 1) {
261
+ throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
262
+ }
263
+ switch (action[0]) {
264
+ case 1:
265
+ stack.push(symbol);
266
+ vstack.push(lexer.yytext);
267
+ lstack.push(lexer.yylloc);
268
+ stack.push(action[1]);
269
+ symbol = null;
270
+ if (!preErrorSymbol) {
271
+ yyleng = lexer.yyleng;
272
+ yytext = lexer.yytext;
273
+ yylineno = lexer.yylineno;
274
+ yyloc = lexer.yylloc;
275
+ if (recovering > 0) {
276
+ recovering--;
277
+ }
278
+ } else {
279
+ symbol = preErrorSymbol;
280
+ preErrorSymbol = null;
281
+ }
282
+ break;
283
+ case 2:
284
+ len = this.productions_[action[1]][1];
285
+ yyval.$ = vstack[vstack.length - len];
286
+ yyval._$ = {
287
+ first_line: lstack[lstack.length - (len || 1)].first_line,
288
+ last_line: lstack[lstack.length - 1].last_line,
289
+ first_column: lstack[lstack.length - (len || 1)].first_column,
290
+ last_column: lstack[lstack.length - 1].last_column
291
+ };
292
+ if (ranges) {
293
+ yyval._$.range = [
294
+ lstack[lstack.length - (len || 1)].range[0],
295
+ lstack[lstack.length - 1].range[1]
296
+ ];
297
+ }
298
+ r = this.performAction.apply(yyval, [
299
+ yytext,
300
+ yyleng,
301
+ yylineno,
302
+ sharedState.yy,
303
+ action[1],
304
+ vstack,
305
+ lstack
306
+ ].concat(args));
307
+ if (typeof r !== 'undefined') {
308
+ return r;
309
+ }
310
+ if (len) {
311
+ stack = stack.slice(0, -1 * len * 2);
312
+ vstack = vstack.slice(0, -1 * len);
313
+ lstack = lstack.slice(0, -1 * len);
314
+ }
315
+ stack.push(this.productions_[action[1]][0]);
316
+ vstack.push(yyval.$);
317
+ lstack.push(yyval._$);
318
+ newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
319
+ stack.push(newState);
320
+ break;
321
+ case 3:
322
+ return true;
323
+ }
324
+ }
325
+ return true;
326
+ }};
327
+ /* generated by jison-lex 0.3.4 */
328
+ var lexer = (function(){
329
+ var lexer = ({
330
+
331
+ EOF:1,
332
+
333
+ parseError:function parseError(str, hash) {
334
+ if (this.yy.parser) {
335
+ this.yy.parser.parseError(str, hash);
336
+ } else {
337
+ throw new Error(str);
338
+ }
339
+ },
340
+
341
+ // resets the lexer, sets new input
342
+ setInput:function (input, yy) {
343
+ this.yy = yy || this.yy || {};
344
+ this._input = input;
345
+ this._more = this._backtrack = this.done = false;
346
+ this.yylineno = this.yyleng = 0;
347
+ this.yytext = this.matched = this.match = '';
348
+ this.conditionStack = ['INITIAL'];
349
+ this.yylloc = {
350
+ first_line: 1,
351
+ first_column: 0,
352
+ last_line: 1,
353
+ last_column: 0
354
+ };
355
+ if (this.options.ranges) {
356
+ this.yylloc.range = [0,0];
357
+ }
358
+ this.offset = 0;
359
+ return this;
360
+ },
361
+
362
+ // consumes and returns one char from the input
363
+ input:function () {
364
+ var ch = this._input[0];
365
+ this.yytext += ch;
366
+ this.yyleng++;
367
+ this.offset++;
368
+ this.match += ch;
369
+ this.matched += ch;
370
+ var lines = ch.match(/(?:\r\n?|\n).*/g);
371
+ if (lines) {
372
+ this.yylineno++;
373
+ this.yylloc.last_line++;
374
+ } else {
375
+ this.yylloc.last_column++;
376
+ }
377
+ if (this.options.ranges) {
378
+ this.yylloc.range[1]++;
379
+ }
380
+
381
+ this._input = this._input.slice(1);
382
+ return ch;
383
+ },
384
+
385
+ // unshifts one char (or a string) into the input
386
+ unput:function (ch) {
387
+ var len = ch.length;
388
+ var lines = ch.split(/(?:\r\n?|\n)/g);
389
+
390
+ this._input = ch + this._input;
391
+ this.yytext = this.yytext.substr(0, this.yytext.length - len);
392
+ //this.yyleng -= len;
393
+ this.offset -= len;
394
+ var oldLines = this.match.split(/(?:\r\n?|\n)/g);
395
+ this.match = this.match.substr(0, this.match.length - 1);
396
+ this.matched = this.matched.substr(0, this.matched.length - 1);
397
+
398
+ if (lines.length - 1) {
399
+ this.yylineno -= lines.length - 1;
400
+ }
401
+ var r = this.yylloc.range;
402
+
403
+ this.yylloc = {
404
+ first_line: this.yylloc.first_line,
405
+ last_line: this.yylineno + 1,
406
+ first_column: this.yylloc.first_column,
407
+ last_column: lines ?
408
+ (lines.length === oldLines.length ? this.yylloc.first_column : 0)
409
+ + oldLines[oldLines.length - lines.length].length - lines[0].length :
410
+ this.yylloc.first_column - len
411
+ };
412
+
413
+ if (this.options.ranges) {
414
+ this.yylloc.range = [r[0], r[0] + this.yyleng - len];
415
+ }
416
+ this.yyleng = this.yytext.length;
417
+ return this;
418
+ },
419
+
420
+ // When called from action, caches matched text and appends it on next action
421
+ more:function () {
422
+ this._more = true;
423
+ return this;
424
+ },
425
+
426
+ // When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead.
427
+ reject:function () {
428
+ if (this.options.backtrack_lexer) {
429
+ this._backtrack = true;
430
+ } else {
431
+ return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n' + this.showPosition(), {
432
+ text: "",
433
+ token: null,
434
+ line: this.yylineno
435
+ });
436
+
437
+ }
438
+ return this;
439
+ },
440
+
441
+ // retain first n characters of the match
442
+ less:function (n) {
443
+ this.unput(this.match.slice(n));
444
+ },
445
+
446
+ // displays already matched input, i.e. for error messages
447
+ pastInput:function () {
448
+ var past = this.matched.substr(0, this.matched.length - this.match.length);
449
+ return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, "");
450
+ },
451
+
452
+ // displays upcoming input, i.e. for error messages
453
+ upcomingInput:function () {
454
+ var next = this.match;
455
+ if (next.length < 20) {
456
+ next += this._input.substr(0, 20-next.length);
457
+ }
458
+ return (next.substr(0,20) + (next.length > 20 ? '...' : '')).replace(/\n/g, "");
459
+ },
460
+
461
+ // displays the character position where the lexing error occurred, i.e. for error messages
462
+ showPosition:function () {
463
+ var pre = this.pastInput();
464
+ var c = new Array(pre.length + 1).join("-");
465
+ return pre + this.upcomingInput() + "\n" + c + "^";
466
+ },
467
+
468
+ // test the lexed token: return FALSE when not a match, otherwise return token
469
+ test_match:function(match, indexed_rule) {
470
+ var token,
471
+ lines,
472
+ backup;
473
+
474
+ if (this.options.backtrack_lexer) {
475
+ // save context
476
+ backup = {
477
+ yylineno: this.yylineno,
478
+ yylloc: {
479
+ first_line: this.yylloc.first_line,
480
+ last_line: this.last_line,
481
+ first_column: this.yylloc.first_column,
482
+ last_column: this.yylloc.last_column
483
+ },
484
+ yytext: this.yytext,
485
+ match: this.match,
486
+ matches: this.matches,
487
+ matched: this.matched,
488
+ yyleng: this.yyleng,
489
+ offset: this.offset,
490
+ _more: this._more,
491
+ _input: this._input,
492
+ yy: this.yy,
493
+ conditionStack: this.conditionStack.slice(0),
494
+ done: this.done
495
+ };
496
+ if (this.options.ranges) {
497
+ backup.yylloc.range = this.yylloc.range.slice(0);
498
+ }
499
+ }
500
+
501
+ lines = match[0].match(/(?:\r\n?|\n).*/g);
502
+ if (lines) {
503
+ this.yylineno += lines.length;
504
+ }
505
+ this.yylloc = {
506
+ first_line: this.yylloc.last_line,
507
+ last_line: this.yylineno + 1,
508
+ first_column: this.yylloc.last_column,
509
+ last_column: lines ?
510
+ lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length :
511
+ this.yylloc.last_column + match[0].length
512
+ };
513
+ this.yytext += match[0];
514
+ this.match += match[0];
515
+ this.matches = match;
516
+ this.yyleng = this.yytext.length;
517
+ if (this.options.ranges) {
518
+ this.yylloc.range = [this.offset, this.offset += this.yyleng];
519
+ }
520
+ this._more = false;
521
+ this._backtrack = false;
522
+ this._input = this._input.slice(match[0].length);
523
+ this.matched += match[0];
524
+ token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
525
+ if (this.done && this._input) {
526
+ this.done = false;
527
+ }
528
+ if (token) {
529
+ return token;
530
+ } else if (this._backtrack) {
531
+ // recover context
532
+ for (var k in backup) {
533
+ this[k] = backup[k];
534
+ }
535
+ return false; // rule action called reject() implying the next rule should be tested instead.
536
+ }
537
+ return false;
538
+ },
539
+
540
+ // return next match in input
541
+ next:function () {
542
+ if (this.done) {
543
+ return this.EOF;
544
+ }
545
+ if (!this._input) {
546
+ this.done = true;
547
+ }
548
+
549
+ var token,
550
+ match,
551
+ tempMatch,
552
+ index;
553
+ if (!this._more) {
554
+ this.yytext = '';
555
+ this.match = '';
556
+ }
557
+ var rules = this._currentRules();
558
+ for (var i = 0; i < rules.length; i++) {
559
+ tempMatch = this._input.match(this.rules[rules[i]]);
560
+ if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
561
+ match = tempMatch;
562
+ index = i;
563
+ if (this.options.backtrack_lexer) {
564
+ token = this.test_match(tempMatch, rules[i]);
565
+ if (token !== false) {
566
+ return token;
567
+ } else if (this._backtrack) {
568
+ match = false;
569
+ continue; // rule action called reject() implying a rule MISmatch.
570
+ } else {
571
+ // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
572
+ return false;
573
+ }
574
+ } else if (!this.options.flex) {
575
+ break;
576
+ }
577
+ }
578
+ }
579
+ if (match) {
580
+ token = this.test_match(match, rules[index]);
581
+ if (token !== false) {
582
+ return token;
583
+ }
584
+ // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
585
+ return false;
586
+ }
587
+ if (this._input === "") {
588
+ return this.EOF;
589
+ } else {
590
+ return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), {
591
+ text: "",
592
+ token: null,
593
+ line: this.yylineno
594
+ });
595
+ }
596
+ },
597
+
598
+ // return next match that has a token
599
+ lex:function lex () {
600
+ var r = this.next();
601
+ if (r) {
602
+ return r;
603
+ } else {
604
+ return this.lex();
605
+ }
606
+ },
607
+
608
+ // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
609
+ begin:function begin (condition) {
610
+ this.conditionStack.push(condition);
611
+ },
612
+
613
+ // pop the previously active lexer condition state off the condition stack
614
+ popState:function popState () {
615
+ var n = this.conditionStack.length - 1;
616
+ if (n > 0) {
617
+ return this.conditionStack.pop();
618
+ } else {
619
+ return this.conditionStack[0];
620
+ }
621
+ },
622
+
623
+ // produce the lexer rule set which is active for the currently active lexer condition state
624
+ _currentRules:function _currentRules () {
625
+ if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
626
+ return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
627
+ } else {
628
+ return this.conditions["INITIAL"].rules;
629
+ }
630
+ },
631
+
632
+ // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
633
+ topState:function topState (n) {
634
+ n = this.conditionStack.length - 1 - Math.abs(n || 0);
635
+ if (n >= 0) {
636
+ return this.conditionStack[n];
637
+ } else {
638
+ return "INITIAL";
639
+ }
640
+ },
641
+
642
+ // alias for begin(condition)
643
+ pushState:function pushState (condition) {
644
+ this.begin(condition);
645
+ },
646
+
647
+ // return the number of states currently on the stack
648
+ stateStackSize:function stateStackSize() {
649
+ return this.conditionStack.length;
650
+ },
651
+ options: {"flex":true},
652
+ performAction: function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
653
+ var YYSTATE=YY_START;
654
+ switch($avoiding_name_collisions) {
655
+ case 0:/* skip whitespace */
656
+ break;
657
+ case 1:/* skip \space */
658
+ break;
659
+ case 2:/* skip '\ ' */
660
+ break;
661
+ case 3:return "INT"
662
+ break;
663
+ case 4:return "FLOAT"
664
+ break;
665
+ case 5:return "^"
666
+ break;
667
+ case 6:return "*"
668
+ break;
669
+ case 7:return "*"
670
+ break;
671
+ case 8:return "*"
672
+ break;
673
+ case 9:return "*"
674
+ break;
675
+ case 10:return "/"
676
+ break;
677
+ case 11:return "/"
678
+ break;
679
+ case 12:return "-"
680
+ break;
681
+ case 13:return "-"
682
+ break;
683
+ case 14:return "+"
684
+ break;
685
+ case 15:return "^"
686
+ break;
687
+ case 16:return "("
688
+ break;
689
+ case 17:return ")"
690
+ break;
691
+ case 18:return "("
692
+ break;
693
+ case 19:return ")"
694
+ break;
695
+ case 20:return "["
696
+ break;
697
+ case 21:return "]"
698
+ break;
699
+ case 22:return "{"
700
+ break;
701
+ case 23:return "}"
702
+ break;
703
+ case 24:return "{"
704
+ break;
705
+ case 25:return "}"
706
+ break;
707
+ case 26:return "_"
708
+ break;
709
+ case 27:return "|"
710
+ break;
711
+ case 28:return "LEFT|"
712
+ break;
713
+ case 29:return "RIGHT|"
714
+ break;
715
+ case 30:return "!"
716
+ break;
717
+ case 31:return "SIGN"
718
+ break;
719
+ case 32:yy_.yytext = "<="; return "SIGN"
720
+ break;
721
+ case 33:yy_.yytext = ">="; return "SIGN"
722
+ break;
723
+ case 34:yy_.yytext = "<="; return "SIGN"
724
+ break;
725
+ case 35:yy_.yytext = ">="; return "SIGN"
726
+ break;
727
+ case 36:yy_.yytext = "<>"; return "SIGN"
728
+ break;
729
+ case 37:yy_.yytext = "<>"; return "SIGN"
730
+ break;
731
+ case 38:yy_.yytext = "<>"; return "SIGN"
732
+ break;
733
+ case 39:yy_.yytext = "<>"; return "SIGN"
734
+ break;
735
+ case 40:yy_.yytext = "<="; return "SIGN"
736
+ break;
737
+ case 41:yy_.yytext = ">="; return "SIGN"
738
+ break;
739
+ case 42:return "FRAC"
740
+ break;
741
+ case 43:return "FRAC"
742
+ break;
743
+ case 44:return "sqrt"
744
+ break;
745
+ case 45:return "abs"
746
+ break;
747
+ case 46:return "ln"
748
+ break;
749
+ case 47:return "log"
750
+ break;
751
+ case 48:return "TRIG"
752
+ break;
753
+ case 49:return "TRIG"
754
+ break;
755
+ case 50:return "TRIG"
756
+ break;
757
+ case 51:return "TRIG"
758
+ break;
759
+ case 52:yy_.yytext = "sin"; return "TRIG"
760
+ break;
761
+ case 53:yy_.yytext = "cos"; return "TRIG"
762
+ break;
763
+ case 54:yy_.yytext = "tan"; return "TRIG"
764
+ break;
765
+ case 55:yy_.yytext = "csc"; return "TRIG"
766
+ break;
767
+ case 56:yy_.yytext = "sec"; return "TRIG"
768
+ break;
769
+ case 57:yy_.yytext = "cot"; return "TRIG"
770
+ break;
771
+ case 58:yy_.yytext = "arcsin"; return "TRIG"
772
+ break;
773
+ case 59:yy_.yytext = "arccos"; return "TRIG"
774
+ break;
775
+ case 60:yy_.yytext = "arctan"; return "TRIG"
776
+ break;
777
+ case 61:yy_.yytext = "arccsc"; return "TRIG"
778
+ break;
779
+ case 62:yy_.yytext = "arcsec"; return "TRIG"
780
+ break;
781
+ case 63:yy_.yytext = "arccot"; return "TRIG"
782
+ break;
783
+ case 64:return "TRIGINV"
784
+ break;
785
+ case 65:return "TRIGINV"
786
+ break;
787
+ case 66:yy_.yytext = "sinh"; return "TRIG"
788
+ break;
789
+ case 67:yy_.yytext = "cosh"; return "TRIG"
790
+ break;
791
+ case 68:yy_.yytext = "tanh"; return "TRIG"
792
+ break;
793
+ case 69:yy_.yytext = "csch"; return "TRIG"
794
+ break;
795
+ case 70:yy_.yytext = "sech"; return "TRIG"
796
+ break;
797
+ case 71:yy_.yytext = "tanh"; return "TRIG"
798
+ break;
799
+ case 72:return "CONST"
800
+ break;
801
+ case 73:yy_.yytext = "pi"; return "CONST"
802
+ break;
803
+ case 74:yy_.yytext = "pi"; return "CONST"
804
+ break;
805
+ case 75:return "VAR"
806
+ break;
807
+ case 76:yy_.yytext = "theta"; return "VAR"
808
+ break;
809
+ case 77:yy_.yytext = "theta"; return "VAR"
810
+ break;
811
+ case 78:return "VAR"
812
+ break;
813
+ case 79:yy_.yytext = "phi"; return "VAR"
814
+ break;
815
+ case 80:yy_.yytext = "phi"; return "VAR"
816
+ break;
817
+ case 81:return yy.symbolLexer(yy_.yytext)
818
+ break;
819
+ case 82:return "EOF"
820
+ break;
821
+ case 83:return "INVALID"
822
+ break;
823
+ case 84:console.log(yy_.yytext);
824
+ break;
825
+ }
826
+ },
827
+ rules: [/^(?:\s+)/,/^(?:\\space)/,/^(?:\\ )/,/^(?:[0-9]+\.?)/,/^(?:([0-9]+)?\.[0-9]+)/,/^(?:\*\*)/,/^(?:\*)/,/^(?:\\cdot|·)/,/^(?:\\times|×)/,/^(?:\\ast)/,/^(?:\/)/,/^(?:\\div|÷)/,/^(?:-)/,/^(?:−)/,/^(?:\+)/,/^(?:\^)/,/^(?:\()/,/^(?:\))/,/^(?:\\left\()/,/^(?:\\right\))/,/^(?:\[)/,/^(?:\])/,/^(?:\{)/,/^(?:\})/,/^(?:\\left\{)/,/^(?:\\right\})/,/^(?:_)/,/^(?:\|)/,/^(?:\\left\|)/,/^(?:\\right\|)/,/^(?:\!)/,/^(?:<=|>=|<>|<|>|=)/,/^(?:\\le)/,/^(?:\\ge)/,/^(?:\\leq)/,/^(?:\\geq)/,/^(?:=\/=)/,/^(?:\\ne)/,/^(?:\\neq)/,/^(?:≠)/,/^(?:≤)/,/^(?:≥)/,/^(?:\\frac)/,/^(?:\\dfrac)/,/^(?:sqrt|\\sqrt)/,/^(?:abs|\\abs)/,/^(?:ln|\\ln)/,/^(?:log|\\log)/,/^(?:sin|cos|tan)/,/^(?:csc|sec|cot)/,/^(?:sinh|cosh|tanh)/,/^(?:csch|sech|coth)/,/^(?:\\sin)/,/^(?:\\cos)/,/^(?:\\tan)/,/^(?:\\csc)/,/^(?:\\sec)/,/^(?:\\cot)/,/^(?:\\arcsin)/,/^(?:\\arccos)/,/^(?:\\arctan)/,/^(?:\\arccsc)/,/^(?:\\arcsec)/,/^(?:\\arccot)/,/^(?:arcsin|arccos|arctan)/,/^(?:arccsc|arcsec|arccot)/,/^(?:\\sinh)/,/^(?:\\cosh)/,/^(?:\\tanh)/,/^(?:\\csch)/,/^(?:\\sech)/,/^(?:\\coth)/,/^(?:pi)/,/^(?:π)/,/^(?:\\pi)/,/^(?:theta)/,/^(?:θ)/,/^(?:\\theta)/,/^(?:phi)/,/^(?:φ)/,/^(?:\\phi)/,/^(?:[a-zA-Z])/,/^(?:$)/,/^(?:.)/,/^(?:.)/],
828
+ conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84],"inclusive":true}}
829
+ });
830
+ return lexer;
831
+ })();
832
+ parser.lexer = lexer;
833
+ function Parser () {
834
+ this.yy = {};
835
+ }
836
+ Parser.prototype = parser;parser.Parser = Parser;
837
+ return new Parser;
838
+ })();
839
+
840
+ export {parser};