buffer-apg-js
Version:
JavaScript APG, an ABNF Parser Generator
116 lines (115 loc) • 7.53 kB
HTML
<html lang="en">
<head>
<title>apg-exp</title>
<meta charset="utf-8">
<link rel="stylesheet" href="./css/apgexp.css" type="text/css" />
<link rel="stylesheet" href="./css/BrightSide.css" type="text/css" />
<script type="text/javascript" src="./import.js"></script>
</head>
<body>
<div id="wrap">
<div id="header"></div>
<div id="content-wrap">
<img src="./images/PointLobosCropped.jpg" width="820" height="120" alt="headerphoto" class="no-border" />
<div id="sidebar"></div>
<div id="main-2col">
<!-- page content goes here -->
<h1>Debug Mode</h1>
<h3>Syntax</h3>
<pre>
var exp = new apgExp(pattern, "d");
</pre>
<p>Debug mode exposes the <b>APG</b> trace object</a> as
<kbd>exp.trace</kbd>. It can be used to display the path of the parser through the parse tree.
If the debug property is <kbd>false</kbd>, <kbd>exp.trace</kbd> is undefined.
</p>
<h3>Example</h3>
<p>
<pre>
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 */
</pre>
<h1>JavaScript APG Trace</h1>
<h3> display mode: ASCII</h3>
<h5> Thu May 19 2016 14:06:20 GMT-0400 (EDT)</h5>
<table class="apg-last2-left-table">
<tr><th>(a)</th><th>(b)</th><th>(c)</th><th>(d)</th><th>(e)</th><th>(f)</th><th>operator</th><th>phrase</th></tr>
<tr><td>0</td><td>13</td><td>0</td><td>0</td><td>0</td><td><span class="apg-active">↓ </span></td><td>RNM(word) </td><td><span class="apg-remainder">ab12</span><span class="apg-line-end">•</span></td></tr>
<tr><td>1</td><td>2</td><td>0</td><td>0</td><td>1</td><td><span class="apg-active">↓ </span></td><td>.RNM(alpha) </td><td><span class="apg-remainder">ab12</span><span class="apg-line-end">•</span></td></tr>
<tr><td>2</td><td>1</td><td>0</td><td>1</td><td>1</td><td><span class="apg-match">↑M</span></td><td>.RNM(alpha) </td><td><span class="apg-match">a</span><span class="apg-remainder">b12</span><span class="apg-line-end">•</span></td></tr>
<tr><td>3</td><td>4</td><td>1</td><td>0</td><td>1</td><td><span class="apg-active">↓ </span></td><td>.RNM(alpha) </td><td><span class="apg-remainder">b12</span><span class="apg-line-end">•</span></td></tr>
<tr><td>4</td><td>3</td><td>1</td><td>1</td><td>1</td><td><span class="apg-match">↑M</span></td><td>.RNM(alpha) </td><td><span class="apg-match">b</span><span class="apg-remainder">12</span><span class="apg-line-end">•</span></td></tr>
<tr><td>5</td><td>6</td><td>2</td><td>0</td><td>1</td><td><span class="apg-active">↓ </span></td><td>.RNM(alpha) </td><td><span class="apg-remainder">12</span><span class="apg-line-end">•</span></td></tr>
<tr><td>6</td><td>5</td><td>2</td><td>0</td><td>1</td><td><span class="apg-nomatch">↑N</span></td><td>.RNM(alpha) </td><td><span class="apg-remainder">12</span><span class="apg-line-end">•</span></td></tr>
<tr><td>7</td><td>8</td><td>2</td><td>0</td><td>1</td><td><span class="apg-active">↓ </span></td><td>.RNM(num) </td><td><span class="apg-remainder">12</span><span class="apg-line-end">•</span></td></tr>
<tr><td>8</td><td>7</td><td>2</td><td>1</td><td>1</td><td><span class="apg-match">↑M</span></td><td>.RNM(num) </td><td><span class="apg-match">1</span><span class="apg-remainder">2</span><span class="apg-line-end">•</span></td></tr>
<tr><td>9</td><td>10</td><td>3</td><td>0</td><td>1</td><td><span class="apg-active">↓ </span></td><td>.RNM(alpha) </td><td><span class="apg-remainder">2</span><span class="apg-line-end">•</span></td></tr>
<tr><td>10</td><td>9</td><td>3</td><td>0</td><td>1</td><td><span class="apg-nomatch">↑N</span></td><td>.RNM(alpha) </td><td><span class="apg-remainder">2</span><span class="apg-line-end">•</span></td></tr>
<tr><td>11</td><td>12</td><td>3</td><td>0</td><td>1</td><td><span class="apg-active">↓ </span></td><td>.RNM(num) </td><td><span class="apg-remainder">2</span><span class="apg-line-end">•</span></td></tr>
<tr><td>12</td><td>11</td><td>3</td><td>1</td><td>1</td><td><span class="apg-match">↑M</span></td><td>.RNM(num) </td><td><span class="apg-match">2</span><span class="apg-line-end">•</span></td></tr>
<tr><td>13</td><td>0</td><td>0</td><td>4</td><td>0</td><td><span class="apg-match">↑M</span></td><td>RNM(word) </td><td><span class="apg-match">ab12</span><span class="apg-line-end">•</span></td></tr>
<tr><th>(a)</th><th>(b)</th><th>(c)</th><th>(d)</th><th>(e)</th><th>(f)</th><th>operator</th><th>phrase</th></tr>
</table>
</table>
<p class="apg-mono">legend:<br>
(a) - line number<br>
(b) - matching line number<br>
(c) - phrase offset<br>
(d) - phrase length<br>
(e) - tree depth<br>
(f) - operator state<br>
- <span class="apg-active">↓</span> phrase opened<br>
- <span class="apg-match">↑M</span> phrase matched<br>
- <span class="apg-empty">↑E</span> empty phrase matched<br>
- <span class="apg-nomatch">↑N</span> phrase not matched<br>
operator - ALT, CAT, REP, RNM, TRG, TLS, TBS<sup>†</sup>, UDT, AND, NOT, BKA, BKN, BKR, ABG, AEN<sup>‡</sup><br>
phrase - up to 80 characters of the phrase being matched<br>
- <span class="apg-match">matched characters</span><br>
- <span class="apg-lh-match">matched characters in look ahead mode</span><br>
- <span class="apg-lb-match">matched characters in look behind mode</span><br>
- <span class="apg-remainder">remainder characters(not yet examined by parser)</span><br>
- <span class="apg-ctrl-char">control characters, TAB, LF, CR, etc. (ASCII mode only)</span><br>
- <span class="apg-empty">𝜺</span> empty string<br>
- <span class="apg-line-end">•</span> end of input string<br>
- <span class="apg-line-end">…</span> input string display truncated<br>
</p>
<p class="apg-mono">
<sup>†</sup>original ABNF operators:<br>
ALT - alternation<br>
CAT - concatenation<br>
REP - repetition<br>
RNM - rule name<br>
TRG - terminal range<br>
TLS - terminal literal string (case insensitive)<br>
TBS - terminal binary string (case sensitive)<br>
<br>
<sup>‡</sup>super set SABNF operators:<br>
UDT - user-defined terminal<br>
AND - positive look ahead<br>
NOT - negative look ahead<br>
BKA - positive look behind<br>
BKN - negative look behind<br>
BKR - back reference<br>
ABG - anchor - begin of input string<br>
AEN - anchor - end of input string<br>
</p>
</div>
</div>
<div id="footer"></div>
</div>
</body>
</html>