buffer-apg-js
Version:
JavaScript APG, an ABNF Parser Generator
64 lines (63 loc) • 1.85 kB
HTML
<html lang="en">
<head>
<title>apg-exp</title>
<meta charset="utf-8">
<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>Property: ast</h1>
<p>
The <kbd>apgExp</kbd> object retains a copy of the <b>APG</b> parser's
Abstract Syntax Tree (AST) object.
The AST object is especially useful for making complex translations
of the matched phrase.
The use and details of the AST are beyond the scope of this guide.
</p>
<h3>Example</h3>
<pre>
var pattern, exp, str, result;
pattern = 'word = alpha *(alpha / num)\n';
pattern += 'alpha = %d65-90 / %d97-122\n';
pattern += 'num = %d48-57\n';
exp = new apgExp(pattern);
str = "ab12";
result = exp.exec(str);
console.log("exp.ast in XML format:");
console.log(exp.ast.toXml());
/* result */
exp.ast in XML format:
<?xml version="1.0" encoding="utf-8"?>
<root nodes="5" characters="4">
<!-- input string, decimal integer character codes -->
97,98,49,50
<node name="word" index="0" length="4">
97,98,49,50
<node name="alpha" index="0" length="1">
97
</node><!-- name="alpha" -->
<node name="alpha" index="1" length="1">
98
</node><!-- name="alpha" -->
<node name="num" index="2" length="1">
49
</node><!-- name="num" -->
<node name="num" index="3" length="1">
50
</node><!-- name="num" -->
</node><!-- name="word" -->
</root>
</div>
</div>
<div id="footer"></div>
</div>
</body>
</html>