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

regular-grammar

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

regular-grammar - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2-b

2

package.json
{
"name": "regular-grammar",
"version": "0.1.1",
"version": "0.1.2b",
"description": "A simple regular grammar/parser generator",

@@ -5,0 +5,0 @@ "author": "Victor Grishchenko <victor.grishchenko@gmail.com>",

@@ -49,3 +49,18 @@ /** The class generates regex _parsers for simple regular languages

const formula = m[0];
const marker = m[2] ? JSON.parse(m[2]) : (m[1] || '');
let marker;
if ( !m[1] ) {
marker = '';
} else if (m[1].length===1) {
marker = m[1];
} else if (m[1][0]==='"') {
marker = JSON.parse(m[1]);
} else if (m[1][0]==='[') {
const re_mrk = new RegExp(m[1]);
marker = re_mrk.source;
} else if (m[1][0]==='/') {
const re_mrk = new RegExp(m[2]);
marker = re_mrk.source;
} else {
throw new Error('marker parse fail: '+m);
}
const rule = m[3] || 'EMPTY';

@@ -80,3 +95,3 @@ const quantifier = m[4] || '';

if (this._splitters[t.formula]) { return this._splitters[t.formula]; }
let p = (t.marker.length === 1 ? '\\' : '') + t.marker;
let p = (t.marker.length === 1 ? '\\' : '') + t.marker + '\\s*';
p += '(' + this.pattern(t.rule) + ')';

@@ -142,3 +157,2 @@ const splitter = new RegExp(p, 'g');

// TODO test: no capture group for bodyless triplets
//console.log(rule_name, joined)

@@ -187,3 +201,3 @@ this._patterns[rule_name] = joined;

Grammar.TRIPLET_RE = /(\[\S*?\]|("(?:\\.|[^"])*")|[^A-Za-z0-9\s])?([A-Z][A-Z0-9_]*)?([*+?|]|{\d+(?:,\d+)?})?/g;
Grammar.TRIPLET_RE = /(\[\S*?\]|"(?:\\.|[^"])*"|\/([^\/\s]+)\/|[^A-Za-z0-9\s])?([A-Z][A-Z0-9_]*)?([*+?|]|{\d+(?:,\d+)?})?/g;

@@ -190,0 +204,0 @@ function sterilize (pattern) {

@@ -16,3 +16,3 @@ const tap = require('tape');

RUN: 'INT /BASE? [+%-]INT?',
RUN: 'INT /BASE? /[+%-]/INT?',
CONSTRUN: 'CONSTANT /BASE?',

@@ -39,2 +39,3 @@ IDS: 'RUN ,RUN*',

formula: 'INT',
empty: false,
marker: '',

@@ -47,2 +48,3 @@ rule: 'INT',

formula: '[+%-]INT?',
empty: false,
marker: '[+%-]',

@@ -49,0 +51,0 @@ rule: 'INT',

@@ -47,4 +47,3 @@ const tape = require('tape');

tap.ok(is);
tap.equals(parts[1].length, entry_count);
console.log(parts);
tap.equals(parts[1].length, entry_count-1);

@@ -51,0 +50,0 @@ tap.end();

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