Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apg-exp

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apg-exp - npm Package Compare versions

Comparing version 1.1.3 to 2.0.0

apgexp-min.css

24

guide/import.js

@@ -30,15 +30,15 @@ (function(){

menu += '<li class="subtoc"><a href="./debug.html">ApgExp.debug</a></li>';
menu += '<li class="subtoc"><a href="./input.html">ApgExp.input ($_)</a></li>';
menu += '<li class="subtoc"><a href="./flags.html">ApgExp.flags</a></li>';
menu += '<li class="subtoc"><a href="./global.html">ApgExp.global</a></li>';
menu += '<li class="subtoc"><a href="./lastMatch.html">ApgExp.input ($_)</a></li>';
menu += '<li class="subtoc"><a href="./lastIndex.html">ApgExp.lastIndex</a></li>';
menu += '<li class="subtoc"><a href="./lastMatch.html">ApgExp.lastMatch ($&)</a></li>';
menu += '<li class="subtoc"><a href="./leftContext.html">ApgExp.leftContext ($`)</a></li>';
menu += '<li class="subtoc"><a href="./lastMatch.html">ApgExp.leftContext ($`)</a></li>';
menu += '<li class="subtoc"><a href="./nodeHits.html">ApgExp.nodeHits</a></li>';
menu += '<li class="subtoc"><a href="./rightContext.html">ApgExp.rightContext ($\')</a></li>';
menu += '<li class="subtoc"><a href="./rules.html">ApgExp.rules (${rule})</a></li>';
menu += '<li class="subtoc"><a href="./lastMatch.html">ApgExp.rightContext ($\')</a></li>';
menu += '<li class="subtoc"><a href="./lastMatch.html">ApgExp.rules (${rule})</a></li>';
menu += '<li class="subtoc"><a href="./source.html">ApgExp.source</a></li>';
menu += '<li class="subtoc"><a href="./sticky.html">ApgExp.sticky</a></li>';
menu += '<li class="subtoc"><a href="./trace.html">ApgExp.trace</a></li>';
menu += '<li class="subtoc"><a href="./treeDepth.html">ApgExp.treeDepth</a></li>';
menu += '<li class="subtoc"><a href="./nodeHits.html">ApgExp.treeDepth</a></li>';
menu += '<li class="subtoc"><a href="./unicode.html">ApgExp.unicode</a></li>';

@@ -48,16 +48,16 @@ menu += '</ul><h1><a id="sitemapanchor"></a>Methods</h1>';

menu += '<ul class="sidemenu">';
menu += '<li><a href="./methods.html">ApgExp Methods</a></li>';
menu += '<li><a href="">ApgExp Methods</a></li>';
menu += '<li class="subtoc"><a href="./defineUdt.html">ApgExp.defineUdt()</a></li>';
menu += '<li class="subtoc"><a href="./exclude.html">ApgExp.exclude()</a></li>';
menu += '<li class="subtoc"><a href="./exec.html">ApgExp.exec()</a></li>';
menu += '<li class="subtoc"><a href="./include.html">ApgExp.include()</a></li>';
menu += '<li class="subtoc"><a href="./exclude.html">ApgExp.include()</a></li>';
menu += '<li class="subtoc"><a href="./maxCallStackDepth.html">ApgExp.maxCallStackDepth()</a></li>';
menu += '<li class="subtoc"><a href="./replace.html">ApgExp.replace()</a></li>';
menu += '<li class="subtoc"><a href="./sourceToHtml.html">ApgExp.sourceToHtml()</a></li>';
menu += '<li class="subtoc"><a href="./sourceToHtmlPage.html">ApgExp.sourceToHtmlPage()</a></li>';
menu += '<li class="subtoc"><a href="./sourceToText.html">ApgExp.sourceToText()</a></li>';
menu += '<li class="subtoc"><a href="./source.html">ApgExp.sourceToHtml()</a></li>';
menu += '<li class="subtoc"><a href="./source.html">ApgExp.sourceToHtmlPage()</a></li>';
menu += '<li class="subtoc"><a href="./source.html">ApgExp.sourceToText()</a></li>';
menu += '<li class="subtoc"><a href="./split.html">ApgExp.split()</a></li>';
menu += '<li class="subtoc"><a href="./test.html">ApgExp.test()</a></li>';
menu += '<li class="subtoc"><a href="./toHtml.html">ApgExp.toHtml()</a></li>';
menu += '<li class="subtoc"><a href="./toHtmlPage.html">ApgExp.toHtmlPage()</a></li>';
menu += '<li class="subtoc"><a href="./toText.html">ApgExp.toHtml()</a></li>';
menu += '<li class="subtoc"><a href="./toText.html">ApgExp.toHtmlPage()</a></li>';
menu += '<li class="subtoc"><a href="./toText.html">ApgExp.toText()</a></li>';

@@ -64,0 +64,0 @@ menu += '</ul><h1><a id="sitemapanchor"></a>Other</h1>';

{
"name": "apg-exp",
"version": "1.1.3",
"description": "Pattern-matching tool similar to RegExp, except uses ABNF grammar instead of regular expressions.",
"version": "2.0.0",
"description": "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.",
"main": "./src/apg-exp.js",

@@ -15,2 +15,3 @@ "scripts": {

"apgexp.css",
"apgexp-min.css",
"index.md",

@@ -20,4 +21,4 @@ "docco-gen"

"dependencies": {
"apg": "*",
"apg-lib": "*"
"apg": "3.x",
"apg-lib": "3.x"
},

@@ -33,2 +34,5 @@ "repository": {

"regexp",
"regex",
"patterns",
"pattern-matching",
"abnf",

@@ -35,0 +39,0 @@ "search",

# apg-exp - APG Expressions
`apg-exp` is a regex-like pattern-matching engine that uses a superset of the [ABNF syntax](https://tools.ietf.org/html/rfc5234) for the pattern definitions and [**APG**](https://github.com/ldthomas/apg-js2) to create and apply the pattern-matching parser. By way of introduction, the [regex Wikipedia article](https://en.wikipedia.org/wiki/Regular_expression) would be a good start and Jeffrey Friedl's book, [*Mastering Regular Expressions*](http://www.amazon.com/Mastering-Regular-Expressions-Jeffrey-Friedl/dp/0596528124) would be a lot better and more complete. This introduction will just mention features, a little on motivation and try to point out some possible advantages to `apg-exp`.
**apg-exp** is a regex-like pattern-matching engine that uses a superset of the [ABNF syntax](https://tools.ietf.org/html/rfc5234) for the pattern definitions and [**APG**](https://github.com/ldthomas/apg-js2) to create and apply the pattern-matching parser.
**Tutorial:** Don't miss the [tutorial](https://www.sitepoint.com/alternative-to-regular-expressions/) on [sitepoint.com](https://www.sitepoint.com/).
It will walk you through the basics from simple to some fairly sophisticated pattern matching of nested, paired parentheses and other brackets. (Something you can't do with RegExp.) It's all laid out for you with nine (9), hands-on, [CodePen](http://codepen.io/) examples.
**Complete User's Guide:** A complete user's guide can be found at `./guide/index.html`
or the [**APG** website](http://coasttocoastresearch.com/docjs2/apg-exp-guide/index.html).
**Version 2.0.0:** There are no functional changes in version 2.0.0. Only minor "under the hood" changes for compatability with [apg 3.0.0](https://github.com/ldthomas/apg-js2) have been made.
**apg-exp:** By way of introduction, the [regex Wikipedia article](https://en.wikipedia.org/wiki/Regular_expression) would be a good start and Jeffrey Friedl's book, [*Mastering Regular Expressions*](http://www.amazon.com/Mastering-Regular-Expressions-Jeffrey-Friedl/dp/0596528124) would be a lot better and more complete. This introduction will just mention features, a little on motivation and try to point out some possible advantages to **apg-exp**.
**Features:**

@@ -48,3 +59,3 @@ <ol>

<li>
The syntax allows <b>APG</b>'s User-Defined Terminals (UDTs) &ndash; arbitrary code for special phrase matching requirements. They make the phrase matching power of <code>apg-exp</code> essentially Turing complete.
The syntax allows <b>APG</b>'s User-Defined Terminals (UDTs) &ndash; write your own code for special phrase matching requirements. They make the phrase matching power of <code>apg-exp</code> essentially Turing complete.
</li>

@@ -75,3 +86,3 @@ <li>

**Motivation:**
**Introduction:**
The motivation was originally twofold.

@@ -83,9 +94,9 @@ <ol>

<li>
I felt (mistakenly) that recursive-descent parsers like <b>APG</b> and <a href="https://en.wikipedia.org/wiki/Parsing_expression_grammar">PEG</a> would prove to be much more powerful pattern matchers than regular expressions.
I felt (mistakenly) that a recursive-descent parser like <b>APG</b> would prove to be much more a powerful pattern matcher than regular expressions.
</li>
</ol>
Hardly any programmer has not used regexes at some point, more likely lots of points, and it doesn't take much reading of the Internet forums to note that many others, like me, find the regex syntax to be quite cryptic. Additionally, because regexes have such a long, rich history with many versions from many (excellent) developers, there are many different syntax variations as you move from system to system and language to language. By contrast ABNF is standardized (although my non-standard superset additions are starting to pile up.) Whether or not the ABNF syntax is preferable to conventional regex syntax will always be a personal preference. But, for me and possibly others, ABNF offers a more transparent syntax to work with.
Hardly any programmer has not needed regexes at some point, more likely lots of points, and it doesn't take much reading of the Internet forums to note that many others, like me, find the regex syntax to be quite cryptic. Additionally, because regexes have such a long, rich history with many versions from many (excellent) developers, there are many different syntax variations as you move from system to system and language to language. By contrast ABNF is standardized (although my non-standard superset additions are starting to pile up.) Whether or not the ABNF syntax is preferable to conventional regex syntax will always be a personal preference. But, for me and possibly others, ABNF offers a more transparent syntax to work with.
At the outset I naively thought that the regular expressions of regexes were just that &ndash; the Chomsky hierarchy variety. Therefore, I thought that using an **APG** parser for the pattern matching would add a great deal of parsing power to the problem. I soon discovered that not only were the "regular expressions" of many regexes full-blown recursive-descent parsers, they were loaded up with features that went well beyond that of **APG**. I had to play a little catch up to add look behind, back referencing and anchors. That being done, however, I think there is still a case for claiming some added power. I'm not a regex expert and I won't be making any big claims here, but there are a couple of points I will mention. I think the way that `apg-exp` gives the user nearly full control over the input, output and interpretation of the character codes goes a long way to address a number of the cautions mentioned in Jeffrey Friedl's book, for example on pages 92 and 106. I also think it addresses a number of the things Larry Wall finds wrong with the regex culture in his [Apocalypse 5](http://perl6.org/archive/doc/design/apo/A05.html) page. For example, back referencing, support for named capture, nested patterns (recursive rules), capture of all matches to a sub-phrase and others.
At the outset I naively thought that the regular expressions of regexes were just that &ndash; the Chomsky hierarchy variety. Therefore, I thought that using an **APG** parser for the pattern matching would add a great deal of parsing power to the problem. I soon discovered that not only were regexes not real "regular expressions", they were powerful, recursive-descent parsers, loaded with features that went well beyond that of **APG**. I had to play a little catch up to add look behind, back referencing and anchors. That being done, however, I think there is still a case for claiming some added power. I'm not a regex expert and I won't be making any big claims here, but there are a couple of points I will mention. I think the way that **apg-exp** gives the user nearly full control over the input, output and interpretation of the character codes goes a long way to address a number of the cautions mentioned in Jeffrey Friedl's book, for example on pages 92 and 106. I also think it addresses a number of the things Larry Wall finds wrong with the regex culture in his [Apocalypse 5](http://perl6.org/archive/doc/design/apo/A05.html) page. For example, back referencing, support for named capture, nested patterns (recursive rules), capture of all matches to a sub-phrase and others.

@@ -97,4 +108,3 @@ But the best thing to do, probably, is to head over to the

**Installation:**
*Requires node.js and npm.*
To install `apg-exp` in your node.js project from GitHub, in your project directory
**GitHub:** In your project directory,
```

@@ -104,20 +114,37 @@ git clone https://github.com/ldthomas/apg-js2-exp.git apgexp

```
or just
**npm:** In your project directory,
```
npm install apg-exp --save
```
**web page:**
```
git clone https://github.com/ldthomas/apg-js2-exp.git apgexp
```
Then, in the header of your web page include,
```
<link rel="stylesheet" href="./apgexp/apgexp.css">
<script src="./apgexp/apgexp.js" charset="utf-8"></script>
```
or,
```
<link rel="stylesheet" href="./apgexp/apgexp-min.css">
<script src="./apgexp/apgexp-min.js" charset="utf-8"></script>
```
(Note that some **apg-exp** output is in HTML format and apgexp.css is needed to properly style it.
Also, it is simply a copy of [apglib.css](https://github.com/ldthomas/apg-js2-lib).)
Now access **apg-exp** as,
```
<script>
var exp = new ApgExp(pattern);
</script>
```
See, specifically, the [email](https://github.com/ldthomas/apg-js2-examples/tree/master/apg-exp/email) example.
**Examples:**
See <a href="https://github.com/ldthomas/apg-js2-examples/tree/master/apg-exp">apg-js2-examples</a> for many examples of using
`apg-exp`.
See <a href="https://github.com/ldthomas/apg-js2-examples/tree/master/apg-exp">apg-js2-examples/apg-exp</a> for many more examples of using
**apg-exp**.
**Documentation:**
<i><b>UPDATE:</b> All fatal errors encountered in the `apg-exp` constructor and its object functions are now reported
with a thrown custom exception. Derived from the JavaScript Error object and named `ApgExpError`, it has functions
`toText()` and `toHtml()` for user-friendly display of the errors in either plain ASCII text or HTML format.
<i><b>UPDATE:</b> The files `apgexp.js` and `apgexp.css` have been added to make using `apg-exp`
in a browser web page simple.</i><br>
See the documentation in `src/apgexpjs-gen.js` and `src/apgexpcss-gen.js`.
See, also, this [CodePen](http://codepen.io/apg-exp/pen/aNWEzR) for an example.
The full documentation is in the code in [`docco`](https://jashkenas.github.io/docco/) format.

@@ -133,3 +160,3 @@ To generate the documentation, from the package directory:

**Copyright:**
*Copyright &copy; 2016 Lowell D. Thomas, all rights reserved*
*Copyright &copy; 2017 Lowell D. Thomas, all rights reserved*

@@ -136,0 +163,0 @@ **License:**

@@ -240,3 +240,6 @@ // This module implements the `exec()` function.

if (parserResult.success) {
return parserResult.index + parserResult.length;
var ret = parserResult.index;
/* bump-along mode - increment is never zero */
ret += (parserResult.length > 0) ? parserResult.length : 1;
return ret;
}

@@ -243,0 +246,0 @@ return 0;

@@ -1,2 +0,2 @@

// Generated by JavaScript APG, Version 2.0 [`apg-js2`](https://github.com/ldthomas/apg-js2)
// Generated by JavaScript APG, Version [`apg-js2`](https://github.com/ldthomas/apg-js2)
module.exports = function(){

@@ -9,3 +9,3 @@ "use strict";

// opcodes = 39
// ABNF original opcodes
// --- ABNF original opcodes
// ALT = 4

@@ -18,3 +18,3 @@ // CAT = 4

// TRG = 6
// SABNF superset opcodes
// --- SABNF superset opcodes
// UDT = 0

@@ -30,16 +30,2 @@ // AND = 0

//```
/* CALLBACK LIST PROTOTYPE (true, false or function reference) */
this.callbacks = [];
this.callbacks['alpha'] = false;
this.callbacks['any-other'] = false;
this.callbacks['digit'] = false;
this.callbacks['error'] = false;
this.callbacks['escape'] = false;
this.callbacks['match'] = false;
this.callbacks['name'] = false;
this.callbacks['prefix'] = false;
this.callbacks['rule'] = false;
this.callbacks['suffix'] = false;
this.callbacks['xname'] = false;
/* OBJECT IDENTIFIER (for internal parser use) */

@@ -46,0 +32,0 @@ this.grammarObject = 'grammarObject';

@@ -6,3 +6,3 @@ // This module defines all of the display functions. Text and HTML displays of

var utils = apglib.utils;
var style = utils.styleNames;
var style = apglib.style;
var MODE_HEX = 16;

@@ -77,3 +77,3 @@ var MODE_DEC = 10;

var caption = "result:";
html += '<table class="' + style.CLASS_LEFT_TABLE + '">\n';
html += '<table class="' + style.CLASS_STATE + '">\n';
html += '<caption>' + caption + '</caption>\n';

@@ -220,3 +220,3 @@ html += '<tr>';

var caption = "last match:";
html += '<table class="' + style.CLASS_LEFT_TABLE + '">\n';
html += '<table class="' + style.CLASS_STATE + '">\n';
html += '<caption>' + caption + '</caption>\n';

@@ -455,3 +455,3 @@ html += '<tr>';

caption += "(" + modeToText(mode) + ")";
html += '<table class="' + style.CLASS_LEFT_TABLE + '">\n';
html += '<table class="' + style.CLASS_STATE + '">\n';
html += '<caption>' + caption + '</caption>\n';

@@ -597,3 +597,3 @@ html += '<tr>';

caption += "(" + modeToText(mode) + ")";
html += '<table class="' + style.CLASS_LEFT_TABLE + '">\n';
html += '<table class="' + style.CLASS_STATE + '">\n';
html += '<caption>' + caption + '</caption>\n';

@@ -600,0 +600,0 @@ html += '<tr>';

@@ -26,3 +26,3 @@ // This module parses an input SABNF grammar string into a grammar object.

try{
grammarAnalysis.getString(input);
grammarResult = grammarAnalysis.analyze(input);
}catch(e){

@@ -32,8 +32,2 @@ result.error = errorName + e.msg;

}
try{
grammarResult = grammarAnalysis.analyze();
}catch(e){
result.error = errorName + e.msg;
break;
}
if(grammarResult.hasErrors){

@@ -40,0 +34,0 @@ result.error = "grammar has validation errors";

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc