UNPKG

apg-exp

Version:

(Deprecated: use apg-js instead.) Pattern-matching alternative to RegExp. Replaces the regular expression syntax with ABNF. Adds APG parser features such as User Defined Terminals (hand-written pattern matchers) and access to the AST.

66 lines (65 loc) 2.06 kB
<!DOCTYPE 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. See <a href="https://github.com/ldthomas/apg-js2-examples/tree/master/ast">here</a> and <a href="https://github.com/ldthomas/apg-js2-examples/tree/master/apg-exp">here</a> for examples of its use. </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: &lt;?xml version="1.0" encoding="utf-8"?> &lt;root nodes="5" characters="4"> &lt;!-- input string, decimal integer character codes --> 97,98,49,50 &lt;node name="word" index="0" length="4"> 97,98,49,50 &lt;node name="alpha" index="0" length="1"> 97 &lt;/node>&lt;!-- name="alpha" --> &lt;node name="alpha" index="1" length="1"> 98 &lt;/node>&lt;!-- name="alpha" --> &lt;node name="num" index="2" length="1"> 49 &lt;/node>&lt;!-- name="num" --> &lt;node name="num" index="3" length="1"> 50 &lt;/node>&lt;!-- name="num" --> &lt;/node>&lt;!-- name="word" --> &lt;/root> </div> </div> <div id="footer"></div> </div> </body> </html>