From bee04ffd99eaedc306acbc72a21968c3fbb2e505 Mon Sep 17 00:00:00 2001 From: Steven Levithan Date: Sun, 27 Oct 2024 15:08:59 +0100 Subject: [PATCH] Quantifier without quantifiable token --- dist/index.min.js | 2 +- src/parse.js | 11 ++++++++--- src/tokenize.js | 1 + src/transform.js | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/dist/index.min.js b/dist/index.min.js index efe1cc7..79634fa 100644 --- a/dist/index.min.js +++ b/dist/index.min.js @@ -32,7 +32,7 @@ var OnigurumaToES=(()=>{var ee=Object.defineProperty;var dt=Object.getOwnPropert | && | . `.replace(/\s+/g,""),"gsu");function R(e,t=""){if(!/^[imx]*$/.test(t))throw new Error(`Flags "${t}" unsupported in Oniguruma`);let r=[t.includes("x")],s={getCurrentModX:()=>r.at(-1),popModX(){r.pop()},pushModX(c){r.push(c)},replaceCurrentModX(c){r[r.length-1]=c}},n=[],a;for(W.lastIndex=0;a=W.exec(e);){let c=Nt(s,e,a[0],W.lastIndex);c.tokens?n.push(...c.tokens):c.token&&n.push(c.token),c.lastIndex!==void 0&&(W.lastIndex=c.lastIndex)}let o=[],i=0;n.forEach(c=>{c.type===g.GroupOpen&&(c.kind===_.capturing?(i++,c.number=i):c.raw==="("&&o.push(c))}),i||o.forEach((c,p)=>{c.kind=_.capturing,c.number=p+1});let u=i||o.length;return n=n.map(c=>c.type===g.EscapedNumber?Dt(c,u):c).flat(),{tokens:n,flags:{ignoreCase:t.includes("i"),dotAll:t.includes("m"),extended:t.includes("x")}}}function Nt(e,t,r,s){let[n,a,o]=r;if(n==="["){let i=It(t,r,s);return{tokens:i.tokens,lastIndex:i.lastIndex}}if(n==="\\")return"AbBGzZ".includes(a)?{token:m(g.Assertion,r,{kind:r})}:/^\\g[<']/.test(r)?{token:m(g.Subroutine,r)}:/^\\k[<']/.test(r)?{token:m(g.Backreference,r)}:a==="K"?{token:m(g.Directive,r,{kind:V.keep})}:"RX".includes(a)?{token:m(g.VariableLengthCharacterSet,r,{kind:r})}:{token:De(r,{inCharClass:!1})};if(n==="("){if(o==="#"){if(t[s]!==")")throw new Error('Unclosed comment group "(?#"');return{lastIndex:s+1}}if("-imx".includes(o))return{token:xt(r,e)};if(e.pushModX(e.getCurrentModX()),r==="("||r==="(?:")return{token:m(g.GroupOpen,r,{kind:_.group})};if(r==="(?>")return{token:m(g.GroupOpen,r,{kind:_.atomic})};if(r==="(?="||r==="(?!"||r==="(?<="||r==="(?\^?)(?[a-z]+):\]/.exec(e);if(!t||!K.get(t.groups.name))throw new Error(`Invalid POSIX class "${e}"`);return m(g.CharacterSet,e,{kind:S.posix,negate:!!t.groups.negate,value:t.groups.name})}return e==="-"?m(g.CharacterClassHyphen,e):e==="&&"?m(g.CharacterClassIntersector,e):(Re(e),m(g.Character,e,{value:e.codePointAt(0)}))}function De(e,{inCharClass:t}){let r=e[1];if(r==="c"||r==="C")return Ft(e);if("dDhHsSwW".includes(r))return Pt(e);if(/^\\[pP]\{/.test(e)){if(e.length===3)throw new Error("Incomplete or invalid Unicode property");return Tt(e)}if(r==="u"||r==="x")return m(g.Character,e,{value:vt(e)});if(Ne.has(r))return m(g.Character,e,{value:Ne.get(r)});if(/\d/.test(r))return m(g.EscapedNumber,e,{inCharClass:t});if(e==="\\")throw new Error(f`Incomplete escape "\"`);if(r==="M")throw new Error(`Unsupported meta escape "${e}"`);if(e.length===2)return m(g.Character,e,{value:e.codePointAt(1)});throw new Error(`Unexpected escape "${e}"`)}function m(e,t,r){return{type:e,raw:t,...r}}function Ft(e){let t=e[1]==="c"?e[2]:e[3];if(!t||!/[a-zA-Z]/.test(t))throw new Error(`Unsupported control character "${e}"`);return m(g.Character,e,{value:t.toUpperCase().codePointAt(0)-64})}function xt(e,t){let{on:r,off:s}=/^\(\?(?[imx]*)(?:-(?[imx\-]*))?/.exec(e).groups;s??="";let n=(t.getCurrentModX()||r.includes("x"))&&!s.includes("x"),a=Ie(r),o=Ie(s),i={};if(a&&(i.enable=a),o&&(i.disable=o),e.endsWith(")"))return t.replaceCurrentModX(n),m(g.Directive,e,{kind:V.flags,flags:i});if(e.endsWith(":")){t.pushModX(n);let u=m(g.GroupOpen,e,{kind:_.group});return(a||o)&&(u.flags=i),u}throw new Error(`Unexpected flag modifier "${e}"`)}function Lt(e){let t={};if(e[0]==="{"){let{min:r,max:s}=/^\{(?\d+)(?:,(?\d*))?/.exec(e).groups,n=1e5;if(+r>n||+s>n)throw new Error("Quantifier value unsupported in Oniguruma");t.min=+r,t.max=s===void 0?+r:s===""?1/0:+s,t.greedy=!e.endsWith("?"),t.possessive=!1}else t.min=e[0]==="+"?1:0,t.max=e[0]==="?"?1:1/0,t.greedy=e[1]!=="?",t.possessive=e[1]==="+";return m(g.Quantifier,e,t)}function Pt(e){let t=e[1].toLowerCase();return m(g.CharacterSet,e,{kind:{d:S.digit,h:S.hex,s:S.space,w:S.word}[t],negate:e[1]!==t})}function Tt(e){let{p:t,neg:r,value:s}=/^\\(?

[pP])\{(?\^?)(?[ \w]+)/.exec(e).groups,n=t==="P"&&!r||t==="p"&&!!r;return m(g.CharacterSet,e,{kind:S.property,negate:n,value:s})}function vt(e){if(/^(?:\\x$|\\u(?!\p{AHex}{4}|\{\s*\p{AHex}{1,6}\s*\}))/u.test(e))throw new Error(`Incomplete or invalid escape "${e}"`);let t=e[2]==="{"?/^\\u\{\s*(?\p{AHex}+)/u.exec(e).groups.hex:e.slice(2),r=parseInt(t,16);if(r>1114111)throw new Error(`Invalid escape out of range "${e}"`);return r}function Ie(e){let t={};return e.includes("i")&&(t.ignoreCase=!0),e.includes("m")&&(t.dotAll=!0),e.includes("x")&&(t.extended=!0),Object.keys(t).length?t:null}function Dt(e,t){let{raw:r,inCharClass:s}=e,n=r.slice(1);if(!s&&(n!=="0"&&n.length===1||n[0]!=="0"&&+n<=t))return[m(g.Backreference,r)];let a=[],o=n.match(/^[0-7]+|\d/g);for(let i=0;i!!r[b]),w=C&&r[C],L=typeof w=="function"?w:w?.enter,k=w?.exit;if(L?.(d,t),!h)switch(o.type){case l.Regex:a(o.pattern,o,"pattern"),a(o.flags,o,"flags");break;case l.Alternative:case l.CharacterClass:n(o.elements,o);break;case l.Assertion:(o.kind===E.lookahead||o.kind===E.lookbehind)&&n(o.alternatives,o);break;case l.Backreference:case l.Character:case l.CharacterSet:case l.Directive:case l.Flags:case l.Recursion:case l.Subroutine:case l.VariableLengthCharacterSet:break;case l.CapturingGroup:case l.Group:case l.Pattern:n(o.alternatives,o);break;case l.CharacterClassIntersection:n(o.classes,o);break;case l.CharacterClassRange:a(o.min,o,"min"),a(o.max,o,"max");break;case l.Quantifier:a(o.element,o,"element");break;default:throw new Error(`Unexpected node type "${o.type}"`)}return k?.(d,t),p}a(e.node,e.parent,e.key,e.container)}function Rt(e,t){"parent"in t&&(e.parent=t)}var l={Alternative:"Alternative",Assertion:"Assertion",Backreference:"Backreference",CapturingGroup:"CapturingGroup",Character:"Character",CharacterClass:"CharacterClass",CharacterClassIntersection:"CharacterClassIntersection",CharacterClassRange:"CharacterClassRange",CharacterSet:"CharacterSet",Directive:"Directive",Flags:"Flags",Group:"Group",Pattern:"Pattern",Quantifier:"Quantifier",Regex:"Regex",Subroutine:"Subroutine",VariableLengthCharacterSet:"VariableLengthCharacterSet",Recursion:"Recursion"},Oe={AnyGroup:"AnyGroup",AnyNode:"AnyNode"};function Ue({type:e,kind:t}){let r=[Oe.AnyNode];return(e===l.Assertion&&(t===E.lookahead||t===E.lookbehind)||e===l.CapturingGroup||e===l.Group)&&r.push(Oe.AnyGroup),r.push(e),r}var E={line_end:"line_end",line_start:"line_start",lookahead:"lookahead",lookbehind:"lookbehind",search_start:"search_start",string_end:"string_end",string_end_newline:"string_end_newline",string_start:"string_start",word_boundary:"word_boundary"},$=S,D=V,j={newline:"newline",grapheme:"grapheme"};function U({tokens:e,flags:t},r){let s={bypassPropertyNameCheck:!1,optimize:!0,...r},n={bypassPropertyNameCheck:s.bypassPropertyNameCheck,capturingGroups:[],current:0,hasNumberedRef:!1,namedGroupsByName:new Map,optimize:s.optimize,parent:null,subroutines:[],token:null,tokens:e,walk:a};function a(d,C){let w=e[n.current];switch(n.parent=d,n.token=w,n.current++,w.type){case g.Alternator:return T();case g.Assertion:return Be(w);case g.Backreference:return Ut(n);case g.Character:return Ve(w.value);case g.CharacterClassHyphen:return Ot(n,C);case g.CharacterClassOpen:return Gt(n,C);case g.CharacterSet:return Mt(n);case g.Directive:return Qt(w);case g.GroupOpen:return Bt(n,C);case g.Quantifier:return Vt(n);case g.Subroutine:return jt(n);case g.VariableLengthCharacterSet:return er(w.kind);default:throw new Error(`Unexpected token type "${w.type}"`)}}let o=Zt(Xt(),qt(t)),i=o.pattern.alternatives[0];for(;n.currentu.length)throw new Error("Subroutine uses a group number that's not defined")}else if(p.has(d)){if(p.get(d).length>1)throw new Error(f`Subroutine uses a duplicate group name "\g<${d}>"`)}else throw new Error(f`Subroutine uses a group name that's not defined "\g<${d}>"`);return y({node:o},null,{AnyNode({node:d,parent:C}){d.parent=C}}),o}function Ut(e){let{raw:t}=e.token,r=/^\\k[<']/.test(t),s=r?t.slice(3,-1):t.slice(1),n=(a,o=!1)=>{let i=e.capturingGroups.length;if(a>i)throw new Error(`Not enough capturing groups defined to the left "${t}"`);return e.hasNumberedRef=!0,Q(o?i+1-a:a)};if(r){let a=/^(?-?)0*(?[1-9]\d*)$/.exec(s);if(a)return n(+a.groups.num,!!a.groups.sign);if(/[-+]/.test(s))throw new Error(`Invalid backref name "${t}"`);if(!e.namedGroupsByName.has(s))throw new Error(`Group name not defined to the left "${t}"`);return Q(s)}return n(+s)}function Ot(e,t){let{parent:r,tokens:s,walk:n}=e,a=r.elements.at(-1),o=s[e.current];if(a&&a.type!==l.CharacterClass&&o&&o.type!==g.CharacterClassOpen&&o.type!==g.CharacterClassClose&&o.type!==g.CharacterClassIntersector){let i=n(r,t);if(a.type===l.Character&&i.type===l.Character)return r.elements.pop(),Wt(a,i);throw new Error("Invalid character class range")}return Ve(45)}function Gt(e,t){let{token:r,tokens:s,optimize:n,walk:a}=e,o=ce({negate:r.negate}),i=o.elements[0],u=Ge(s[e.current]);for(;u.type!==g.CharacterClassClose;){if(u.type===g.CharacterClassIntersector)i.classes.push(ce({negate:!1,baseOnly:!0})),e.current++;else{let c=i.classes.at(-1);c.elements.push(a(c,t))}u=Ge(s[e.current])}if(n&&sr(i),i.classes.length===1){let c=i.classes[0];c.negate=o.negate!==c.negate,o=c}return e.current++,o}function Mt({token:e,bypassPropertyNameCheck:t}){let{kind:r,negate:s,value:n}=e;if(r===S.property){let o=B(n);if($e.has(o))r=S.posix,n=o;else return pe(n,{negate:s,allowAnyName:t})}let a={type:l.CharacterSet,kind:I($[r],`Unexpected character set kind "${r}"`)};return(r===S.digit||r===S.hex||r===S.posix||r===S.space||r===S.word)&&(a.negate=s,r===S.posix&&(a.value=n)),a}function Bt(e,t){let{token:r,tokens:s,optimize:n,capturingGroups:a,namedGroupsByName:o,walk:i}=e,u=Ht(r);u.type===l.CapturingGroup&&(a.push(u),u.name&&v(o,u.name,[]).push(u));let c=Me(s[e.current]);for(;c.type!==g.GroupClose;){if(c.type===g.Alternator)u.alternatives.push(T()),e.current++;else{let p=u.alternatives.at(-1);t.isInLookbehind||=u.kind===E.lookbehind;let h=i(p,t);if(p.elements.push(h),t.isInLookbehind&&h.type===l.Quantifier&&h.min!==h.max)throw new Error("Variable repetition within lookbehind unsupported in Oniguruma")}c=Me(s[e.current])}return n&&(u=rr(u)),e.current++,u}function Vt({token:e,parent:t}){let{min:r,max:s,greedy:n,possessive:a}=e;if(!t.elements.length)throw new Error("Nothing to repeat");let o=Jt(t.elements.at(-1),r,s,n,a);return t.elements.pop(),o}function jt(e){let{token:t,capturingGroups:r,subroutines:s}=e,n=t.raw.slice(3,-1),a=/^(?[-+]?)0*(?[1-9]\d*)$/.exec(n);if(a){let i=+a.groups.num,u=r.length;if(e.hasNumberedRef=!0,n={"":i,"+":u+i,"-":u+1-i}[a.groups.sign],n<1)throw new Error("Invalid subroutine number")}else n==="0"&&(n=0);let o=Yt(n);return s.push(o),o}function T(){return{type:l.Alternative,elements:[]}}function Be({type:e,kind:t,negate:r}){if(e===g.GroupOpen)return le({behind:t===_.lookbehind,negate:r});let s=I({"^":E.line_start,$:E.line_end,"\\A":E.string_start,"\\b":E.word_boundary,"\\B":E.word_boundary,"\\G":E.search_start,"\\z":E.string_end,"\\Z":E.string_end_newline}[t],`Unexpected assertion kind "${t}"`),n={type:l.Assertion,kind:s};return s===E.word_boundary&&(n.negate=t===f`\B`),n}function Q(e){return{type:l.Backreference,ref:e}}function Ht(e){let{kind:t,number:r,name:s,flags:n}=e;switch(t){case _.atomic:return F({atomic:!0});case _.capturing:return zt(r,s);case _.group:return F({flags:n});case _.lookahead:case _.lookbehind:return Be(e);default:throw new Error(`Unexpected group kind "${t}"`)}}function zt(e,t){let r=t!==void 0;if(r&&!nr(t))throw new Error(`Group name "${t}" invalid in Oniguruma`);return{type:l.CapturingGroup,number:e,...r&&{name:t},alternatives:[T()]}}function Ve(e){return{type:l.Character,value:e}}function ce(e){let t={baseOnly:!1,negate:!1,...e};return{type:l.CharacterClass,negate:t.negate,elements:t.baseOnly?[]:[Kt()]}}function Kt(){return{type:l.CharacterClassIntersection,classes:[ce({negate:!1,baseOnly:!0})]}}function Wt(e,t){if(t.values[0].toUpperCase()+s.slice(1).toLowerCase())}function rr(e){let t=e.alternatives[0],r=t.elements[0];return e.type===l.Group&&e.alternatives.length===1&&t.elements.length===1&&r.type===l.Group&&!(e.atomic&&r.flags)&&!(e.flags&&(r.atomic||r.flags))?(e.atomic?r.atomic=!0:e.flags&&(r.flags=e.flags),r):e}function nr(e){return!/^(?:[-\d]|$)/.test(e)}function sr(e){for(let t=0;ta.kind===D.flags);for(let a=r+1;a\^?)(?[a-z]+):\]/.exec(e);if(!t||!K.get(t.groups.name))throw new Error(`Invalid POSIX class "${e}"`);return m(g.CharacterSet,e,{kind:S.posix,negate:!!t.groups.negate,value:t.groups.name})}return e==="-"?m(g.CharacterClassHyphen,e):e==="&&"?m(g.CharacterClassIntersector,e):(Re(e),m(g.Character,e,{value:e.codePointAt(0)}))}function De(e,{inCharClass:t}){let r=e[1];if(r==="c"||r==="C")return Ft(e);if("dDhHsSwW".includes(r))return Pt(e);if(/^\\[pP]\{/.test(e)){if(e.length===3)throw new Error("Incomplete or invalid Unicode property");return Tt(e)}if(r==="u"||r==="x")return m(g.Character,e,{value:vt(e)});if(Ne.has(r))return m(g.Character,e,{value:Ne.get(r)});if(/\d/.test(r))return m(g.EscapedNumber,e,{inCharClass:t});if(e==="\\")throw new Error(f`Incomplete escape "\"`);if(r==="M")throw new Error(`Unsupported meta escape "${e}"`);if(e.length===2)return m(g.Character,e,{value:e.codePointAt(1)});throw new Error(`Unexpected escape "${e}"`)}function m(e,t,r){return{type:e,raw:t,...r}}function Ft(e){let t=e[1]==="c"?e[2]:e[3];if(!t||!/[a-zA-Z]/.test(t))throw new Error(`Unsupported control character "${e}"`);return m(g.Character,e,{value:t.toUpperCase().codePointAt(0)-64})}function xt(e,t){let{on:r,off:s}=/^\(\?(?[imx]*)(?:-(?[imx\-]*))?/.exec(e).groups;s??="";let n=(t.getCurrentModX()||r.includes("x"))&&!s.includes("x"),a=Ie(r),o=Ie(s),i={};if(a&&(i.enable=a),o&&(i.disable=o),e.endsWith(")"))return t.replaceCurrentModX(n),m(g.Directive,e,{kind:V.flags,flags:i});if(e.endsWith(":")){t.pushModX(n);let u=m(g.GroupOpen,e,{kind:_.group});return(a||o)&&(u.flags=i),u}throw new Error(`Unexpected flag modifier "${e}"`)}function Lt(e){let t={};if(e[0]==="{"){let{min:r,max:s}=/^\{(?\d+)(?:,(?\d*))?/.exec(e).groups,n=1e5;if(+r>n||+s>n)throw new Error("Quantifier value unsupported in Oniguruma");t.min=+r,t.max=s===void 0?+r:s===""?1/0:+s,t.greedy=!e.endsWith("?"),t.possessive=!1}else t.min=e[0]==="+"?1:0,t.max=e[0]==="?"?1:1/0,t.greedy=e[1]!=="?",t.possessive=e[1]==="+";return m(g.Quantifier,e,t)}function Pt(e){let t=e[1].toLowerCase();return m(g.CharacterSet,e,{kind:{d:S.digit,h:S.hex,s:S.space,w:S.word}[t],negate:e[1]!==t})}function Tt(e){let{p:t,neg:r,value:s}=/^\\(?

[pP])\{(?\^?)(?[ \w]+)/.exec(e).groups,n=t==="P"&&!r||t==="p"&&!!r;return m(g.CharacterSet,e,{kind:S.property,negate:n,value:s})}function vt(e){if(/^(?:\\x$|\\u(?!\p{AHex}{4}|\{\s*\p{AHex}{1,6}\s*\}))/u.test(e))throw new Error(`Incomplete or invalid escape "${e}"`);let t=e[2]==="{"?/^\\u\{\s*(?\p{AHex}+)/u.exec(e).groups.hex:e.slice(2),r=parseInt(t,16);if(r>1114111)throw new Error(`Invalid escape out of range "${e}"`);return r}function Ie(e){let t={};return e.includes("i")&&(t.ignoreCase=!0),e.includes("m")&&(t.dotAll=!0),e.includes("x")&&(t.extended=!0),Object.keys(t).length?t:null}function Dt(e,t){let{raw:r,inCharClass:s}=e,n=r.slice(1);if(!s&&(n!=="0"&&n.length===1||n[0]!=="0"&&+n<=t))return[m(g.Backreference,r)];let a=[],o=n.match(/^[0-7]+|\d/g);for(let i=0;i!!r[b]),w=C&&r[C],L=typeof w=="function"?w:w?.enter,k=w?.exit;if(L?.(d,t),!h)switch(o.type){case l.Regex:a(o.pattern,o,"pattern"),a(o.flags,o,"flags");break;case l.Alternative:case l.CharacterClass:n(o.elements,o);break;case l.Assertion:(o.kind===E.lookahead||o.kind===E.lookbehind)&&n(o.alternatives,o);break;case l.Backreference:case l.Character:case l.CharacterSet:case l.Directive:case l.Flags:case l.Recursion:case l.Subroutine:case l.VariableLengthCharacterSet:break;case l.CapturingGroup:case l.Group:case l.Pattern:n(o.alternatives,o);break;case l.CharacterClassIntersection:n(o.classes,o);break;case l.CharacterClassRange:a(o.min,o,"min"),a(o.max,o,"max");break;case l.Quantifier:a(o.element,o,"element");break;default:throw new Error(`Unexpected node type "${o.type}"`)}return k?.(d,t),p}a(e.node,e.parent,e.key,e.container)}function Rt(e,t){"parent"in t&&(e.parent=t)}var l={Alternative:"Alternative",Assertion:"Assertion",Backreference:"Backreference",CapturingGroup:"CapturingGroup",Character:"Character",CharacterClass:"CharacterClass",CharacterClassIntersection:"CharacterClassIntersection",CharacterClassRange:"CharacterClassRange",CharacterSet:"CharacterSet",Directive:"Directive",Flags:"Flags",Group:"Group",Pattern:"Pattern",Quantifier:"Quantifier",Regex:"Regex",Subroutine:"Subroutine",VariableLengthCharacterSet:"VariableLengthCharacterSet",Recursion:"Recursion"},Oe={AnyGroup:"AnyGroup",AnyNode:"AnyNode"};function Ue({type:e,kind:t}){let r=[Oe.AnyNode];return(e===l.Assertion&&(t===E.lookahead||t===E.lookbehind)||e===l.CapturingGroup||e===l.Group)&&r.push(Oe.AnyGroup),r.push(e),r}var E={line_end:"line_end",line_start:"line_start",lookahead:"lookahead",lookbehind:"lookbehind",search_start:"search_start",string_end:"string_end",string_end_newline:"string_end_newline",string_start:"string_start",word_boundary:"word_boundary"},$=S,D=V,j={newline:"newline",grapheme:"grapheme"};function U({tokens:e,flags:t},r){let s={bypassPropertyNameCheck:!1,optimize:!0,...r},n={bypassPropertyNameCheck:s.bypassPropertyNameCheck,capturingGroups:[],current:0,hasNumberedRef:!1,namedGroupsByName:new Map,optimize:s.optimize,parent:null,subroutines:[],token:null,tokens:e,walk:a};function a(d,C){let w=e[n.current];switch(n.parent=d,n.token=w,n.current++,w.type){case g.Alternator:return T();case g.Assertion:return Be(w);case g.Backreference:return Ut(n);case g.Character:return Ve(w.value);case g.CharacterClassHyphen:return Ot(n,C);case g.CharacterClassOpen:return Gt(n,C);case g.CharacterSet:return Mt(n);case g.Directive:return Qt(w);case g.GroupOpen:return Bt(n,C);case g.Quantifier:return Vt(n);case g.Subroutine:return jt(n);case g.VariableLengthCharacterSet:return er(w.kind);default:throw new Error(`Unexpected token type "${w.type}"`)}}let o=Zt(Xt(),qt(t)),i=o.pattern.alternatives[0];for(;n.currentu.length)throw new Error("Subroutine uses a group number that's not defined")}else if(p.has(d)){if(p.get(d).length>1)throw new Error(f`Subroutine uses a duplicate group name "\g<${d}>"`)}else throw new Error(f`Subroutine uses a group name that's not defined "\g<${d}>"`);return y({node:o},null,{AnyNode({node:d,parent:C}){d.parent=C}}),o}function Ut(e){let{raw:t}=e.token,r=/^\\k[<']/.test(t),s=r?t.slice(3,-1):t.slice(1),n=(a,o=!1)=>{let i=e.capturingGroups.length;if(a>i)throw new Error(`Not enough capturing groups defined to the left "${t}"`);return e.hasNumberedRef=!0,Q(o?i+1-a:a)};if(r){let a=/^(?-?)0*(?[1-9]\d*)$/.exec(s);if(a)return n(+a.groups.num,!!a.groups.sign);if(/[-+]/.test(s))throw new Error(`Invalid backref name "${t}"`);if(!e.namedGroupsByName.has(s))throw new Error(`Group name not defined to the left "${t}"`);return Q(s)}return n(+s)}function Ot(e,t){let{parent:r,tokens:s,walk:n}=e,a=r.elements.at(-1),o=s[e.current];if(a&&a.type!==l.CharacterClass&&o&&o.type!==g.CharacterClassOpen&&o.type!==g.CharacterClassClose&&o.type!==g.CharacterClassIntersector){let i=n(r,t);if(a.type===l.Character&&i.type===l.Character)return r.elements.pop(),Wt(a,i);throw new Error("Invalid character class range")}return Ve(45)}function Gt(e,t){let{token:r,tokens:s,optimize:n,walk:a}=e,o=ce({negate:r.negate}),i=o.elements[0],u=Ge(s[e.current]);for(;u.type!==g.CharacterClassClose;){if(u.type===g.CharacterClassIntersector)i.classes.push(ce({negate:!1,baseOnly:!0})),e.current++;else{let c=i.classes.at(-1);c.elements.push(a(c,t))}u=Ge(s[e.current])}if(n&&sr(i),i.classes.length===1){let c=i.classes[0];c.negate=o.negate!==c.negate,o=c}return e.current++,o}function Mt({token:e,bypassPropertyNameCheck:t}){let{kind:r,negate:s,value:n}=e;if(r===S.property){let o=B(n);if($e.has(o))r=S.posix,n=o;else return pe(n,{negate:s,allowAnyName:t})}let a={type:l.CharacterSet,kind:I($[r],`Unexpected character set kind "${r}"`)};return(r===S.digit||r===S.hex||r===S.posix||r===S.space||r===S.word)&&(a.negate=s,r===S.posix&&(a.value=n)),a}function Bt(e,t){let{token:r,tokens:s,optimize:n,capturingGroups:a,namedGroupsByName:o,walk:i}=e,u=Ht(r);u.type===l.CapturingGroup&&(a.push(u),u.name&&v(o,u.name,[]).push(u));let c=Me(s[e.current]);for(;c.type!==g.GroupClose;){if(c.type===g.Alternator)u.alternatives.push(T()),e.current++;else{let p=u.alternatives.at(-1);t.isInLookbehind||=u.kind===E.lookbehind;let h=i(p,t);if(p.elements.push(h),t.isInLookbehind&&h.type===l.Quantifier&&h.min!==h.max)throw new Error("Variable repetition within lookbehind unsupported in Oniguruma")}c=Me(s[e.current])}return n&&(u=rr(u)),e.current++,u}function Vt({token:e,parent:t}){let{min:r,max:s,greedy:n,possessive:a}=e,o=t.elements.at(-1);if(!o||o.type===l.Directive)throw new Error("Quantifier requires a repeatable token");let i=Jt(o,r,s,n,a);return t.elements.pop(),i}function jt(e){let{token:t,capturingGroups:r,subroutines:s}=e,n=t.raw.slice(3,-1),a=/^(?[-+]?)0*(?[1-9]\d*)$/.exec(n);if(a){let i=+a.groups.num,u=r.length;if(e.hasNumberedRef=!0,n={"":i,"+":u+i,"-":u+1-i}[a.groups.sign],n<1)throw new Error("Invalid subroutine number")}else n==="0"&&(n=0);let o=Yt(n);return s.push(o),o}function T(){return{type:l.Alternative,elements:[]}}function Be({type:e,kind:t,negate:r}){if(e===g.GroupOpen)return le({behind:t===_.lookbehind,negate:r});let s=I({"^":E.line_start,$:E.line_end,"\\A":E.string_start,"\\b":E.word_boundary,"\\B":E.word_boundary,"\\G":E.search_start,"\\z":E.string_end,"\\Z":E.string_end_newline}[t],`Unexpected assertion kind "${t}"`),n={type:l.Assertion,kind:s};return s===E.word_boundary&&(n.negate=t===f`\B`),n}function Q(e){return{type:l.Backreference,ref:e}}function Ht(e){let{kind:t,number:r,name:s,flags:n}=e;switch(t){case _.atomic:return F({atomic:!0});case _.capturing:return zt(r,s);case _.group:return F({flags:n});case _.lookahead:case _.lookbehind:return Be(e);default:throw new Error(`Unexpected group kind "${t}"`)}}function zt(e,t){let r=t!==void 0;if(r&&!nr(t))throw new Error(`Group name "${t}" invalid in Oniguruma`);return{type:l.CapturingGroup,number:e,...r&&{name:t},alternatives:[T()]}}function Ve(e){return{type:l.Character,value:e}}function ce(e){let t={baseOnly:!1,negate:!1,...e};return{type:l.CharacterClass,negate:t.negate,elements:t.baseOnly?[]:[Kt()]}}function Kt(){return{type:l.CharacterClassIntersection,classes:[ce({negate:!1,baseOnly:!0})]}}function Wt(e,t){if(t.values[0].toUpperCase()+s.slice(1).toLowerCase())}function rr(e){let t=e.alternatives[0],r=t.elements[0];return e.type===l.Group&&e.alternatives.length===1&&t.elements.length===1&&r.type===l.Group&&!(e.atomic&&r.flags)&&!(e.flags&&(r.atomic||r.flags))?(e.atomic?r.atomic=!0:e.flags&&(r.flags=e.flags),r):e}function nr(e){return!/^(?:[-\d]|$)/.test(e)}function sr(e){for(let t=0;ta.kind===D.flags);for(let a=r+1;a1)throw new Error(f`Uses "\K" in a way that's unsupported for conversion to JS`);o(H(le({behind:!0}),i()))}},Flags({node:e,parent:t}){delete e.extended,Object.assign(e,{global:!1,hasIndices:!1,multiline:!1,sticky:e.sticky??!1}),t.options={disable:{x:!0,n:!0},force:{v:!0}}},Group({node:e}){if(!e.flags)return;let{enable:t,disable:r}=e.flags;t?.dotAll&&r?.dotAll&&delete t.dotAll,t?.ignoreCase&&r?.ignoreCase&&delete t.ignoreCase,t&&!Object.keys(t).length&&delete e.flags.enable},Pattern({node:e}){let t=!1,r=!1;for(let s of e.alternatives)s.elements.sort((n,a)=>n.kind===E.search_start&&a.kind===D.flags?-1:n.kind===D.flags&&a.kind===E.search_start?1:0),s.elements[0]?.kind===E.search_start?t=!0:r=!0;if(t&&r)throw new Error(f`Uses "\G" in a way that's unsupported for conversion to JS`)},Quantifier({node:e}){if(e.element.type===l.Quantifier){let t=H(F(),[e.element]);t.parent=e,e.element=t}},VariableLengthCharacterSet({node:e,replaceWith:t},{allowBestEffort:r,minTargetEs2024:s}){let{kind:n}=e;if(n===j.newline)t(x(f`(?>\r\n?|[\n\v\f\x85\u2028\u2029])`));else if(n===j.grapheme){if(!r)throw new Error(f`Use of "\X" requires option allowBestEffort`);let a=s?f`\p{RGI_Emoji}`:be().source;t(x(f`(?>\r\n|${a}|\P{M}\p{M}*)`,{bypassPropertyNameCheck:!0}))}else throw new Error(`Unexpected varcharset kind "${n}"`)}},ze={Alternative({node:e},{namedGroupsInScopeByAlt:t}){let r=q(e);if(r){let s=t.get(r);s&&t.set(e,s)}},Backreference({node:e},{multiplexCapturesToLeftByRef:t,reffedNodesByBackreference:r}){let{ref:s}=e;r.set(e,[...t.get(s).map(({node:n})=>n)])},CapturingGroup:{enter({node:e,replaceWith:t,skip:r},{groupOriginByCopy:s,groupsWithDuplicateNamesToRemove:n,multiplexCapturesToLeftByRef:a,namedGroupsInScopeByAlt:o,openDirectCaptures:i,openSubroutineRefs:u}){let{name:c,number:p}=e,h=c??p,d=s.get(e),C=u.has(h)||i.has(d),w=C&&!u.size;if(C&&!w)throw new Error("Unsupported indirect recursion");if(d?u.add(h):i.add(e),w){t(je(h)),r();return}let L=v(a,h,[]);for(let k=0;kw.type===l.Group&&!!w.flags));C&&(d=H(F({flags:C}),[h]))}n(d),p||y({node:d,parent:t,key:r,container:s},a,ze)}},ar={CapturingGroup({node:e},t){e.number=++t.numCapturesToLeft,t.groupsWithDuplicateNamesToRemove.has(e)&&delete e.name},Backreference({node:e,replaceWith:t},{reffedNodesByBackreference:r}){let s=r.get(e);if(s.length>1){let n=s.map(a=>X(T(),[Q(a.number)]));t(X(F(),n))}else e.ref=s[0].number}};function X(e,t){return t.forEach(r=>r.parent=e),e[We(e)]=t,e}function Ke(e,t,r,s){let n=Array.isArray(e)?[]:{};for(let[a,o]of Object.entries(e))a==="parent"?n.parent=Array.isArray(r)?s:r:o&&typeof o=="object"?n[a]=Ke(o,t,n,r):(a==="type"&&o===l.CapturingGroup&&t.set(n,e),n[a]=o);return n}function je(e){if(typeof e=="number"&&e!==0)throw new Error("Unsupported recursion by number; use name instead");return{type:l.Recursion,ref:e}}function or(e,t){let r=[];for(;e=e.parent;)(!t||t(e))&&r.push(e);return r}function We(e){if(e.alternatives)return"alternatives";if(e.elements)return"elements";if(e.classes)return"classes";throw new Error("Accessor for child container unknown")}function Qe(e){let t=["dotAll","ignoreCase"],r={enable:{},disable:{}};return e.forEach(({flags:s})=>{t.forEach(n=>{s.enable?.[n]&&(delete r.disable[n],r.enable[n]=!0),s.disable?.[n]&&(r.disable[n]=!0)})}),Object.keys(r.enable).length||delete r.enable,Object.keys(r.disable).length||delete r.disable,r.enable||r.disable?r:null}function q(e){for(;e=e.parent;)if(e.type===l.Alternative)return e;return null}function ir(e){return/^[$_\p{IDS}][$\u200C\u200D\p{IDC}]*$/u.test(e)}function x(e,{bypassPropertyNameCheck:t}={}){let s=U(R(e),{bypassPropertyNameCheck:t}).pattern.alternatives;return s.length>1||s[0].elements.length>1?X(F(),s):s[0].elements[0]}function H(e,t){let r=We(e);return e[r][0].parent=e,t&&X(e[r][0],t),e}function Xe(e,t){let r=ge(t),s=M(r.target,"ES2024"),n=M(r.target,"ESNext"),a=r.maxRecursionDepth;if(a!==null&&(!Number.isInteger(a)||a<2||a>100))throw new Error("Invalid maxRecursionDepth; use null or 2-100");let o=null,i=null;if(!n){let C=[e.flags.ignoreCase];y({node:e},{getCurrentModI:()=>C.at(-1),popModI(){C.pop()},pushModI(w){C.push(w)},setHasCasedChar(){C.at(-1)?o=!0:i=!0}},ur)}let u={dotAll:e.flags.dotAll,ignoreCase:!!((e.flags.ignoreCase||o)&&!i)},c=null,p={allowBestEffort:r.allowBestEffort,appliedGlobalFlags:u,captureFlagIMap:new Map,currentFlags:{dotAll:e.flags.dotAll,ignoreCase:e.flags.ignoreCase},groupNames:new Set,inCharClass:!1,lastNode:c,maxRecursionDepth:a,optimize:r.optimize,useAppliedIgnoreCase:!!(!n&&o&&i),useDuplicateNames:n,useFlagMods:n,useFlagV:s,usePostEs2018Properties:s};function h(C){switch(p.lastNode=c,c=C,C.type){case l.Regex:return{pattern:h(C.pattern),flags:h(C.flags),options:{...C.options}};case l.Alternative:return C.elements.map(h).join("");case l.Assertion:return gr(C,p,h);case l.Backreference:return hr(C,p);case l.CapturingGroup:return dr(C,p,h);case l.Character:return Cr(C,p);case l.CharacterClass:return mr(C,p,h);case l.CharacterClassIntersection:if(!p.useFlagV)throw new Error("Use of class intersection requires target ES2024 or later");return C.classes.map(h).join("&&");case l.CharacterClassRange:return Er(C,p);case l.CharacterSet:return wr(C,p);case l.Flags:return Ar(C,p);case l.Group:return Sr(C,p,h);case l.Pattern:return C.alternatives.map(h).join("|");case l.Quantifier:return h(C.element)+$r(C);case l.Recursion:return kr(C,p);default:throw new Error(`Unexpected node type "${C.type}"`)}}let d=h(e);return s||(delete d.options.force.v,d.options.disable.v=!0,d.options.unicodeSetsPlugin=null),d}var ur={AnyGroup:{enter({node:e},t){let r=t.getCurrentModI();t.pushModI(e.flags?Ze({ignoreCase:r},e.flags).ignoreCase:r)},exit(e,t){t.popModI()}},Backreference(e,t){t.setHasCasedChar()},Character({node:e},t){fe(A(e.value))&&t.setHasCasedChar()},CharacterClassRange({node:e,skip:t},r){t(),Je(e,{firstOnly:!0}).length&&r.setHasCasedChar()},CharacterSet({node:e},t){e.kind===$.property&&ie.has(e.value)&&t.setHasCasedChar()}},cr=new Set(["$","(",")","*","+",".","?","[","\\","]","^","{","|","}"]),lr=new Set(["-","\\","]","^"]),pr=new Set(["(",")","-","/","[","\\","]","^","{","|","}","!","#","$","%","&","*","+",",",".",":",";","<","=",">","?","@","`","~"]),qe=new Map([[9,f`\t`],[10,f`\n`],[11,f`\v`],[12,f`\f`],[13,f`\r`]]),fr=/^\p{Cased}$/u;function fe(e){return fr.test(e)}function gr({kind:e,negate:t,alternatives:r},s,n){if(e===E.lookahead||e===E.lookbehind)return`(?${`${e===E.lookahead?"":"<"}${t?"!":"="}`}${r.map(n).join("|")})`;if(e===E.string_end)return"$";if(e===E.string_start)return"^";throw new Error(`Unexpected assertion kind "${e}"`)}function hr({ref:e},t){if(typeof e!="number")throw new Error("Unexpected named backref in transformed AST");if(!t.useFlagMods&&!t.allowBestEffort&&t.currentFlags.ignoreCase&&!t.captureFlagIMap.get(e))throw new Error("Use of case-insensitive backref to case-sensitive group requires option allowBestEffort or target ESNext");return"\\"+e}function dr({name:e,number:t,alternatives:r},s,n){return e&&(s.groupNames.has(e)?s.useDuplicateNames||(e=null):s.groupNames.add(e)),s.captureFlagIMap.set(t,s.currentFlags.ignoreCase),`(${e?`?<${e}>`:""}${r.map(n).join("|")})`}function Cr({value:e},t){let r=A(e),s=O(e,{isAfterBackref:t.lastNode.type===l.Backreference,inCharClass:t.inCharClass,useFlagV:t.useFlagV});if(s!==r)return s;if(t.useAppliedIgnoreCase&&t.currentFlags.ignoreCase&&fe(r)){let n=ne(r);return t.inCharClass?n.join(""):n.length>1?`[${n.join("")}]`:n[0]}return r}function mr({negate:e,parent:t,elements:r},s,n){if(!e&&(!s.useFlagV||s.optimize)&&t.type===l.CharacterClass&&r[0].type!==l.CharacterClassIntersection||s.optimize&&t.type===l.CharacterClassIntersection&&r.length===1&&r[0].type!==l.CharacterClassRange)return r.map(n).join("");if(!s.useFlagV&&t.type===l.CharacterClass)throw new Error("Use of nested character class requires target ES2024 or later");s.inCharClass=!0;let a=`[${e?"^":""}${r.map(n).join("")}]`;return s.inCharClass=!1,a}function Er(e,t){let r=e.min.value,s=e.max.value,n={isAfterBackref:!1,inCharClass:!0,useFlagV:t.useFlagV},a=O(r,n),o=O(s,n),i="";if(t.useAppliedIgnoreCase&&t.currentFlags.ignoreCase){let u=Je(e);br(u).forEach(p=>{i+=Array.isArray(p)?`${O(p[0],n)}-${O(p[1],n)}`:O(p,n)})}return`${a}-${o}${i}`}function wr({kind:e,negate:t,value:r,key:s},n){if(e===$.any)return n.currentFlags.dotAll?n.appliedGlobalFlags.dotAll||n.useFlagMods?".":"[^]":f`[^\n]`;if(e===$.digit)return t?f`\D`:f`\d`;if(e===$.property){if(!n.usePostEs2018Properties&&_e.has(r))throw new Error(`Unicode property "${r}" unavailable in target ES2018`);if(n.useAppliedIgnoreCase&&n.currentFlags.ignoreCase&&ie.has(r))throw new Error(`Unicode property "${r}" can't be case-insensitive when other chars have specific case`);return`${t?f`\P`:f`\p`}{${s?`${s}=`:""}${r}}`}if(e===$.word)return t?f`\W`:f`\w`;throw new Error(`Unexpected character set kind "${e}"`)}function Ar(e,t){return(t.appliedGlobalFlags.ignoreCase?"i":"")+(e.dotAll?"s":"")+(e.sticky?"y":"")}function Sr({atomic:e,flags:t,parent:r,alternatives:s},n,a){let o=n.currentFlags;t&&(n.currentFlags=Ze(o,t));let i=s.map(a).join("|"),u=n.optimize&&s.length===1&&r.type!==l.Quantifier&&!e&&(!n.useFlagMods||!t)?i:`(?${_r(e,t,n.useFlagMods)}${i})`;return n.currentFlags=o,u}function kr({ref:e},t){let r=t.maxRecursionDepth;if(!r)throw new Error("Use of recursion disabled");if(!t.allowBestEffort)throw new Error("Use of recursion requires option allowBestEffort");return e===0?`(?R=${r})`:f`\g<${e}&R=${r}>`}function Je(e,{firstOnly:t}={}){let r=e.min.value,s=e.max.value,n=[];if(r<65&&(s===65535||s>=131071)||r===65536&&s>=131071)return n;for(let a=r;a<=s;a++){let o=A(a);if(!fe(o))continue;let i=ne(o).filter(u=>{let c=u.codePointAt(0);return cs});if(i.length&&(n.push(...i),t))break}return n}function br(e){let t=e.map(n=>n.codePointAt(0)).sort((n,a)=>n-a),r=[],s=null;for(let n=0;n126&&e<160||t&&Nr(e))return f`\x${e.toString(16).padStart(2,"0")}`;let n=r?s?pr:lr:cr,a=A(e);return(n.has(a)?"\\":"")+a}function _r(e,t,r){if(e)return">";let s="";if(t&&r){let{enable:n,disable:a}=t;s=(n?.ignoreCase?"i":"")+(n?.dotAll?"s":"")+(a?"-":"")+(a?.ignoreCase?"i":"")+(a?.dotAll?"s":"")}return`${s}:`}function Ze(e,{enable:t,disable:r}){return{dotAll:!r?.dotAll&&!!(t?.dotAll||e.dotAll),ignoreCase:!r?.ignoreCase&&!!(t?.ignoreCase||e.ignoreCase)}}function $r({min:e,max:t,greedy:r,possessive:s}){let n;return!e&&t===1?n="?":!e&&t===1/0?n="*":e===1&&t===1/0?n="+":e===t?n=`{${e}}`:n=`{${e},${t===1/0?"":t}}`,n+(s?"+":r?"":"?")}function Nr(e){return e>47&&e<58}var Z=Object.freeze({DEFAULT:"DEFAULT",CHAR_CLASS:"CHAR_CLASS"});function Ir(e,t,r,s){let n=new RegExp(String.raw`${t}|(?<$skip>\[\^?|\\?.)`,"gsu"),a=[!1],o=0,i="";for(let u of e.matchAll(n)){let{0:c,groups:{$skip:p}}=u;if(!p&&(!s||s===Z.DEFAULT==!o)){r instanceof Function?i+=r(u,{context:o?Z.CHAR_CLASS:Z.DEFAULT,negated:a[a.length-1]}):i+=r;continue}c[0]==="["?(o++,a.push(c[1]==="^")):c==="]"&&o&&(o--,a.pop()),i+=c}return i}var Ye={DEFAULT:"DEFAULT",CHAR_CLASS:"CHAR_CLASS",ENCLOSED_P:"ENCLOSED_P",ENCLOSED_U:"ENCLOSED_U",GROUP_NAME:"GROUP_NAME",INTERVAL_QUANTIFIER:"INTERVAL_QUANTIFIER",INVALID_INCOMPLETE_TOKEN:"INVALID_INCOMPLETE_TOKEN"},he={DEFAULT:"DEFAULT",ENCLOSED_P:"ENCLOSED_P",ENCLOSED_Q:"ENCLOSED_Q",ENCLOSED_U:"ENCLOSED_U",INVALID_INCOMPLETE_TOKEN:"INVALID_INCOMPLETE_TOKEN",RANGE:"RANGE"},dn=new Set([Ye.ENCLOSED_P,Ye.ENCLOSED_U]),Cn=new Set([he.ENCLOSED_P,he.ENCLOSED_Q,he.ENCLOSED_U]),mn=(()=>{try{new RegExp("(?i:)")}catch{return!1}return!0})(),En=(()=>{try{new RegExp("","v")}catch{return!1}return!0})(),tt="&!#$%*+,.:;<=>?@^`~",yr="$E$",rt=String.raw`\(\?<(?![=!])(?[^>]+)>`,Fr=String.raw`\((?!\?)(?!(?<=\(\?\()DEFINE\))|${rt}`,Ce=String.raw`\(\?(?:[:=!>A-Za-z\-]|<[=!]|\(DEFINE\))`;var wn=new RegExp(String.raw` (?\(\?<(?![=!])|\\[gk]<) | (?\\[pPu]\{) diff --git a/src/parse.js b/src/parse.js index 22d1ee6..ee1afc6 100644 --- a/src/parse.js +++ b/src/parse.js @@ -345,11 +345,16 @@ function parseGroupOpen(context, state) { function parseQuantifier({token, parent}) { const {min, max, greedy, possessive} = token; - if (!parent.elements.length) { + const quantifiedNode = parent.elements.at(-1); + if ( // First child in `Alternative` - throw new Error('Nothing to repeat'); + !quantifiedNode || + // `\K` or `(?im-x)` + quantifiedNode.type === AstTypes.Directive + ) { + throw new Error(`Quantifier requires a repeatable token`); } - const node = createQuantifier(parent.elements.at(-1), min, max, greedy, possessive); + const node = createQuantifier(quantifiedNode, min, max, greedy, possessive); parent.elements.pop(); return node; } diff --git a/src/tokenize.js b/src/tokenize.js index 4da539d..216ca3f 100644 --- a/src/tokenize.js +++ b/src/tokenize.js @@ -513,6 +513,7 @@ function createTokenForFlagMod(raw, context) { if (raw.endsWith(')')) { // Replace flag x value until the end of the current group context.replaceCurrentModX(isXOn); + // Can't remove flag directives without flags like `(?-)`; they affect following quantifiers return createToken(TokenTypes.Directive, raw, { kind: TokenDirectiveKinds.flags, flags: flagChanges, diff --git a/src/transform.js b/src/transform.js index 04b0516..3f08a4e 100644 --- a/src/transform.js +++ b/src/transform.js @@ -175,8 +175,8 @@ const FirstPassVisitor = { Directive({node, parent, key, container, ast, remove, replaceWith, removeAllPrevSiblings, removeAllNextSiblings}, state) { const {kind, flags} = node; if (kind === AstDirectiveKinds.flags) { - // Flag directive with no flags; ex: `(?-)`, `(?--)` if (!flags.enable && !flags.disable) { + // Flag directive without flags; ex: `(?-)`, `(?--)` remove(); } else { const flagGroup = prepContainer(createGroup({flags}), removeAllNextSiblings());