regjsparser
Advanced tools
Comparing version 0.1.4 to 0.1.5
{ | ||
"name": "regjsparser", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"author": "'Julian Viereck' <julian.viereck@gmail.com>", | ||
@@ -5,0 +5,0 @@ "license": "BSD", |
@@ -243,3 +243,3 @@ // regjsparser | ||
greedy: true, | ||
body: null, // set later on, | ||
body: null, // set later on | ||
range: [ | ||
@@ -278,3 +278,3 @@ from, | ||
if (min.codePoint > max.codePoint) { | ||
throw SyntaxError('invalid range in character class'); | ||
bail('invalid range in character class', min.raw + '-' + max.raw, from, to); | ||
} | ||
@@ -314,3 +314,3 @@ | ||
if (!match(value)) { | ||
throw SyntaxError('character: ' + value); | ||
bail('character', value); | ||
} | ||
@@ -403,3 +403,3 @@ } | ||
if (!atom) { | ||
throw SyntaxError('Expected atom') | ||
bail('Expected atom'); | ||
} | ||
@@ -430,3 +430,3 @@ var quantifier = parseQuantifier() || false; | ||
if (!body) { | ||
throw SyntaxError('Expected disjunction'); | ||
bail('Expected disjunction'); | ||
} | ||
@@ -483,3 +483,3 @@ skip(')'); | ||
var res; | ||
var res, from = pos; | ||
var quantifier; | ||
@@ -509,3 +509,3 @@ var min, max; | ||
if (min > max) { | ||
throw SyntaxError('numbers out of order in {} quantifier'); | ||
bail('numbers out of order in {} quantifier', '', from, pos); | ||
} | ||
@@ -551,3 +551,3 @@ quantifier = createQuantifier(min, max, res.range[0], res.range[1]); | ||
if (!res) { | ||
throw SyntaxError('atomEscape'); | ||
bail('atomEscape'); | ||
} | ||
@@ -602,3 +602,3 @@ return res; | ||
var res; | ||
var res, from = pos; | ||
@@ -618,3 +618,3 @@ res = parseDecimalEscape(); | ||
} else if (match('B')) { | ||
throw SyntaxError('\\B not possible inside of CharacterClass'); | ||
bail('\\B not possible inside of CharacterClass', '', from); | ||
} | ||
@@ -753,3 +753,2 @@ } | ||
var res; | ||
var tmp; | ||
@@ -804,3 +803,3 @@ | ||
if (!res) { | ||
throw SyntaxError('nonEmptyClassRanges'); | ||
bail('nonEmptyClassRanges'); | ||
} | ||
@@ -819,3 +818,3 @@ return res; | ||
if (!res) { | ||
throw SyntaxError('classAtom'); | ||
bail('classAtom'); | ||
} | ||
@@ -825,3 +824,3 @@ to = pos; | ||
if (!classRanges) { | ||
throw SyntaxError('classRanges'); | ||
bail('classRanges'); | ||
} | ||
@@ -837,3 +836,3 @@ from = atom.range[0]; | ||
if (!res) { | ||
throw SyntaxError('nonEmptyClassRangesNoDash'); | ||
bail('nonEmptyClassRangesNoDash'); | ||
} | ||
@@ -852,3 +851,3 @@ | ||
if (!atom) { | ||
throw SyntaxError('classAtom'); | ||
bail('classAtom'); | ||
} | ||
@@ -874,3 +873,3 @@ | ||
if (!res) { | ||
throw SyntaxError('classAtom'); | ||
bail('classAtom'); | ||
} | ||
@@ -909,3 +908,3 @@ if (current(']')) { | ||
if (!res) { | ||
throw SyntaxError('classEscape'); | ||
bail('classEscape'); | ||
} | ||
@@ -917,2 +916,18 @@ | ||
function bail(message, details, from, to) { | ||
from = from == null ? pos : from; | ||
to = to == null ? from : to; | ||
var contextStart = Math.max(0, from - 10); | ||
var contextEnd = Math.min(to + 10, str.length); | ||
// Output a bit of context and a line pointing to where our error is. | ||
// | ||
// We are assuming that there are no actual newlines in the content as this is a regular expression. | ||
var context = ' ' + str.substring(contextStart, contextEnd); | ||
var pointer = ' ' + new Array(from - contextStart + 1).join(' ') + '^'; | ||
throw SyntaxError(message + ' at position ' + from + (details ? ': ' + details : '') + '\n' + context + '\n' + pointer); | ||
} | ||
var backrefDenied = []; | ||
@@ -933,3 +948,3 @@ var closedCaptureCounter = 0; | ||
if (result.range[1] !== str.length) { | ||
throw SyntaxError('Could not parse entire input - got stuck: ' + str); | ||
bail('Could not parse entire input - got stuck', '', result.range[1]); | ||
} | ||
@@ -939,6 +954,6 @@ | ||
// As the parser collects the number of capture groups as the string is | ||
// parsed it is impossible to make these decisions at the point the `\2` is | ||
// handled. In case the local decision turns out to be wrongq after the | ||
// parsing has finished, the input string is parsed a second time with the | ||
// total count of capture groups set. | ||
// parsed it is impossible to make these decisions at the point when the | ||
// `\2` is handled. In case the local decision turns out to be wrong after | ||
// the parsing has finished, the input string is parsed a second time with | ||
// the total number of capture groups set. | ||
// | ||
@@ -956,3 +971,3 @@ // SEE: https://github.com/jviereck/regjsparser/issues/70 | ||
return result; | ||
}; | ||
} | ||
@@ -959,0 +974,0 @@ var regjsparser = { |
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
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
34675
870