regular-grammar
Advanced tools
Comparing version 0.1.1 to 0.1.2-b
{ | ||
"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(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51649
451
1