regjsparser
Advanced tools
Comparing version 0.8.4 to 0.9.0
{ | ||
"name": "regjsparser", | ||
"version": "0.8.4", | ||
"version": "0.9.0", | ||
"author": "'Julian Viereck' <julian.viereck@gmail.com>", | ||
@@ -5,0 +5,0 @@ "license": "BSD-2-Clause", |
@@ -8,2 +8,3 @@ type _If<Test, Then, Else> = Test extends true ? Then : Else; | ||
unicodeSet?: boolean; | ||
modifiers?: boolean; | ||
}; | ||
@@ -102,12 +103,32 @@ | ||
export type NonCapturingGroup<F extends Features = {}> = Base<"group"> & { | ||
behavior: | ||
| "ignore" | ||
| "lookahead" | ||
| "lookbehind" | ||
| "negativeLookahead" | ||
| "negativeLookbehind"; | ||
body: RootNode<F>[]; | ||
}; | ||
export type ModifierFlags = { | ||
enabling: string, | ||
disabling: string | ||
} | ||
export type NonCapturingGroup<F extends Features = {}> = Base<"group"> & | ||
( | ||
| { | ||
behavior: | ||
| "lookahead" | ||
| "lookbehind" | ||
| "negativeLookahead" | ||
| "negativeLookbehind"; | ||
body: RootNode<F>[]; | ||
} | ||
| ({ | ||
behavior: "ignore"; | ||
body: RootNode<F>[]; | ||
} & _If< | ||
F["modifiers"], | ||
{ | ||
modifierFlags?: ModifierFlags; | ||
}, | ||
{ | ||
modifierFlags: undefined; | ||
} | ||
>) | ||
); | ||
export type CapturingGroup<F extends Features = {}> = Base<"group"> & { | ||
@@ -114,0 +135,0 @@ behavior: "normal"; |
@@ -210,2 +210,12 @@ // regjsparser | ||
// | ||
// -------------------------------------------------------------- | ||
// NOTE: The following productions refer to the | ||
// "Regular Expression Pattern Modifiers for ECMAScript" proposal. | ||
// https://github.com/tc39/proposal-regexp-modifiers | ||
// -------------------------------------------------------------- | ||
// | ||
// Atom :: | ||
// ( ? RegularExpressionFlags : Disjunction ) | ||
// ( ? RegularExpressionFlags - RegularExpressionFlags : Disjunction ) | ||
// | ||
@@ -722,3 +732,4 @@ "use strict"; | ||
// ( GroupSpecifier Disjunction ) | ||
// ( ? : Disjunction ) | ||
// ( ? RegularExpressionFlags : Disjunction ) | ||
// ( ? RegularExpressionFlags - RegularExpressionFlags : Disjunction ) | ||
// ExtendedAtom :: | ||
@@ -771,2 +782,5 @@ // ExtendedPatternCharacter | ||
} | ||
else if (features.modifiers && str.indexOf("(?") == pos && str[pos+2] != ":") { | ||
return parseModifiersGroup(); | ||
} | ||
else { | ||
@@ -779,2 +793,46 @@ // ( Disjunction ) | ||
function parseModifiersGroup() { | ||
function hasDupChar(str) { | ||
var i = 0; | ||
while (i < str.length) { | ||
if (str.indexOf(str[i], i + 1) != -1) { | ||
return true; | ||
} | ||
i++; | ||
} | ||
return false; | ||
} | ||
var from = pos; | ||
incr(2); | ||
var enablingFlags = matchReg(/^[sim]+/); | ||
var disablingFlags; | ||
if(match("-")){ | ||
disablingFlags = matchReg(/^[sim]+/); | ||
if (!disablingFlags) { | ||
bail('Invalid flags for modifiers group'); | ||
} | ||
} else if(!enablingFlags){ | ||
bail('Invalid flags for modifiers group'); | ||
} | ||
enablingFlags = enablingFlags ? enablingFlags[0] : ""; | ||
disablingFlags = disablingFlags ? disablingFlags[0] : ""; | ||
var flags = enablingFlags + disablingFlags; | ||
if(flags.length > 3 || hasDupChar(flags)) { | ||
bail('flags cannot be duplicated for modifiers group'); | ||
} | ||
var modifiersGroup = finishGroup("ignore", from); | ||
modifiersGroup.modifierFlags = { | ||
enabling: enablingFlags, | ||
disabling: disablingFlags | ||
}; | ||
return modifiersGroup; | ||
} | ||
function parseUnicodeSurrogatePairEscape(firstEscape) { | ||
@@ -781,0 +839,0 @@ if (isUnicodeMode) { |
65737
1661