|
16 | 16 | Rule.highestId = 0;
|
17 | 17 |
|
18 | 18 | Rule.prototype.toString = function(withCursorAt) {
|
19 |
| - function stringifySymbolSequence (e) { |
20 |
| - return e.literal ? JSON.stringify(e.literal) : |
21 |
| - e.type ? '%' + e.type : e.toString(); |
22 |
| - } |
23 | 19 | var symbolSequence = (typeof withCursorAt === "undefined")
|
24 |
| - ? this.symbols.map(stringifySymbolSequence).join(' ') |
25 |
| - : ( this.symbols.slice(0, withCursorAt).map(stringifySymbolSequence).join(' ') |
| 20 | + ? this.symbols.map(getSymbolShortDisplay).join(' ') |
| 21 | + : ( this.symbols.slice(0, withCursorAt).map(getSymbolShortDisplay).join(' ') |
26 | 22 | + " ● "
|
27 |
| - + this.symbols.slice(withCursorAt).map(stringifySymbolSequence).join(' ') ); |
| 23 | + + this.symbols.slice(withCursorAt).map(getSymbolShortDisplay).join(' ') ); |
28 | 24 | return this.name + " → " + symbolSequence;
|
29 | 25 | }
|
30 | 26 |
|
|
391 | 387 | };
|
392 | 388 |
|
393 | 389 | Parser.prototype.getSymbolDisplay = function(symbol) {
|
394 |
| - var type = typeof symbol; |
395 |
| - if (type === "string") { |
396 |
| - return symbol; |
397 |
| - } else if (type === "object" && symbol.literal) { |
398 |
| - return JSON.stringify(symbol.literal); |
399 |
| - } else if (type === "object" && symbol instanceof RegExp) { |
400 |
| - return 'character matching ' + symbol; |
401 |
| - } else if (type === "object" && symbol.type) { |
402 |
| - return symbol.type + ' token'; |
403 |
| - } else { |
404 |
| - throw new Error('Unknown symbol type: ' + symbol); |
405 |
| - } |
| 390 | + return getSymbolLongDisplay(symbol); |
406 | 391 | };
|
407 | 392 |
|
408 | 393 | /*
|
|
478 | 463 | return considerations.map(function(c) {return c.data; });
|
479 | 464 | };
|
480 | 465 |
|
| 466 | + function getSymbolLongDisplay(symbol) { |
| 467 | + var type = typeof symbol; |
| 468 | + if (type === "string") { |
| 469 | + return symbol; |
| 470 | + } else if (type === "object") { |
| 471 | + if (symbol.literal) { |
| 472 | + return JSON.stringify(symbol.literal); |
| 473 | + } else if (symbol instanceof RegExp) { |
| 474 | + return 'character matching ' + symbol; |
| 475 | + } else if (symbol.type) { |
| 476 | + return symbol.type + ' token'; |
| 477 | + } else if (symbol.test) { |
| 478 | + return 'token matching ' + String(symbol.test); |
| 479 | + } else { |
| 480 | + throw new Error('Unknown symbol type: ' + symbol); |
| 481 | + } |
| 482 | + } |
| 483 | + } |
| 484 | + |
| 485 | + function getSymbolShortDisplay(symbol) { |
| 486 | + var type = typeof symbol; |
| 487 | + if (type === "string") { |
| 488 | + return symbol; |
| 489 | + } else if (type === "object") { |
| 490 | + if (symbol.literal) { |
| 491 | + return JSON.stringify(symbol.literal); |
| 492 | + } else if (symbol instanceof RegExp) { |
| 493 | + return symbol.toString(); |
| 494 | + } else if (symbol.type) { |
| 495 | + return '%' + symbol.type; |
| 496 | + } else if (symbol.test) { |
| 497 | + return '<' + String(symbol.test) + '>'; |
| 498 | + } else { |
| 499 | + throw new Error('Unknown symbol type: ' + symbol); |
| 500 | + } |
| 501 | + } |
| 502 | + } |
| 503 | + |
481 | 504 | return {
|
482 | 505 | Parser: Parser,
|
483 | 506 | Grammar: Grammar,
|
|
0 commit comments