UNPKG

buffer-apg-js

Version:

JavaScript APG, an ABNF Parser Generator

115 lines (114 loc) 2.78 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>Methods: include() & exclude()</h1> <p> By default, the <kbd>result.rules</kbd> object retains the sub-phrases matched by <i>all</i> named rules. Often there are rule names that are of no interest. The <kbd>include()</kbd> and <kbd>exclude()</kbd> methods can be used to limit the list of rule names retained in the results. </p> <h3>Syntax</h3> <pre> var exp = new apgExp(pattern[, flags]); exp.include(array); exp.exclude(array); </pre> <h3>Parameters</h3> <p>&bull; array: An array of rule names (strings) to include/exclude.</p> <h3>Return</h3> <p> <i>none</i> </p> <h3>Example 1</h3> <p> By default, all matches to all rules are retained in the <kbd>result.rules</kbd> object. </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'; str = "ab12"; exp = new apgExp(pattern); result = exp.exec(str); console.log(result.toText()); /* returns */ result: [0]: ab12 input: ab12 index: 0 length: 4 tree depth: 7 node hits: 26 rules: word : 0: ab12 : alpha : 0: a : alpha : 1: b : num : 2: 1 : num : 3: 2 </pre> <h3>Example 2</h3> <p> By using <kbd>exclude(["alpha", "num"])</kbd> "alpha" and "num" are removed from the <kbd>result.rules</kbd> object. </p> <pre> /* same as Example 1 except */ exp = new apgExp(pattern); exp.exclude(["alpha", "num"]) result = exp.exec(str); console.log(result.toText()); /* returns */ result: [0]: ab12 input: ab12 index: 0 length: 4 tree depth: 7 node hits: 26 rules: word : 0: ab12 </pre> <h3>Example 3</h3> <p> By using <kbd>include(["word"])</kbd> all rules except "word" are removed from the <kbd>result.rules</kbd> object. </p> <pre> /* same as Example 1 except */ exp = new apgExp(pattern); exp.include(["word"]) result = exp.exec(str); console.log(result.toText()); /* returns */ result: [0]: ab12 input: ab12 index: 0 length: 4 tree depth: 7 node hits: 26 rules: word : 0: ab12 </pre> </div> </div> <div id="footer"></div> </div> </body> </html>