Debug Mode
Syntax
var exp = new apgExp(pattern, "d");
Debug mode exposes the APG trace object as exp.trace. It can be used to display the path of the parser through the parse tree. If the debug property is false, exp.trace is undefined.
Example
var pattern, str, exp, result; pattern = 'word = alpha *(alpha / num)\n'; pattern += 'alpha = %d65-90 / %d97-122\n'; pattern += 'num = %d48-57\n'; exp = new apgExp(pattern, "yd"); str = "ab12"; result = exp.exec(str); if(result){ var htmlPage = exp.trace.toHtmlPage(); /* display as HTML page */ var html = exp.trace.toHtml(); /* display in HTML page */ console.log(html); } /* returns */
JavaScript APG Trace
display mode: ASCII
Thu May 19 2016 14:06:20 GMT-0400 (EDT)
(a) | (b) | (c) | (d) | (e) | (f) | operator | phrase |
---|---|---|---|---|---|---|---|
0 | 13 | 0 | 0 | 0 | ↓ | RNM(word) | ab12• |
1 | 2 | 0 | 0 | 1 | ↓ | .RNM(alpha) | ab12• |
2 | 1 | 0 | 1 | 1 | ↑M | .RNM(alpha) | ab12• |
3 | 4 | 1 | 0 | 1 | ↓ | .RNM(alpha) | b12• |
4 | 3 | 1 | 1 | 1 | ↑M | .RNM(alpha) | b12• |
5 | 6 | 2 | 0 | 1 | ↓ | .RNM(alpha) | 12• |
6 | 5 | 2 | 0 | 1 | ↑N | .RNM(alpha) | 12• |
7 | 8 | 2 | 0 | 1 | ↓ | .RNM(num) | 12• |
8 | 7 | 2 | 1 | 1 | ↑M | .RNM(num) | 12• |
9 | 10 | 3 | 0 | 1 | ↓ | .RNM(alpha) | 2• |
10 | 9 | 3 | 0 | 1 | ↑N | .RNM(alpha) | 2• |
11 | 12 | 3 | 0 | 1 | ↓ | .RNM(num) | 2• |
12 | 11 | 3 | 1 | 1 | ↑M | .RNM(num) | 2• |
13 | 0 | 0 | 4 | 0 | ↑M | RNM(word) | ab12• |
(a) | (b) | (c) | (d) | (e) | (f) | operator | phrase |
legend:
(a) - line number
(b) - matching line number
(c) - phrase offset
(d) - phrase length
(e) - tree depth
(f) - operator state
- ↓ phrase opened
- ↑M phrase matched
- ↑E empty phrase matched
- ↑N phrase not matched
operator - ALT, CAT, REP, RNM, TRG, TLS, TBS†, UDT, AND, NOT, BKA, BKN, BKR, ABG, AEN‡
phrase - up to 80 characters of the phrase being matched
- matched characters
- matched characters in look ahead mode
- matched characters in look behind mode
- remainder characters(not yet examined by parser)
- control characters, TAB, LF, CR, etc. (ASCII mode only)
- 𝜺 empty string
- • end of input string
- … input string display truncated
†original ABNF operators:
ALT - alternation
CAT - concatenation
REP - repetition
RNM - rule name
TRG - terminal range
TLS - terminal literal string (case insensitive)
TBS - terminal binary string (case sensitive)
‡super set SABNF operators:
UDT - user-defined terminal
AND - positive look ahead
NOT - negative look ahead
BKA - positive look behind
BKN - negative look behind
BKR - back reference
ABG - anchor - begin of input string
AEN - anchor - end of input string