headerphoto

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)operatorphrase
013000↓ RNM(word) ab12
12001↓ .RNM(alpha) ab12
21011↑M.RNM(alpha) ab12
34101↓ .RNM(alpha) b12
43111↑M.RNM(alpha) b12
56201↓ .RNM(alpha) 12
65201↑N.RNM(alpha) 12
78201↓ .RNM(num) 12
87211↑M.RNM(num) 12
910301↓ .RNM(alpha) 2
109301↑N.RNM(alpha) 2
1112301↓ .RNM(num) 2
1211311↑M.RNM(num) 2
130040↑MRNM(word) ab12
(a)(b)(c)(d)(e)(f)operatorphrase

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