|
14 | 14 | } |
15 | 15 | return (new Function("return " + str))(); |
16 | 16 | } catch(e) { |
17 | | - te("ijs"); |
| 17 | + te("ijs", e.message); |
18 | 18 | } |
19 | 19 | } |
20 | 20 |
|
|
40 | 40 | }; |
41 | 41 |
|
42 | 42 | // throw an error message |
43 | | - function te(ec) { |
44 | | - throw new Error(errorCodes[ec]); |
| 43 | + function te(ec, context) { |
| 44 | + throw new Error(errorCodes[ec] + " in '" + context + "'"); |
45 | 45 | } |
46 | 46 |
|
47 | 47 | // THE LEXER |
|
90 | 90 | else if (m[3]) a = [off, toks.typ, m[0]]; |
91 | 91 | else if (m[4]) a = [off, toks.psc, m[0]]; |
92 | 92 | else if (m[5]) a = [off, toks.psf, m[0]]; |
93 | | - else if (m[6]) te("upc"); |
| 93 | + else if (m[6]) te("upc", str); |
94 | 94 | else if (m[8]) a = [off, m[7] ? toks.ide : toks.str, jsonParse(m[8])]; |
95 | | - else if (m[9]) te("ujs"); |
| 95 | + else if (m[9]) te("ujs", str); |
96 | 96 | else if (m[10]) a = [off, toks.ide, m[10].replace(/\\([^\r\n\f0-9a-fA-F])/g,"$1")]; |
97 | 97 | return a; |
98 | 98 | } |
|
156 | 156 | if (l && l[1] === '(') { |
157 | 157 | lhs = exprParse2(str, l[0]); |
158 | 158 | var p = exprLex(str, lhs[0]); |
159 | | - if (!p || p[1] !== ')') te('epex'); |
| 159 | + if (!p || p[1] !== ')') te('epex', str); |
160 | 160 | off = p[0]; |
161 | 161 | lhs = [ '(', lhs[1] ]; |
162 | 162 | } else if (!l || (l[1] && l[1] != 'x')) { |
163 | | - te("ee"); |
| 163 | + te("ee", str + " - " + ( l[1] && l[1] )); |
164 | 164 | } else { |
165 | 165 | lhs = ((l[1] === 'x') ? undefined : l[2]); |
166 | 166 | off = l[0]; |
|
170 | 170 | var op = exprLex(str, off); |
171 | 171 | if (!op || op[1] == ')') return [off, lhs]; |
172 | 172 | else if (op[1] == 'x' || !op[1]) { |
173 | | - te('bop'); |
| 173 | + te('bop', str + " - " + ( op[1] && op[1] )); |
174 | 174 | } |
175 | 175 |
|
176 | 176 | // tail recursion to fetch the rhs expression |
|
238 | 238 | a = []; |
239 | 239 | off = s[0]; |
240 | 240 | } else if (s[1] === ")") { |
241 | | - if (!nested) te("ucp"); |
| 241 | + if (!nested) te("ucp", s[1]); |
242 | 242 | readParen = 1; |
243 | 243 | off = s[0]; |
244 | 244 | break; |
245 | 245 | } |
246 | 246 | } |
247 | | - if (nested && !readParen) te("mcp"); |
| 247 | + if (nested && !readParen) te("mcp", str); |
248 | 248 | if (am) am.push(a); |
249 | 249 | var rv; |
250 | 250 | if (!nested && hints.usesSiblingOp) { |
|
322 | 322 | if (l === undefined) { |
323 | 323 | break; |
324 | 324 | } else if (l[1] === toks.ide) { |
325 | | - if (s.id) te("nmi"); |
| 325 | + if (s.id) te("nmi", l[1]); |
326 | 326 | s.id = l[2]; |
327 | 327 | } else if (l[1] === toks.psc) { |
328 | | - if (s.pc || s.pf) te("mpc"); |
| 328 | + if (s.pc || s.pf) te("mpc", l[1]); |
329 | 329 | // collapse first-child and last-child into nth-child expressions |
330 | 330 | if (l[2] === ":first-child") { |
331 | 331 | s.pf = ":nth-child"; |
|
344 | 344 | // any amount of whitespace, followed by paren, string, paren |
345 | 345 | l = lex(str, (off = l[0])); |
346 | 346 | if (l && l[1] === " ") l = lex(str, off = l[0]); |
347 | | - if (!l || l[1] !== "(") te("pex"); |
| 347 | + if (!l || l[1] !== "(") te("pex", str); |
348 | 348 | l = lex(str, (off = l[0])); |
349 | 349 | if (l && l[1] === " ") l = lex(str, off = l[0]); |
350 | | - if (!l || l[1] !== toks.str) te("sex"); |
| 350 | + if (!l || l[1] !== toks.str) te("sex", str); |
351 | 351 | s.expr[2] = l[2]; |
352 | 352 | l = lex(str, (off = l[0])); |
353 | 353 | if (l && l[1] === " ") l = lex(str, off = l[0]); |
354 | | - if (!l || l[1] !== ")") te("epex"); |
| 354 | + if (!l || l[1] !== ")") te("epex", str); |
355 | 355 | } else if (l[2] === ":has") { |
356 | 356 | // any amount of whitespace, followed by paren |
357 | 357 | l = lex(str, (off = l[0])); |
358 | 358 | if (l && l[1] === " ") l = lex(str, off = l[0]); |
359 | | - if (!l || l[1] !== "(") te("pex"); |
| 359 | + if (!l || l[1] !== "(") te("pex", str); |
360 | 360 | var h = parse(str, l[0], true); |
361 | 361 | l[0] = h[0]; |
362 | 362 | if (!s.has) s.has = []; |
363 | 363 | s.has.push(h[1]); |
364 | 364 | } else if (l[2] === ":expr") { |
365 | | - if (s.expr) te("mexp"); |
| 365 | + if (s.expr) te("mexp", str); |
366 | 366 | var e = exprParse(str, l[0]); |
367 | 367 | l[0] = e[0]; |
368 | 368 | s.expr = e[1]; |
369 | 369 | } else { |
370 | | - if (s.pc || s.pf ) te("mpc"); |
| 370 | + if (s.pc || s.pf ) te("mpc", str); |
371 | 371 | s.pf = l[2]; |
372 | 372 | var m = nthPat.exec(str.substr(l[0])); |
373 | | - if (!m) te("mepf"); |
| 373 | + if (!m) te("mepf", str); |
374 | 374 | if (m[5]) { |
375 | 375 | s.a = 2; |
376 | 376 | s.b = (m[5] === "odd") ? 1 : 0; |
|
390 | 390 | } |
391 | 391 |
|
392 | 392 | // now if we didn't actually parse anything it's an error |
393 | | - if (soff === off) te("se"); |
| 393 | + if (soff === off) te("se", str); |
394 | 394 |
|
395 | 395 | return [off, s]; |
396 | 396 | } |
|
0 commit comments