0759c4c10d2fa3df33f07c549f2e5f542a7b85f322f77b898f7fe193289bd463.json 20 KB

1
  1. {"ast":null,"code":"/**\n * Extracts the characters between two markers (for eg, between \"(\" and \")\"). The function handles nested markers as well as markers inside strings (delimited by \", ' or `) and comments\n * @param markerOpen opening marker\n * @param markerClose closing marker\n * @param block code block to parse\n * @param startIndex starting index in block where the extraction must start. The character at block[startIndex] should be the markerOpen character!\n * @returns index of the last character for the extraction (or -1 if the string is invalid - no matching closing marker found). The string to extract (without the markers) is the string between startIndex + 1 and the returned value (exclusive)\n */\nexport function ExtractBetweenMarkers(markerOpen, markerClose, block, startIndex) {\n let currPos = startIndex,\n openMarkers = 0,\n waitForChar = \"\";\n while (currPos < block.length) {\n const currChar = block.charAt(currPos);\n if (!waitForChar) {\n switch (currChar) {\n case markerOpen:\n openMarkers++;\n break;\n case markerClose:\n openMarkers--;\n break;\n case '\"':\n case \"'\":\n case \"`\":\n waitForChar = currChar;\n break;\n case \"/\":\n if (currPos + 1 < block.length) {\n const nextChar = block.charAt(currPos + 1);\n if (nextChar === \"/\") {\n waitForChar = \"\\n\";\n } else if (nextChar === \"*\") {\n waitForChar = \"*/\";\n }\n }\n break;\n }\n } else {\n if (currChar === waitForChar) {\n if (waitForChar === '\"' || waitForChar === \"'\") {\n block.charAt(currPos - 1) !== \"\\\\\" && (waitForChar = \"\");\n } else {\n waitForChar = \"\";\n }\n } else if (waitForChar === \"*/\" && currChar === \"*\" && currPos + 1 < block.length) {\n block.charAt(currPos + 1) === \"/\" && (waitForChar = \"\");\n if (waitForChar === \"\") {\n currPos++;\n }\n }\n }\n currPos++;\n if (openMarkers === 0) {\n break;\n }\n }\n return openMarkers === 0 ? currPos - 1 : -1;\n}\n/**\n * Parses a string and skip whitespaces\n * @param s string to parse\n * @param index index where to start parsing\n * @returns the index after all whitespaces have been skipped\n */\nexport function SkipWhitespaces(s, index) {\n while (index < s.length) {\n const c = s[index];\n if (c !== \" \" && c !== \"\\n\" && c !== \"\\r\" && c !== \"\\t\" && c !== \"\\u000a\" && c !== \"\\u00a0\") {\n break;\n }\n index++;\n }\n return index;\n}\n/**\n * Checks if a character is an identifier character (meaning, if it is 0-9, A-Z, a-z or _)\n * @param c character to check\n * @returns true if the character is an identifier character\n */\nexport function IsIdentifierChar(c) {\n const v = c.charCodeAt(0);\n return v >= 48 && v <= 57 ||\n // 0-9\n v >= 65 && v <= 90 ||\n // A-Z\n v >= 97 && v <= 122 ||\n // a-z\n v == 95; // _\n}\n/**\n * Removes the comments of a code block\n * @param block code block to parse\n * @returns block with the comments removed\n */\nexport function RemoveComments(block) {\n let currPos = 0,\n waitForChar = \"\",\n inComments = false;\n const s = [];\n while (currPos < block.length) {\n const currChar = block.charAt(currPos);\n if (!waitForChar) {\n switch (currChar) {\n case '\"':\n case \"'\":\n case \"`\":\n waitForChar = currChar;\n break;\n case \"/\":\n if (currPos + 1 < block.length) {\n const nextChar = block.charAt(currPos + 1);\n if (nextChar === \"/\") {\n waitForChar = \"\\n\";\n inComments = true;\n } else if (nextChar === \"*\") {\n waitForChar = \"*/\";\n inComments = true;\n }\n }\n break;\n }\n if (!inComments) {\n s.push(currChar);\n }\n } else {\n if (currChar === waitForChar) {\n if (waitForChar === '\"' || waitForChar === \"'\") {\n block.charAt(currPos - 1) !== \"\\\\\" && (waitForChar = \"\");\n s.push(currChar);\n } else {\n waitForChar = \"\";\n inComments = false;\n }\n } else if (waitForChar === \"*/\" && currChar === \"*\" && currPos + 1 < block.length) {\n block.charAt(currPos + 1) === \"/\" && (waitForChar = \"\");\n if (waitForChar === \"\") {\n inComments = false;\n currPos++;\n }\n } else {\n if (!inComments) {\n s.push(currChar);\n }\n }\n }\n currPos++;\n }\n return s.join(\"\");\n}\n/**\n * Finds the first occurrence of a character in a string going backward\n * @param s the string to parse\n * @param index starting index in the string\n * @param c the character to find\n * @param c2 an optional second character to find\n * @returns the index of the character if found, else -1\n */\nexport function FindBackward(s, index, c, c2) {\n while (index >= 0 && s.charAt(index) !== c && (!c2 || s.charAt(index) !== c2)) {\n index--;\n }\n return index;\n}\n/**\n * Escapes a string so that it is usable as a regular expression\n * @param s string to escape\n * @returns escaped string\n */\nexport function EscapeRegExp(s) {\n return s.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n/**\n * Injects code at the beginning and/or end of a function.\n * The function is identified by \"mainFuncDecl\". The starting code is injected just after the first \"\\{\" found after the mainFuncDecl.\n * The ending code is injected just before the last \"\\}\" of the whole block of code (so, it is assumed that the function is the last of the block of code).\n * @param code code to inject into\n * @param mainFuncDecl Function declaration to find in the code (for eg: \"void main\")\n * @param startingCode The code to inject at the beginning of the function\n * @param endingCode The code to inject at the end of the function\n * @returns The code with the injected code\n */\nexport function InjectStartingAndEndingCode(code, mainFuncDecl, startingCode, endingCode) {\n let idx = code.indexOf(mainFuncDecl);\n if (idx < 0) {\n return code;\n }\n if (startingCode) {\n // eslint-disable-next-line no-empty\n while (idx++ < code.length && code.charAt(idx) != \"{\") {}\n if (idx < code.length) {\n const part1 = code.substring(0, idx + 1);\n const part2 = code.substring(idx + 1);\n code = part1 + startingCode + part2;\n }\n }\n if (endingCode) {\n const lastClosingCurly = code.lastIndexOf(\"}\");\n code = code.substring(0, lastClosingCurly);\n code += endingCode + \"\\n}\";\n }\n return code;\n}","map":{"version":3,"names":["ExtractBetweenMarkers","markerOpen","markerClose","block","startIndex","currPos","openMarkers","waitForChar","length","currChar","charAt","nextChar","SkipWhitespaces","s","index","c","IsIdentifierChar","v","charCodeAt","RemoveComments","inComments","push","join","FindBackward","c2","EscapeRegExp","replace","InjectStartingAndEndingCode","code","mainFuncDecl","startingCode","endingCode","idx","indexOf","part1","substring","part2","lastClosingCurly","lastIndexOf"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/Misc/codeStringParsingTools.js"],"sourcesContent":["/**\n * Extracts the characters between two markers (for eg, between \"(\" and \")\"). The function handles nested markers as well as markers inside strings (delimited by \", ' or `) and comments\n * @param markerOpen opening marker\n * @param markerClose closing marker\n * @param block code block to parse\n * @param startIndex starting index in block where the extraction must start. The character at block[startIndex] should be the markerOpen character!\n * @returns index of the last character for the extraction (or -1 if the string is invalid - no matching closing marker found). The string to extract (without the markers) is the string between startIndex + 1 and the returned value (exclusive)\n */\nexport function ExtractBetweenMarkers(markerOpen, markerClose, block, startIndex) {\n let currPos = startIndex, openMarkers = 0, waitForChar = \"\";\n while (currPos < block.length) {\n const currChar = block.charAt(currPos);\n if (!waitForChar) {\n switch (currChar) {\n case markerOpen:\n openMarkers++;\n break;\n case markerClose:\n openMarkers--;\n break;\n case '\"':\n case \"'\":\n case \"`\":\n waitForChar = currChar;\n break;\n case \"/\":\n if (currPos + 1 < block.length) {\n const nextChar = block.charAt(currPos + 1);\n if (nextChar === \"/\") {\n waitForChar = \"\\n\";\n }\n else if (nextChar === \"*\") {\n waitForChar = \"*/\";\n }\n }\n break;\n }\n }\n else {\n if (currChar === waitForChar) {\n if (waitForChar === '\"' || waitForChar === \"'\") {\n block.charAt(currPos - 1) !== \"\\\\\" && (waitForChar = \"\");\n }\n else {\n waitForChar = \"\";\n }\n }\n else if (waitForChar === \"*/\" && currChar === \"*\" && currPos + 1 < block.length) {\n block.charAt(currPos + 1) === \"/\" && (waitForChar = \"\");\n if (waitForChar === \"\") {\n currPos++;\n }\n }\n }\n currPos++;\n if (openMarkers === 0) {\n break;\n }\n }\n return openMarkers === 0 ? currPos - 1 : -1;\n}\n/**\n * Parses a string and skip whitespaces\n * @param s string to parse\n * @param index index where to start parsing\n * @returns the index after all whitespaces have been skipped\n */\nexport function SkipWhitespaces(s, index) {\n while (index < s.length) {\n const c = s[index];\n if (c !== \" \" && c !== \"\\n\" && c !== \"\\r\" && c !== \"\\t\" && c !== \"\\u000a\" && c !== \"\\u00a0\") {\n break;\n }\n index++;\n }\n return index;\n}\n/**\n * Checks if a character is an identifier character (meaning, if it is 0-9, A-Z, a-z or _)\n * @param c character to check\n * @returns true if the character is an identifier character\n */\nexport function IsIdentifierChar(c) {\n const v = c.charCodeAt(0);\n return ((v >= 48 && v <= 57) || // 0-9\n (v >= 65 && v <= 90) || // A-Z\n (v >= 97 && v <= 122) || // a-z\n v == 95); // _\n}\n/**\n * Removes the comments of a code block\n * @param block code block to parse\n * @returns block with the comments removed\n */\nexport function RemoveComments(block) {\n let currPos = 0, waitForChar = \"\", inComments = false;\n const s = [];\n while (currPos < block.length) {\n const currChar = block.charAt(currPos);\n if (!waitForChar) {\n switch (currChar) {\n case '\"':\n case \"'\":\n case \"`\":\n waitForChar = currChar;\n break;\n case \"/\":\n if (currPos + 1 < block.length) {\n const nextChar = block.charAt(currPos + 1);\n if (nextChar === \"/\") {\n waitForChar = \"\\n\";\n inComments = true;\n }\n else if (nextChar === \"*\") {\n waitForChar = \"*/\";\n inComments = true;\n }\n }\n break;\n }\n if (!inComments) {\n s.push(currChar);\n }\n }\n else {\n if (currChar === waitForChar) {\n if (waitForChar === '\"' || waitForChar === \"'\") {\n block.charAt(currPos - 1) !== \"\\\\\" && (waitForChar = \"\");\n s.push(currChar);\n }\n else {\n waitForChar = \"\";\n inComments = false;\n }\n }\n else if (waitForChar === \"*/\" && currChar === \"*\" && currPos + 1 < block.length) {\n block.charAt(currPos + 1) === \"/\" && (waitForChar = \"\");\n if (waitForChar === \"\") {\n inComments = false;\n currPos++;\n }\n }\n else {\n if (!inComments) {\n s.push(currChar);\n }\n }\n }\n currPos++;\n }\n return s.join(\"\");\n}\n/**\n * Finds the first occurrence of a character in a string going backward\n * @param s the string to parse\n * @param index starting index in the string\n * @param c the character to find\n * @param c2 an optional second character to find\n * @returns the index of the character if found, else -1\n */\nexport function FindBackward(s, index, c, c2) {\n while (index >= 0 && s.charAt(index) !== c && (!c2 || s.charAt(index) !== c2)) {\n index--;\n }\n return index;\n}\n/**\n * Escapes a string so that it is usable as a regular expression\n * @param s string to escape\n * @returns escaped string\n */\nexport function EscapeRegExp(s) {\n return s.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n/**\n * Injects code at the beginning and/or end of a function.\n * The function is identified by \"mainFuncDecl\". The starting code is injected just after the first \"\\{\" found after the mainFuncDecl.\n * The ending code is injected just before the last \"\\}\" of the whole block of code (so, it is assumed that the function is the last of the block of code).\n * @param code code to inject into\n * @param mainFuncDecl Function declaration to find in the code (for eg: \"void main\")\n * @param startingCode The code to inject at the beginning of the function\n * @param endingCode The code to inject at the end of the function\n * @returns The code with the injected code\n */\nexport function InjectStartingAndEndingCode(code, mainFuncDecl, startingCode, endingCode) {\n let idx = code.indexOf(mainFuncDecl);\n if (idx < 0) {\n return code;\n }\n if (startingCode) {\n // eslint-disable-next-line no-empty\n while (idx++ < code.length && code.charAt(idx) != \"{\") { }\n if (idx < code.length) {\n const part1 = code.substring(0, idx + 1);\n const part2 = code.substring(idx + 1);\n code = part1 + startingCode + part2;\n }\n }\n if (endingCode) {\n const lastClosingCurly = code.lastIndexOf(\"}\");\n code = code.substring(0, lastClosingCurly);\n code += endingCode + \"\\n}\";\n }\n return code;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,qBAAqBA,CAACC,UAAU,EAAEC,WAAW,EAAEC,KAAK,EAAEC,UAAU,EAAE;EAC9E,IAAIC,OAAO,GAAGD,UAAU;IAAEE,WAAW,GAAG,CAAC;IAAEC,WAAW,GAAG,EAAE;EAC3D,OAAOF,OAAO,GAAGF,KAAK,CAACK,MAAM,EAAE;IAC3B,MAAMC,QAAQ,GAAGN,KAAK,CAACO,MAAM,CAACL,OAAO,CAAC;IACtC,IAAI,CAACE,WAAW,EAAE;MACd,QAAQE,QAAQ;QACZ,KAAKR,UAAU;UACXK,WAAW,EAAE;UACb;QACJ,KAAKJ,WAAW;UACZI,WAAW,EAAE;UACb;QACJ,KAAK,GAAG;QACR,KAAK,GAAG;QACR,KAAK,GAAG;UACJC,WAAW,GAAGE,QAAQ;UACtB;QACJ,KAAK,GAAG;UACJ,IAAIJ,OAAO,GAAG,CAAC,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