Team Ai
Datasetpublic

Brunobkr/llama.cpp_AlgMor24_github

ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes3.1kdownloads
parser.js1824 linesDownload Raw Back to regjsparser
1// regjsparser2//3// ==================================================================4//5// See ECMA-262 Standard: 15.10.16//7// NOTE: The ECMA-262 standard uses the term "Assertion" for /^/. Here the8//   term "Anchor" is used.9//10// Pattern ::11//      Disjunction12//13// Disjunction ::14//      Alternative15//      Alternative | Disjunction16//17// Alternative ::18//      [empty]19//      Alternative Term20//21// Term ::22//      Anchor23//      Anchor Quantifier (see https://github.com/jviereck/regjsparser/issues/130)24//      Atom25//      Atom Quantifier26//27// Anchor ::28//      ^29//      $30//      \ b31//      \ B32//      ( ? = Disjunction )33//      ( ? ! Disjunction )34//      ( ? < = Disjunction )35//      ( ? < ! Disjunction )36//37// Quantifier ::38//      QuantifierPrefix39//      QuantifierPrefix ?40//41// QuantifierPrefix ::42//      *43//      +44//      ?45//      { DecimalDigits }46//      { DecimalDigits , }47//      { DecimalDigits , DecimalDigits }48//49// Atom ::50//      PatternCharacter51//      .52//      \ AtomEscape53//      CharacterClass54//      ( GroupSpecifier Disjunction )55//      ( ? : Disjunction )56//57// PatternCharacter ::58//      SourceCharacter but not any of: ^ $ \ . * + ? ( ) [ ] { } |59//60// AtomEscape ::61//      DecimalEscape62//      CharacterClassEscape63//      CharacterEscape64//      k GroupName65//66// CharacterEscape[U] ::67//      ControlEscape68//      c ControlLetter69//      HexEscapeSequence70//      RegExpUnicodeEscapeSequence[?U] (ES6)71//      IdentityEscape[?U]72//73// ControlEscape ::74//      one of f n r t v75// ControlLetter ::76//      one of77//          a b c d e f g h i j k l m n o p q r s t u v w x y z78//          A B C D E F G H I J K L M N O P Q R S T U V W X Y Z79//80// IdentityEscape ::81//      SourceCharacter but not c82//83// DecimalEscape ::84//      DecimalIntegerLiteral [lookahead ∉ DecimalDigit]85//86// CharacterClassEscape ::87//      one of d D s S w W88//89// CharacterClass ::90//      [ [lookahead ∉ {^}] ClassContents ]91//      [ ^ ClassContents ]92//93// ClassContents ::94//      [empty]95//      [~V] NonemptyClassRanges96//      [+V] ClassSetExpression97//98// NonemptyClassRanges ::99//      ClassAtom100//      ClassAtom NonemptyClassRangesNoDash101//      ClassAtom - ClassAtom ClassContents102//103// NonemptyClassRangesNoDash ::104//      ClassAtom105//      ClassAtomNoDash NonemptyClassRangesNoDash106//      ClassAtomNoDash - ClassAtom ClassContents107//108// ClassAtom ::109//      -110//      ClassAtomNoDash111//112// ClassAtomNoDash ::113//      SourceCharacter but not one of \ or ] or -114//      \ ClassEscape115//116// ClassEscape ::117//      DecimalEscape118//      b119//      CharacterEscape120//      CharacterClassEscape121//122// GroupSpecifier ::123//      [empty]124//      ? GroupName125//126// GroupName ::127//      < RegExpIdentifierName >128//129// RegExpIdentifierName ::130//      RegExpIdentifierStart131//      RegExpIdentifierName RegExpIdentifierContinue132//133// RegExpIdentifierStart ::134//      UnicodeIDStart135//      $136//      _137//      \ RegExpUnicodeEscapeSequence138//139// RegExpIdentifierContinue ::140//      UnicodeIDContinue141//      $142//      _143//      \ RegExpUnicodeEscapeSequence144//      <ZWNJ>145//      <ZWJ>146//147// --------------------------------------------------------------148// NOTE: The following productions refer to the "set notation and149//       properties of strings" proposal.150//       https://github.com/tc39/proposal-regexp-set-notation151// --------------------------------------------------------------152//153// ClassSetExpression ::154//      ClassUnion155//      ClassIntersection156//      ClassSubtraction157//158// ClassUnion ::159//      ClassSetRange ClassUnion?160//      ClassSetOperand ClassUnion?161//162// ClassIntersection ::163//      ClassSetOperand && [lookahead ≠ &] ClassSetOperand164//      ClassIntersection && [lookahead ≠ &] ClassSetOperand165//166// ClassSubtraction ::167//      ClassSetOperand -- ClassSetOperand168//      ClassSubtraction -- ClassSetOperand169//170// ClassSetRange ::171//      ClassSetCharacter - ClassSetCharacter172//173// ClassSetOperand ::174//      ClassSetCharacter175//      ClassStringDisjunction176//      NestedClass177//178// NestedClass ::179//      [ [lookahead ≠ ^] ClassContents[+U,+V] ]180//      [ ^ ClassContents[+U,+V] ]181//      \ CharacterClassEscape[+U, +V]182//183// ClassStringDisjunction ::184//      \q{ ClassStringDisjunctionContents }185//186// ClassStringDisjunctionContents ::187//      ClassString188//      ClassString | ClassStringDisjunctionContents189//190// ClassString ::191//      [empty]192//      NonEmptyClassString193//194// NonEmptyClassString ::195//      ClassSetCharacter NonEmptyClassString?196//197// ClassSetCharacter ::198//      [lookahead ∉ ClassSetReservedDoublePunctuator] SourceCharacter but not ClassSetSyntaxCharacter199//      \ CharacterEscape[+U]200//      \ ClassSetReservedPunctuator201//      \b202//203// ClassSetReservedDoublePunctuator ::204//      one of && !! ## $$ %% ** ++ ,, .. :: ;; << == >> ?? @@ ^^ `` ~~205//206// ClassSetSyntaxCharacter ::207//      one of ( ) [ ] { } / - \ |208//209// ClassSetReservedPunctuator ::210//      one of & - ! # % , : ; < = > @ ` ~211//212// --------------------------------------------------------------213// NOTE: The following productions refer to the214//       "Regular Expression Pattern Modifiers for ECMAScript" proposal.215//       https://github.com/tc39/proposal-regexp-modifiers216// --------------------------------------------------------------217//218// Atom ::219//      ( ? RegularExpressionModifiers : Disjunction )220//      ( ? RegularExpressionModifiers - RegularExpressionModifiers : Disjunction )221//222// RegularExpressionModifiers:223//      [empty]224//      RegularExpressionModifiers RegularExpressionModifier225//226// RegularExpressionModifier:227//      one of i m s228 229"use strict";230(function() {231 232  var fromCodePoint = String.fromCodePoint || (function() {233    // Implementation taken from234    // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint235 236    var stringFromCharCode = String.fromCharCode;237    var floor = Math.floor;238 239    return function fromCodePoint() {240      var MAX_SIZE = 0x4000;241      var codeUnits = [];242      var highSurrogate;243      var lowSurrogate;244      var index = -1;245      var length = arguments.length;246      if (!length) {247        return '';248      }249      var result = '';250      while (++index < length) {251        var codePoint = Number(arguments[index]);252        if (253          !isFinite(codePoint) ||       // `NaN`, `+Infinity`, or `-Infinity`254          codePoint < 0 ||              // not a valid Unicode code point255          codePoint > 0x10FFFF ||       // not a valid Unicode code point256          floor(codePoint) != codePoint // not an integer257        ) {258          throw RangeError('Invalid code point: ' + codePoint);259        }260        if (codePoint <= 0xFFFF) { // BMP code point261          codeUnits.push(codePoint);262        } else { // Astral code point; split in surrogate halves263          // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae264          codePoint -= 0x10000;265          highSurrogate = (codePoint >> 10) + 0xD800;266          lowSurrogate = (codePoint % 0x400) + 0xDC00;267          codeUnits.push(highSurrogate, lowSurrogate);268        }269        if (index + 1 == length || codeUnits.length > MAX_SIZE) {270          result += stringFromCharCode.apply(null, codeUnits);271          codeUnits.length = 0;272        }273      }274      return result;275    };276  }());277 278  function parse(str, flags, features) {279    if (!features) {280      features = {};281    }282 283    function updateRawStart(node, start) {284      node.range[0] = start;285      node.raw = str.substring(start, node.range[1]);286      return node;287    }288 289    function createAnchor(kind, rawLength) {290      return {291        type: 'anchor',292        kind: kind,293        range: [294          pos - rawLength,295          pos296        ],297        raw: str.substring(pos - rawLength, pos)298      };299    }300 301    function createValue(kind, codePoint, from, to) {302      return {303        type: 'value',304        kind: kind,305        codePoint: codePoint,306        range: [from, to],307        raw: str.substring(from, to)308      };309    }310 311    function createEscaped(kind, codePoint, value, fromOffset) {312      fromOffset = fromOffset || 0;313      return createValue(kind, codePoint, pos - (value.length + fromOffset), pos);314    }315 316    function createCharacter(matches) {317      var _char = matches[0];318      var first = _char.charCodeAt(0);319      if (isUnicodeMode) {320        var second;321        if (_char.length === 1 && first >= 0xD800 && first <= 0xDBFF) {322          second = lookahead().charCodeAt(0);323          if (second >= 0xDC00 && second <= 0xDFFF) {324            // Unicode surrogate pair325            pos++;326            return createValue(327              'symbol',328              (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000,329              pos - 2, pos);330          }331        }332      }333      return createValue('symbol', first, pos - 1, pos);334    }335 336    function createDisjunction(alternatives, from, to) {337      return {338        type: 'disjunction',339        body: alternatives,340        range: [341          from,342          to343        ],344        raw: str.substring(from, to)345      };346    }347 348    function createDot() {349      return {350        type: 'dot',351        range: [352          pos - 1,353          pos354        ],355        raw: '.'356      };357    }358 359    function createCharacterClassEscape(value) {360      return {361        type: 'characterClassEscape',362        value: value,363        range: [364          pos - 2,365          pos366        ],367        raw: str.substring(pos - 2, pos)368      };369    }370 371    function createReference(matchIndex) {372      var start = pos - 1 - matchIndex.length;373      return {374        type: 'reference',375        matchIndex: parseInt(matchIndex, 10),376        range: [377          start,378          pos379        ],380        raw: str.substring(start, pos)381      };382    }383 384    function createNamedReference(name) {385      var start = name.range[0] - 3;386      return {387        type: 'reference',388        name: name,389        range: [390          start,391          pos392        ],393        raw: str.substring(start, pos)394      };395    }396 397    function createGroup(behavior, disjunction, from, to) {398      return {399        type: 'group',400        behavior: behavior,401        body: disjunction,402        range: [403          from,404          to405        ],406        raw: str.substring(from, to)407      };408    }409 410    function createQuantifier(min, max, from, to, symbol) {411      if (to == null) {412        from = pos - 1;413        to = pos;414      }415 416      return {417        type: 'quantifier',418        min: min,419        max: max,420        greedy: true,421        body: null, // set later on422        symbol: symbol,423        range: [424          from,425          to426        ],427        raw: str.substring(from, to)428      };429    }430 431    function createAlternative(terms, from, to) {432      return {433        type: 'alternative',434        body: terms,435        range: [436          from,437          to438        ],439        raw: str.substring(from, to)440      };441    }442 443    function createCharacterClass(contents, negative, from, to) {444      return {445        type: 'characterClass',446        kind: contents.kind,447        body: contents.body,448        negative: negative,449        range: [450          from,451          to452        ],453        raw: str.substring(from, to)454      };455    }456 457    function createClassRange(min, max, from, to) {458      // See 15.10.2.15:459      if (min.codePoint > max.codePoint) {460        bail('invalid range in character class', min.raw + '-' + max.raw, from, to);461      }462 463      return {464        type: 'characterClassRange',465        min: min,466        max: max,467        range: [468          from,469          to470        ],471        raw: str.substring(from, to)472      };473    }474 475    function createClassStrings(strings, from, to) {476      return {477        type: 'classStrings',478        strings: strings,479        range: [from, to],480        raw: str.substring(from, to)481      };482    }483 484    function createClassString(characters, from, to) {485      return {486        type: 'classString',487        characters: characters,488        range: [from, to],489        raw: str.substring(from, to)490      };491    }492 493    function flattenBody(body) {494      if (body.type === 'alternative') {495        return body.body;496      } else {497        return [body];498      }499    }500 501    function incr(amount) {502      amount = (amount || 1);503      pos += amount;504    }505 506    function consume(amount) {507      var res = str.substring(pos, pos += amount);508      return res;509    }510 511    function skip(value) {512      if (!match(value)) {513        bail('character', value);514      }515    }516 517    function match(value) {518      var len = value.length;519      if (str.substring(pos, pos + len) === value) {520        incr(len);521        return value;522      }523    }524 525    function matchOne(value) {526      if (str[pos] === value) {527        pos++;528        return value;529      }530    }531 532    function lookahead() {533      return str[pos];534    }535 536    function currentOne(value) {537      return str[pos] === value;538    }539 540    function current(value) {541      var len = value.length;542      return str.substring(pos, pos + len) === value;543    }544 545    function next(value) {546      return str[pos + 1] === value;547    }548 549    function matchReg(regExp) {550      var subStr = str.substring(pos);551      var res = subStr.match(regExp);552      if (res) {553        pos += res[0].length;554      }555      return res;556    }557 558    function parseDisjunction() {559      // Disjunction ::560      //      Alternative561      //      Alternative | Disjunction562      var res = [], from = pos;563      res.push(parseAlternative());564 565      while (matchOne('|')) {566        res.push(parseAlternative());567      }568 569      if (res.length === 1) {570        return res[0];571      }572 573      return createDisjunction(res, from, pos);574    }575 576    function parseAlternative() {577      var res = [], from = pos;578      var term;579 580      // Alternative ::581      //      [empty]582      //      Alternative Term583      while (term = parseTerm()) {584        res.push(term);585      }586 587      if (res.length === 1) {588        return res[0];589      }590 591      return createAlternative(res, from, pos);592    }593 594    function parseTerm() {595      // Term ::596      //      Anchor597      //      Atom598      //      Atom Quantifier599 600      // Term (Annex B)::601      //      [~UnicodeMode] QuantifiableAssertion Quantifier (see https://github.com/jviereck/regjsparser/issues/130)602      //      [~UnicodeMode] ExtendedAtom Quantifier603 604      // QuantifiableAssertion::605      //      (?= Disjunction[~UnicodeMode, ~UnicodeSetsMode, ?NamedCaptureGroups] )606      //      (?! Disjunction[~UnicodeMode, ~UnicodeSetsMode, ?NamedCaptureGroups] )607 608      if (pos >= str.length || currentOne('|') || currentOne(')')) {609        return null; /* Means: The term is empty */610      }611 612      var anchor = parseAnchor();613      var quantifier;614      if (anchor) {615        var pos_backup = pos;616        quantifier = parseQuantifier() || false;617        if (quantifier) {618          // Annex B619          if (!isUnicodeMode && anchor.type === "group") {620            quantifier.body = flattenBody(anchor);621            // The quantifier contains the anchor. Therefore, the beginning of the622            // quantifier range is given by the beginning of the anchor.623            updateRawStart(quantifier, anchor.range[0]);624            return quantifier;625          }626          pos = pos_backup;627          bail("Expected atom");628        }629        return anchor;630      }631 632      // If there is no Anchor, try to parse an atom.633      var atom = parseAtomAndExtendedAtom();634      if (!atom) {635        // Check if a quantifier is following. A quantifier without an atom636        // is an error.637        pos_backup = pos;638        quantifier = parseQuantifier() || false;639        if (quantifier) {640          pos = pos_backup;641          bail("Expected atom");642        }643 644        // If no unicode flag, then try to parse ExtendedAtom -> ExtendedPatternCharacter.645        //      ExtendedPatternCharacter646        if (!isUnicodeMode && matchOne("{")) {647          atom = createCharacter("{");648        } else {649          bail("Expected atom");650        }651      }652 653      quantifier = parseQuantifier() || false;654      if (quantifier) {655        var type = atom.type, behavior = atom.behavior;656        if (657          type === "group" &&658          (behavior === "negativeLookbehind" ||659            behavior === "lookbehind")660        ) {661          bail(662            "Invalid quantifier",663            "",664            quantifier.range[0],665            quantifier.range[1]666          );667        }668        quantifier.body = flattenBody(atom);669        // The quantifier contains the atom. Therefore, the beginning of the670        // quantifier range is given by the beginning of the atom.671        updateRawStart(quantifier, atom.range[0]);672        return quantifier;673      }674      return atom;675    }676 677    function parseGroup(matchA, typeA, matchB, typeB) {678      var type, from = pos;679 680      if (match(matchA)) {681        type = typeA;682      } else if (match(matchB)) {683        type = typeB;684      } else {685        return false;686      }687 688      return finishGroup(type, from);689    }690 691    function finishGroup(type, from) {692      var body = parseDisjunction();693      if (!body) {694        bail('Expected disjunction');695      }696      skip(')');697      var group = createGroup(type, flattenBody(body), from, pos);698 699      if (type == 'normal') {700        // Keep track of the number of closed groups. This is required for701        // parseDecimalEscape(). In case the string is parsed a second time the702        // value already holds the total count and no incrementation is required.703        if (firstIteration) {704          closedCaptureCounter++;705        }706      }707      return group;708    }709 710    function parseAnchor() {711      // Anchor ::712      //      ^713      //      $714      //      \ b715      //      \ B716      //      ( ? = Disjunction )717      //      ( ? ! Disjunction )718 719      switch(lookahead()) {720        case '^':721          incr();722          return createAnchor('start', 1 /* rawLength */);723        case '$':724          incr();725          return createAnchor('end', 1 /* rawLength */);726        case '\\': {727          if (next('b')) {728            incr(2);729            return createAnchor('boundary', 2 /* rawLength */);730          } else if (next('B')) {731            incr(2);732            return createAnchor('not-boundary', 2 /* rawLength */);733          }734          break;735        }736        case '(':737          return parseGroup('(?=', 'lookahead', '(?!', 'negativeLookahead');738        default:739          return;740      }741    }742 743    function parseQuantifier() {744      // Quantifier ::745      //      QuantifierPrefix746      //      QuantifierPrefix ?747      //748      // QuantifierPrefix ::749      //      *750      //      +751      //      ?752      //      { DecimalDigits }753      //      { DecimalDigits , }754      //      { DecimalDigits , DecimalDigits }755 756      var res, from = pos;757      var quantifier;758      var min, max;759 760      switch(lookahead()) {761        case '*':762          incr();763          quantifier = createQuantifier(0, undefined, undefined, undefined, '*');764          break;765        case '+':766          incr();767          quantifier = createQuantifier(1, undefined, undefined, undefined, "+");768          break;769        case '?':770          incr();771          quantifier = createQuantifier(0, 1, undefined, undefined, "?");772          break;773        case '{': {774          if (res = matchReg(/^\{(\d+)\}/)) {775            min = parseInt(res[1], 10);776            quantifier = createQuantifier(min, min, from, pos);777          }778          else if (res = matchReg(/^\{(\d+),\}/)) {779            min = parseInt(res[1], 10);780            quantifier = createQuantifier(min, undefined, from, pos);781          }782          else if (res = matchReg(/^\{(\d+),(\d+)\}/)) {783            min = parseInt(res[1], 10);784            max = parseInt(res[2], 10);785            if (min > max) {786              bail('numbers out of order in {} quantifier', '', from, pos);787            }788            quantifier = createQuantifier(min, max, from, pos);789          }790 791          if (min && (!Number.isSafeInteger(min)) || (max && !Number.isSafeInteger(max))) {792            bail("iterations outside JS safe integer range in quantifier", "", from, pos);793          }794        }795      }796 797      if (quantifier) {798        if (matchOne('?')) {799          quantifier.greedy = false;800          quantifier.range[1] += 1;801        }802      }803 804      return quantifier;805    }806 807    function parseAtomAndExtendedAtom() {808      // Parsing Atom and ExtendedAtom together due to redundancy.809      // ExtendedAtom is defined in Appendix B of the ECMA-262 standard.810      //811      // SEE: https://www.ecma-international.org/ecma-262/10.0/index.html#prod-annexB-ExtendedPatternCharacter812      //813      // Atom ::814      //      PatternCharacter815      //      .816      //      \ AtomEscape817      //      CharacterClass818      //      ( GroupSpecifier Disjunction )819      //      ( ? RegularExpressionModifiers : Disjunction )820      //      ( ? RegularExpressionModifiers - RegularExpressionModifiers : Disjunction )821      // ExtendedAtom ::822      //      ExtendedPatternCharacter823      // ExtendedPatternCharacter ::824      //      SourceCharacter but not one of ^$\.*+?()[|825 826      var res;827 828      switch (res = lookahead()) {829        case '.':830          //      .831          incr();832          return createDot();833        case '\\': {834          //      \ AtomEscape835          incr();836          res = parseAtomEscape();837          if (!res) {838            if (!isUnicodeMode && lookahead() == 'c') {839              // B.1.4 ExtendedAtom840              // \[lookahead = c]841              return createValue('symbol', 92, pos - 1, pos);842            }843            bail('atomEscape');844          }845          return res;846        }847        case '[':848          return parseCharacterClass();849        case '(': {850          if (features.lookbehind && (res = parseGroup('(?<=', 'lookbehind', '(?<!', 'negativeLookbehind'))) {851            return res;852          }853          else if (features.namedGroups && match("(?<")) {854            var name = parseIdentifier();855            skip(">");856            var group = finishGroup("normal", name.range[0] - 3);857            group.name = name;858            return group;859          }860          else if (features.modifiers && current("(?") && str[pos + 2] != ":") {861            return parseModifiersGroup();862          }863          else {864            //      ( Disjunction )865            //      ( ? : Disjunction )866            return parseGroup('(?:', 'ignore', '(', 'normal');867          }868        }869        case ']':870        case '}':871          //      ExtendedPatternCharacter, first part. See parseTerm.872          if (!isUnicodeMode) {873            incr();874            return createCharacter(res);875          }876          break;877        case '^':878        case '$':879        case '*':880        case '+':881        case '?':882        case '{':883        case ')':884        case '|':885          break;886        default:887          //      PatternCharacter888          incr();889          return createCharacter(res);890      }891    }892 893    function parseModifiersGroup() {894      function hasDupChar(str) {895        var i = 0;896        while (i < str.length) {897          if (str.indexOf(str[i], i + 1) != -1) {898            return true;899          }900          i++;901        }902        return false;903      }904 905      var from = pos;906      incr(2);907 908      var enablingFlags = matchReg(/^[sim]+/);909      var disablingFlags;910      if(matchOne("-") && lookahead() !== ":"){911        disablingFlags = matchReg(/^[sim]+/);912        if (!disablingFlags) {913          bail('Invalid flags for modifiers group');914        }915      } else if(!enablingFlags){916        bail('Invalid flags for modifiers group');917      }918 919      enablingFlags = enablingFlags ? enablingFlags[0] : "";920      disablingFlags = disablingFlags ? disablingFlags[0] : "";921 922      var flags = enablingFlags + disablingFlags;923      if(flags.length > 3 || hasDupChar(flags)) {924        bail('flags cannot be duplicated for modifiers group');925      }926 927      if(!matchOne(":")) {928        bail('Invalid flags for modifiers group');929      }930 931      var modifiersGroup = finishGroup("ignore", from);932 933      modifiersGroup.modifierFlags = {934        enabling: enablingFlags,935        disabling: disablingFlags936      };937 938      return modifiersGroup;939    }940 941    function parseUnicodeSurrogatePairEscape(firstEscape, isUnicodeMode) {942      if (isUnicodeMode) {943        var first, second;944        if (firstEscape.kind == 'unicodeEscape' &&945          (first = firstEscape.codePoint) >= 0xD800 && first <= 0xDBFF &&946          currentOne('\\') && next('u') ) {947          var prevPos = pos;948          pos++;949          var secondEscape = parseClassEscape();950          if (secondEscape.kind == 'unicodeEscape' &&951            (second = secondEscape.codePoint) >= 0xDC00 && second <= 0xDFFF) {952            // Unicode surrogate pair953            firstEscape.kind = 'unicodeCodePointEscape';954            firstEscape.codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;955            firstEscape.range[1] = pos;956            firstEscape.raw = str.substring(firstEscape.range[0], pos)957          }958          else {959            pos = prevPos;960          }961        }962      }963      return firstEscape;964    }965 966    function parseClassEscape() {967      return parseAtomEscape(true);968    }969 970    function parseAtomEscape(insideCharacterClass) {971      // AtomEscape ::972      //      DecimalEscape973      //      CharacterEscape974      //      CharacterClassEscape975      //      k GroupName976 977      var res, from = pos, ch;978 979      switch (ch = lookahead()) {980        case '0':981        case '1':982        case '2':983        case '3':984        case '4':985        case '5':986        case '6':987        case '7':988        case '8':989        case '9':990          return parseDecimalEscape(insideCharacterClass);991        case 'B': {992          if (insideCharacterClass) {993            bail('\\B not possible inside of CharacterClass', '', from);994            break;995          } else {996            return parseIdentityEscape();997          }998        }999        case 'b': {1000          if (insideCharacterClass) {1001            // 15.10.2.191002            // The production ClassEscape :: b evaluates by returning the1003            // CharSet containing the one character <BS> (Unicode value 0008).1004            incr();1005            return createEscaped('singleEscape', 0x0008, '\\b');1006          } else {1007            return parseIdentityEscape();1008          }1009        }1010        case 'c': {1011          if (insideCharacterClass) {1012            if (!isUnicodeMode && (res = matchReg(/^c(\d)/))) {1013              // B.1.41014              // c ClassControlLetter, ClassControlLetter = DecimalDigit1015              return createEscaped('controlLetter', res[1] + 16, res[1], 2);1016            } else if (!isUnicodeMode && match("c_")) {1017              // B.1.41018              // c ClassControlLetter, ClassControlLetter = _1019              return createEscaped('controlLetter', 31, '_', 2);1020            }1021          }1022          return parseCharacterEscape();1023        }1024        // CharacterClassEscape :: one of d D s S w W1025        case 'd':1026        case 'D':1027        case 'w':1028        case 'W':1029        case 's':1030        case 'S':1031          incr();1032          return createCharacterClassEscape(ch);1033        case 'k':1034          return parseNamedReference() || parseIdentityEscape();1035        case 'p':1036        case 'P':1037          return parseUnicodePropertyEscape() || parseIdentityEscape();1038        case '-': {1039          //     [+U] -1040          if (insideCharacterClass && isUnicodeMode) {1041            incr();1042            return createEscaped('singleEscape', 0x002d, '\\-');1043          }1044          return parseIdentityEscape();1045        }1046        default:1047          return parseCharacterEscape();1048      }1049    }1050 1051 1052    function parseDecimalEscape(insideCharacterClass) {1053      // DecimalEscape ::1054      //      DecimalIntegerLiteral [lookahead ∉ DecimalDigit]1055 1056      var res, match, from = pos;1057 1058      if (res = matchReg(/^(?!0)\d+/)) {1059        match = res[0];1060        var refIdx = parseInt(match, 10);1061        if (refIdx <= closedCaptureCounter && !insideCharacterClass) {1062          // If the number is smaller than the normal-groups found so1063          // far, then it is a reference...1064          return createReference(match);1065        } else {1066          // ... otherwise it needs to be interpreted as a octal (if the1067          // number is in an octal format). If it is NOT octal format,1068          // then the slash is ignored and the number is matched later1069          // as normal characters.1070 1071          // Recall the negative decision to decide if the input must be parsed1072          // a second time with the total normal-groups.1073          backrefDenied.push(refIdx);1074 1075          // \1 octal escapes are disallowed in unicode mode, but they might1076          // be references to groups which haven't been parsed yet.1077          // We must parse a second time to determine if \1 is a reference1078          // or an octal scape, and then we can report the error.1079          if (firstIteration) {1080            shouldReparse = true;1081          } else {1082            bailOctalEscapeIfUnicode(from, pos);1083          }1084 1085          // Reset the position again, as maybe only parts of the previous1086          // matched numbers are actual octal numbers. E.g. in '019' only1087          // the '01' should be matched.1088          incr(-match.length);1089          if (res = matchReg(/^[0-7]{1,3}/)) {1090            return createEscaped('octal', parseInt(res[0], 8), res[0], 1);1091          } else {1092            // If we end up here, we have a case like /\91/. Then the1093            // first slash is to be ignored and the 9 & 1 to be treated1094            // like ordinary characters. Create a character for the1095            // first number only here - other number-characters1096            // (if available) will be matched later.1097            var start = pos;1098            res = createCharacter(matchReg(/^[89]/));1099            return updateRawStart(res, start - 1);1100          }1101        }1102      }1103      // Only allow octal numbers in the following. All matched numbers start1104      // with a zero (if the do not, the previous if-branch is executed).1105      // If the number is not octal format and starts with zero (e.g. `091`)1106      // then only the zeros `0` is treated here and the `91` are ordinary1107      // characters.1108      // Example:1109      //   /\091/.exec('\091')[0].length === 31110      else if (res = matchReg(/^[0-7]{1,3}/)) {1111        match = res[0];1112        if (match !== '0') {1113          bailOctalEscapeIfUnicode(from, pos);1114        }1115        if (/^0{1,3}$/.test(match)) {1116          // If they are all zeros, then only take the first one.1117          return createEscaped('null', 0x0000, '0', match.length);1118        } else {1119          return createEscaped('octal', parseInt(match, 8), match, 1);1120        }1121      }1122      return false;1123    }1124 1125    function bailOctalEscapeIfUnicode(from, pos) {1126      if (isUnicodeMode) {1127        bail("Invalid decimal escape in unicode mode", null, from, pos);1128      }1129    }1130 1131    function parseUnicodePropertyEscape() {1132      var res, from = pos;1133      if (features.unicodePropertyEscape && isUnicodeMode && (res = matchReg(/^([pP])\{([^}]+)\}/))) {1134        // https://github.com/jviereck/regjsparser/issues/771135        return {1136          type: 'unicodePropertyEscape',1137          negative: res[1] === 'P',1138          value: res[2],1139          range: [from - 1, pos],1140          raw: str.substring(from - 1, pos)1141        };1142      }1143      return false;1144    }1145 1146    function parseNamedReference() {1147      if (features.namedGroups && matchReg(/^k<(?=.*?>)/)) {1148        var name = parseIdentifier();1149        skip('>');1150        return createNamedReference(name);1151      }1152    }1153 1154    function parseRegExpUnicodeEscapeSequence(isUnicodeMode) {1155      var res;1156      if (res = matchReg(/^u([0-9a-fA-F]{4})/)) {1157        // UnicodeEscapeSequence1158        return parseUnicodeSurrogatePairEscape(1159          createEscaped('unicodeEscape', parseInt(res[1], 16), res[1], 2),1160          isUnicodeMode1161        );1162      } else if (isUnicodeMode && (res = matchReg(/^u\{([0-9a-fA-F]+)\}/))) {1163        // RegExpUnicodeEscapeSequence (ES6 Unicode code point escape)1164        return createEscaped('unicodeCodePointEscape', parseInt(res[1], 16), res[1], 4);1165      }1166    }1167 1168    function parseCharacterEscape() {1169      // CharacterEscape ::1170      //      ControlEscape1171      //      c ControlLetter1172      //      HexEscapeSequence1173      //      UnicodeEscapeSequence[?UnicodeMode]1174      //      IdentityEscape[?UnicodeMode]1175 1176      var res;1177      var from = pos;1178      switch (lookahead()) {1179        case 't':1180          incr();1181          return createEscaped('singleEscape', 0x009, '\\t');1182        case 'n':1183          incr();1184          return createEscaped('singleEscape', 0x00A, '\\n');1185        case 'v':1186          incr();1187          return createEscaped('singleEscape', 0x00B, '\\v');1188        case 'f':1189          incr();1190          return createEscaped('singleEscape', 0x00C, '\\f');1191        case 'r':1192          incr();1193          return createEscaped('singleEscape', 0x00D, '\\r');1194        case 'c':1195          if (res = matchReg(/^c([a-zA-Z])/)) {1196            // c ControlLetter1197            return createEscaped('controlLetter', res[1].charCodeAt(0) % 32, res[1], 2);1198          }1199          break;1200        case 'x':

Showing the first 1,200 of 1824 lines. Download the file for the rest.

Brunobkr/llama.cpp_AlgMor24_github · Team Ai