1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.getPrecedence = getPrecedence;
|
7 | exports.getAssociativity = getAssociativity;
|
8 | exports.isAssociativeWith = isAssociativeWith;
|
9 | exports.properties = void 0;
|
10 |
|
11 | var _object = require("../utils/object.js");
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | var properties = [{
|
32 |
|
33 | AssignmentNode: {},
|
34 | FunctionAssignmentNode: {}
|
35 | }, {
|
36 |
|
37 | ConditionalNode: {
|
38 | latexLeftParens: false,
|
39 | latexRightParens: false,
|
40 | latexParens: false
|
41 |
|
42 |
|
43 | }
|
44 | }, {
|
45 |
|
46 | 'OperatorNode:or': {
|
47 | associativity: 'left',
|
48 | associativeWith: []
|
49 | }
|
50 | }, {
|
51 |
|
52 | 'OperatorNode:xor': {
|
53 | associativity: 'left',
|
54 | associativeWith: []
|
55 | }
|
56 | }, {
|
57 |
|
58 | 'OperatorNode:and': {
|
59 | associativity: 'left',
|
60 | associativeWith: []
|
61 | }
|
62 | }, {
|
63 |
|
64 | 'OperatorNode:bitOr': {
|
65 | associativity: 'left',
|
66 | associativeWith: []
|
67 | }
|
68 | }, {
|
69 |
|
70 | 'OperatorNode:bitXor': {
|
71 | associativity: 'left',
|
72 | associativeWith: []
|
73 | }
|
74 | }, {
|
75 |
|
76 | 'OperatorNode:bitAnd': {
|
77 | associativity: 'left',
|
78 | associativeWith: []
|
79 | }
|
80 | }, {
|
81 |
|
82 | 'OperatorNode:equal': {
|
83 | associativity: 'left',
|
84 | associativeWith: []
|
85 | },
|
86 | 'OperatorNode:unequal': {
|
87 | associativity: 'left',
|
88 | associativeWith: []
|
89 | },
|
90 | 'OperatorNode:smaller': {
|
91 | associativity: 'left',
|
92 | associativeWith: []
|
93 | },
|
94 | 'OperatorNode:larger': {
|
95 | associativity: 'left',
|
96 | associativeWith: []
|
97 | },
|
98 | 'OperatorNode:smallerEq': {
|
99 | associativity: 'left',
|
100 | associativeWith: []
|
101 | },
|
102 | 'OperatorNode:largerEq': {
|
103 | associativity: 'left',
|
104 | associativeWith: []
|
105 | },
|
106 | RelationalNode: {
|
107 | associativity: 'left',
|
108 | associativeWith: []
|
109 | }
|
110 | }, {
|
111 |
|
112 | 'OperatorNode:leftShift': {
|
113 | associativity: 'left',
|
114 | associativeWith: []
|
115 | },
|
116 | 'OperatorNode:rightArithShift': {
|
117 | associativity: 'left',
|
118 | associativeWith: []
|
119 | },
|
120 | 'OperatorNode:rightLogShift': {
|
121 | associativity: 'left',
|
122 | associativeWith: []
|
123 | }
|
124 | }, {
|
125 |
|
126 | 'OperatorNode:to': {
|
127 | associativity: 'left',
|
128 | associativeWith: []
|
129 | }
|
130 | }, {
|
131 |
|
132 | RangeNode: {}
|
133 | }, {
|
134 |
|
135 | 'OperatorNode:add': {
|
136 | associativity: 'left',
|
137 | associativeWith: ['OperatorNode:add', 'OperatorNode:subtract']
|
138 | },
|
139 | 'OperatorNode:subtract': {
|
140 | associativity: 'left',
|
141 | associativeWith: []
|
142 | }
|
143 | }, {
|
144 |
|
145 | 'OperatorNode:multiply': {
|
146 | associativity: 'left',
|
147 | associativeWith: ['OperatorNode:multiply', 'OperatorNode:divide', 'Operator:dotMultiply', 'Operator:dotDivide']
|
148 | },
|
149 | 'OperatorNode:divide': {
|
150 | associativity: 'left',
|
151 | associativeWith: [],
|
152 | latexLeftParens: false,
|
153 | latexRightParens: false,
|
154 | latexParens: false
|
155 |
|
156 |
|
157 |
|
158 | },
|
159 | 'OperatorNode:dotMultiply': {
|
160 | associativity: 'left',
|
161 | associativeWith: ['OperatorNode:multiply', 'OperatorNode:divide', 'OperatorNode:dotMultiply', 'OperatorNode:doDivide']
|
162 | },
|
163 | 'OperatorNode:dotDivide': {
|
164 | associativity: 'left',
|
165 | associativeWith: []
|
166 | },
|
167 | 'OperatorNode:mod': {
|
168 | associativity: 'left',
|
169 | associativeWith: []
|
170 | }
|
171 | }, {
|
172 |
|
173 | 'OperatorNode:unaryPlus': {
|
174 | associativity: 'right'
|
175 | },
|
176 | 'OperatorNode:unaryMinus': {
|
177 | associativity: 'right'
|
178 | },
|
179 | 'OperatorNode:bitNot': {
|
180 | associativity: 'right'
|
181 | },
|
182 | 'OperatorNode:not': {
|
183 | associativity: 'right'
|
184 | }
|
185 | }, {
|
186 |
|
187 | 'OperatorNode:pow': {
|
188 | associativity: 'right',
|
189 | associativeWith: [],
|
190 | latexRightParens: false
|
191 |
|
192 |
|
193 |
|
194 | },
|
195 | 'OperatorNode:dotPow': {
|
196 | associativity: 'right',
|
197 | associativeWith: []
|
198 | }
|
199 | }, {
|
200 |
|
201 | 'OperatorNode:factorial': {
|
202 | associativity: 'left'
|
203 | }
|
204 | }, {
|
205 |
|
206 | 'OperatorNode:transpose': {
|
207 | associativity: 'left'
|
208 | }
|
209 | }];
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 | exports.properties = properties;
|
221 |
|
222 | function getPrecedence(_node, parenthesis) {
|
223 | var node = _node;
|
224 |
|
225 | if (parenthesis !== 'keep') {
|
226 |
|
227 | node = _node.getContent();
|
228 | }
|
229 |
|
230 | var identifier = node.getIdentifier();
|
231 |
|
232 | for (var i = 0; i < properties.length; i++) {
|
233 | if (identifier in properties[i]) {
|
234 | return i;
|
235 | }
|
236 | }
|
237 |
|
238 | return null;
|
239 | }
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 | function getAssociativity(_node, parenthesis) {
|
253 | var node = _node;
|
254 |
|
255 | if (parenthesis !== 'keep') {
|
256 |
|
257 | node = _node.getContent();
|
258 | }
|
259 |
|
260 | var identifier = node.getIdentifier();
|
261 | var index = getPrecedence(node, parenthesis);
|
262 |
|
263 | if (index === null) {
|
264 |
|
265 | return null;
|
266 | }
|
267 |
|
268 | var property = properties[index][identifier];
|
269 |
|
270 | if ((0, _object.hasOwnProperty)(property, 'associativity')) {
|
271 | if (property.associativity === 'left') {
|
272 | return 'left';
|
273 | }
|
274 |
|
275 | if (property.associativity === 'right') {
|
276 | return 'right';
|
277 | }
|
278 |
|
279 |
|
280 | throw Error('\'' + identifier + '\' has the invalid associativity \'' + property.associativity + '\'.');
|
281 | }
|
282 |
|
283 |
|
284 | return null;
|
285 | }
|
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 | function isAssociativeWith(nodeA, nodeB, parenthesis) {
|
298 |
|
299 | var a = parenthesis !== 'keep' ? nodeA.getContent() : nodeA;
|
300 | var b = parenthesis !== 'keep' ? nodeA.getContent() : nodeB;
|
301 | var identifierA = a.getIdentifier();
|
302 | var identifierB = b.getIdentifier();
|
303 | var index = getPrecedence(a, parenthesis);
|
304 |
|
305 | if (index === null) {
|
306 |
|
307 | return null;
|
308 | }
|
309 |
|
310 | var property = properties[index][identifierA];
|
311 |
|
312 | if ((0, _object.hasOwnProperty)(property, 'associativeWith') && property.associativeWith instanceof Array) {
|
313 | for (var i = 0; i < property.associativeWith.length; i++) {
|
314 | if (property.associativeWith[i] === identifierB) {
|
315 | return true;
|
316 | }
|
317 | }
|
318 |
|
319 | return false;
|
320 | }
|
321 |
|
322 |
|
323 | return null;
|
324 | } |
\ | No newline at end of file |