@exercode/problem-utils 1.19.0 → 1.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/helpers/removeCommentsInSourceCode.cjs +6 -5
- package/dist/helpers/removeCommentsInSourceCode.cjs.map +1 -1
- package/dist/helpers/removeCommentsInSourceCode.js +6 -5
- package/dist/helpers/removeCommentsInSourceCode.js.map +1 -1
- package/dist/types/language.cjs +1 -1
- package/dist/types/language.cjs.map +1 -1
- package/dist/types/language.d.ts +1 -0
- package/dist/types/language.js +1 -1
- package/dist/types/language.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
"use strict";function e(e,t){return n(e,t,{removeStrings:!1})}function t(e,t){return n(e,t,{removeStrings:!0})}function n(e,t,n,a=r(e)){if(!e.comments?.length&&(!n.removeStrings||!e.strings?.length))return t;let s=[],c=0;for(;c<t.length;){let r;for(let e of a){let a=e.openRegExp;a.lastIndex=c;let o=a.exec(t);o&&i(o,e,r,n)&&(r={grammar:e,match:o})}if(r){let i=r.match.index;if(!r.grammar.isComment&&n.removeStrings&&(i=
|
|
2
|
-
`)}function h(e,t
|
|
3
|
-
`)}function
|
|
4
|
-
`)
|
|
5
|
-
|
|
1
|
+
"use strict";function e(e,t){return n(e,t,{removeStrings:!1})}function t(e,t){return n(e,t,{removeStrings:!0})}function n(e,t,n,a=r(e)){if(!e.comments?.length&&(!n.removeStrings||!e.strings?.length))return t;let s=[],c=0;for(;c<t.length;){let r;for(let e of a){let a=e.openRegExp;a.lastIndex=c;let o=a.exec(t);o&&i(o,e,r,n)&&(r={grammar:e,match:o})}if(r){let i=r.match.index;if(!r.grammar.isComment&&n.removeStrings&&(i=d(t,r.match.index)),s.push(t.slice(c,i)),r.grammar.isComment){let e=r.grammar.closeRegExp;e.lastIndex=r.match.index+r.match[0].length;let n=e.exec(t);c=n?n.index+n[0].length:t.length}else{c=o(t,r.match.index,r.grammar);let i=t.slice(r.match.index,c);n.removeStrings?s.push(p(e,a,r.grammar,t,r.match.index,i)):s.push(i)}}else s.push(t.slice(c)),c=t.length}return s.join(``)}function r(e){return[...e.comments?.map(e=>({closeRegExp:a(e.close??/(?=\n)/g),isComment:!0,openRegExp:a(e.open)}))??[],...e.strings?.map(e=>({closeRegExp:a(e.close),isComment:!1,openRegExp:a(e.open),templateSyntax:e.templateSyntax}))??[]]}function i(e,t,n,r){return!n||e.index<n.match.index?!0:e.index>n.match.index?!1:r.removeStrings&&n.grammar.isComment&&!t.isComment}function a(e){return new RegExp(e,e.flags.includes(`g`)?e.flags:`${e.flags}g`)}function o(e,t,n){if(n.templateSyntax===`kotlin`)return s(e,t);if(e[t]==="`")return c(e,t);if(_(e,t))return l(e,t);let r=n.closeRegExp;r.lastIndex=t+1;let i=r.exec(e);return i?i.index+i[0].length:e.length}function s(e,t){let n=u(e,t),r=n.length===3,i=t+n.length;for(;i<e.length;){if(e.startsWith(n,i))return i+n.length;if(!r&&e[i]===`\\`){i+=2;continue}if(e[i]===`$`&&e[i+1]===`{`){i=b(e,i+2,`}`,{slashStartsComments:!0,slashStartsRegExp:!1,supportsKotlinStrings:!0}).endIndex+1;continue}i+=1}return e.length}function c(e,t){let n=t+1;for(;n<e.length;){if(e[n]===`\\`){n+=2;continue}if(e[n]==="`")return n+1;if(e[n]===`$`&&e[n+1]===`{`){n=b(e,n+2,`}`,{slashStartsRegExp:!0}).endIndex+1;continue}n+=1}return e.length}function l(e,t){let n=u(e,t),r=t+n.length;for(;r<e.length;){if(e.startsWith(n,r))return r+n.length;if(e[r]===`{`&&e[r+1]===`{`){r+=2;continue}if(e[r]===`{`){r=b(e,r+1,`}`,{slashStartsRegExp:!1}).endIndex+1;continue}r+=e[r]===`\\`?2:1}return e.length}function u(e,t){let n=e.slice(t,t+3);return n===`'''`||n===`"""`?n:e[t]??``}function d(e,t){let n=f(e,t);return n?t-n.length:t}function f(e,t){if(e[t]!==`"`&&e[t]!==`'`)return;let n=t-1;for(;n>=0&&/[A-Za-z]/.test(e[n]??``);)--n;let r=e.slice(n+1,t);if(!(!r||!/^[bfru]+$/i.test(r))&&!(n>=0&&/[\dA-Za-z_]/.test(e[n]??``)))return r}function p(e,t,n,r,i,a){return n.templateSyntax===`kotlin`?m(e,t,a):a.startsWith("`")?v(e,t,a):_(r,i)?y(e,t,a):``}function m(e,t,r){let i=u(r,0).length,a=i===3,o=[],s=i;for(;s<r.length-i;){if(!a&&r[s]===`\\`){s+=2;continue}if(r[s]!==`$`){s+=1;continue}if(r[s+1]===`{`){let i=b(r,s+2,`}`,{slashStartsComments:!0,slashStartsRegExp:!1,supportsKotlinStrings:!0});o.push(n(e,i.content,{removeStrings:!0},t)),s=i.endIndex+1;continue}if(h(r[s+1])){let e=s+2;for(;g(r[e]);)e+=1;o.push(r.slice(s+1,e)),s=e;continue}s+=1}return o.join(`
|
|
2
|
+
`)}function h(e){return e!==void 0&&/[\p{L}_]/u.test(e)}function g(e){return e!==void 0&&/[\p{L}\p{N}_]/u.test(e)}function _(e,t){return f(e,t)?.toLowerCase().includes(`f`)??!1}function v(e,t,r){let i=[],a=1;for(;a<r.length-1;){if(r[a]===`\\`){a+=2;continue}if(r[a]===`$`&&r[a+1]===`{`){let o=b(r,a+2,`}`,{slashStartsRegExp:!0});i.push(n(e,o.content,{removeStrings:!0},t)),a=o.endIndex+1;continue}a+=1}return i.join(`
|
|
3
|
+
`)}function y(e,t,r){let i=u(r,0).length,a=[],o=i;for(;o<r.length-i;){if(r[o]===`{`&&r[o+1]===`{`){o+=2;continue}if(r[o]===`{`){let i=b(r,o+1,`}`,{slashStartsRegExp:!1});a.push(n(e,i.content,{removeStrings:!0},t)),o=i.endIndex+1;continue}o+=r[o]===`\\`?2:1}return a.join(`
|
|
4
|
+
`)}function b(e,t,n,r){let i=1,a=t;for(;a<e.length;){let o=e[a];if(o===`"`&&r.supportsKotlinStrings){a=s(e,a);continue}if(o===`"`||o===`'`||o==="`"){a=x(e,a);continue}if((r.slashStartsComments||r.slashStartsRegExp)&&e[a]===`/`&&e[a+1]===`/`){a=C(e,a);continue}if((r.slashStartsComments||r.slashStartsRegExp)&&e[a]===`/`&&e[a+1]===`*`){a=w(e,a);continue}if(r.slashStartsRegExp&&o===`/`){a=S(e,a);continue}if(o===`{`&&(i+=1),o===n&&(--i,i===0))return{content:e.slice(t,a),endIndex:a};a+=1}return{content:e.slice(t),endIndex:e.length}}function x(e,t){let n=u(e,t),r=t+n.length;for(;r<e.length;){if(e[r]===`\\`){r+=2;continue}if(e.startsWith(n,r))return r+n.length;r+=1}return r}function S(e,t){let n=t+1,r=!1;for(;n<e.length;){if(e[n]===`\\`){n+=2;continue}if(e[n]===`[`&&(r=!0),e[n]===`]`&&(r=!1),e[n]===`/`&&!r){for(n+=1;/[A-Za-z]/.test(e[n]??``);)n+=1;return n}if(e[n]===`
|
|
5
|
+
`)return t+1;n+=1}return t+1}function C(e,t){let n=e.indexOf(`
|
|
6
|
+
`,t+2);return n===-1?e.length:n}function w(e,t){let n=e.indexOf(`*/`,t+2);return n===-1?e.length:n+2}exports.removeCommentsAndStringsInSourceCode=t,exports.removeCommentsInSourceCode=e;
|
|
6
7
|
//# sourceMappingURL=removeCommentsInSourceCode.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"removeCommentsInSourceCode.cjs","names":[],"sources":["../../src/helpers/removeCommentsInSourceCode.ts"],"sourcesContent":["import type { LanguageDefinition } from '../types/language.js';\n\nexport type SourceCodeGrammar = NonNullable<LanguageDefinition['grammer']>;\n\n/** Removes comments from source code according to the provided language grammar. */\nexport function removeCommentsInSourceCode(grammar: SourceCodeGrammar, sourceCode: string): string {\n return removeCommentsAndMaybeStringsInSourceCode(grammar, sourceCode, { removeStrings: false });\n}\n\n/** Removes comments and string literal contents while preserving executable interpolation expressions. */\nexport function removeCommentsAndStringsInSourceCode(grammar: SourceCodeGrammar, sourceCode: string): string {\n return removeCommentsAndMaybeStringsInSourceCode(grammar, sourceCode, { removeStrings: true });\n}\n\ninterface CommentOrStringGrammar {\n closeRegExp: RegExp;\n isComment: boolean;\n openRegExp: RegExp;\n}\n\nfunction removeCommentsAndMaybeStringsInSourceCode(\n grammar: SourceCodeGrammar,\n sourceCode: string,\n options: { removeStrings: boolean },\n commentOrStringGrammars = compileCommentOrStringGrammars(grammar)\n): string {\n if (!grammar.comments?.length && (!options.removeStrings || !grammar.strings?.length)) return sourceCode;\n\n const newSourceCodeSlices: string[] = [];\n\n let lastIndex = 0;\n\n while (lastIndex < sourceCode.length) {\n let first: { grammar: CommentOrStringGrammar; match: RegExpExecArray } | undefined;\n\n for (const commentOrStringGrammer of commentOrStringGrammars) {\n const startRegExp = commentOrStringGrammer.openRegExp;\n startRegExp.lastIndex = lastIndex;\n\n const match = startRegExp.exec(sourceCode);\n\n if (match && shouldPreferMatch(match, commentOrStringGrammer, first, options)) {\n first = { grammar: commentOrStringGrammer, match };\n }\n }\n\n if (first) {\n let stringPrefixStartIndex = first.match.index;\n if (!first.grammar.isComment && options.removeStrings) {\n stringPrefixStartIndex = getPythonStringPrefixStartIndex(sourceCode, first.match.index);\n }\n newSourceCodeSlices.push(sourceCode.slice(lastIndex, stringPrefixStartIndex));\n\n if (!first.grammar.isComment) {\n lastIndex = findStringEndIndex(sourceCode, first.match.index, first.grammar);\n const stringLiteral = sourceCode.slice(first.match.index, lastIndex);\n if (options.removeStrings) {\n newSourceCodeSlices.push(\n preserveStringInterpolationExpressions(\n grammar,\n commentOrStringGrammars,\n sourceCode,\n first.match.index,\n stringLiteral\n )\n );\n } else {\n newSourceCodeSlices.push(stringLiteral);\n }\n } else {\n const closeRegExp = first.grammar.closeRegExp;\n closeRegExp.lastIndex = first.match.index + first.match[0].length;\n\n const match = closeRegExp.exec(sourceCode);\n\n lastIndex = match ? match.index + match[0].length : sourceCode.length;\n }\n } else {\n newSourceCodeSlices.push(sourceCode.slice(lastIndex));\n lastIndex = sourceCode.length;\n }\n }\n\n return newSourceCodeSlices.join('');\n}\n\nfunction compileCommentOrStringGrammars(grammar: SourceCodeGrammar): readonly CommentOrStringGrammar[] {\n return [\n ...(grammar.comments?.map((v) => ({\n closeRegExp: makeGlobalRegExp(v.close ?? /(?=\\n)/g),\n isComment: true,\n openRegExp: makeGlobalRegExp(v.open),\n })) ?? []),\n ...(grammar.strings?.map((v) => ({\n closeRegExp: makeGlobalRegExp(v.close),\n isComment: false,\n openRegExp: makeGlobalRegExp(v.open),\n })) ?? []),\n ] satisfies CommentOrStringGrammar[];\n}\n\nfunction shouldPreferMatch(\n match: RegExpExecArray,\n grammar: CommentOrStringGrammar,\n first: { grammar: CommentOrStringGrammar; match: RegExpExecArray } | undefined,\n options: { removeStrings: boolean }\n): boolean {\n if (!first) return true;\n if (match.index < first.match.index) return true;\n if (match.index > first.match.index) return false;\n return options.removeStrings && first.grammar.isComment && !grammar.isComment;\n}\n\nfunction makeGlobalRegExp(regExp: RegExp): RegExp {\n return new RegExp(regExp, regExp.flags.includes('g') ? regExp.flags : `${regExp.flags}g`);\n}\n\nfunction findStringEndIndex(sourceCode: string, stringStartIndex: number, grammar: CommentOrStringGrammar): number {\n if (sourceCode[stringStartIndex] === '`') return findJavaScriptTemplateEndIndex(sourceCode, stringStartIndex);\n if (hasPythonFStringPrefix(sourceCode, stringStartIndex))\n return findPythonFStringEndIndex(sourceCode, stringStartIndex);\n\n const closeRegExp = grammar.closeRegExp;\n closeRegExp.lastIndex = stringStartIndex + 1;\n const match = closeRegExp.exec(sourceCode);\n return match ? match.index + match[0].length : sourceCode.length;\n}\n\nfunction findJavaScriptTemplateEndIndex(sourceCode: string, stringStartIndex: number): number {\n let index = stringStartIndex + 1;\n\n while (index < sourceCode.length) {\n if (sourceCode[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (sourceCode[index] === '`') return index + 1;\n if (sourceCode[index] === '$' && sourceCode[index + 1] === '{') {\n index = readBalancedExpression(sourceCode, index + 2, '}', { slashStartsRegExp: true }).endIndex + 1;\n continue;\n }\n index += 1;\n }\n\n return sourceCode.length;\n}\n\nfunction findPythonFStringEndIndex(sourceCode: string, stringStartIndex: number): number {\n const quote = getStringQuote(sourceCode, stringStartIndex);\n let index = stringStartIndex + quote.length;\n\n while (index < sourceCode.length) {\n if (sourceCode.startsWith(quote, index)) return index + quote.length;\n if (sourceCode[index] === '{' && sourceCode[index + 1] === '{') {\n index += 2;\n continue;\n }\n if (sourceCode[index] === '{') {\n index = readBalancedExpression(sourceCode, index + 1, '}', { slashStartsRegExp: false }).endIndex + 1;\n continue;\n }\n index += sourceCode[index] === '\\\\' ? 2 : 1;\n }\n\n return sourceCode.length;\n}\n\nfunction getStringQuote(sourceCode: string, stringStartIndex: number): string {\n const threeCharacterQuote = sourceCode.slice(stringStartIndex, stringStartIndex + 3);\n if (threeCharacterQuote === \"'''\" || threeCharacterQuote === '\"\"\"') return threeCharacterQuote;\n return sourceCode[stringStartIndex] ?? '';\n}\n\nfunction getPythonStringPrefixStartIndex(sourceCode: string, stringStartIndex: number): number {\n const prefix = getPythonStringPrefix(sourceCode, stringStartIndex);\n return prefix ? stringStartIndex - prefix.length : stringStartIndex;\n}\n\nfunction getPythonStringPrefix(sourceCode: string, stringStartIndex: number): string | undefined {\n if (sourceCode[stringStartIndex] !== '\"' && sourceCode[stringStartIndex] !== \"'\") return undefined;\n let index = stringStartIndex - 1;\n while (index >= 0 && /[A-Za-z]/.test(sourceCode[index] ?? '')) index -= 1;\n\n const prefix = sourceCode.slice(index + 1, stringStartIndex);\n if (!prefix || !/^[bfru]+$/i.test(prefix)) return undefined;\n if (index >= 0 && /[\\dA-Za-z_]/.test(sourceCode[index] ?? '')) return undefined;\n\n return prefix;\n}\n\nfunction preserveStringInterpolationExpressions(\n grammar: SourceCodeGrammar,\n commentOrStringGrammars: readonly CommentOrStringGrammar[],\n sourceCode: string,\n stringStartIndex: number,\n stringLiteral: string\n): string {\n if (stringLiteral.startsWith('`'))\n return preserveJavaScriptTemplateExpressions(grammar, commentOrStringGrammars, stringLiteral);\n if (hasPythonFStringPrefix(sourceCode, stringStartIndex))\n return preservePythonFStringExpressions(grammar, commentOrStringGrammars, stringLiteral);\n return '';\n}\n\nfunction hasPythonFStringPrefix(sourceCode: string, stringStartIndex: number): boolean {\n return getPythonStringPrefix(sourceCode, stringStartIndex)?.toLowerCase().includes('f') ?? false;\n}\n\nfunction preserveJavaScriptTemplateExpressions(\n grammar: SourceCodeGrammar,\n commentOrStringGrammars: readonly CommentOrStringGrammar[],\n stringLiteral: string\n): string {\n const expressions: string[] = [];\n let index = 1;\n\n while (index < stringLiteral.length - 1) {\n if (stringLiteral[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (stringLiteral[index] === '$' && stringLiteral[index + 1] === '{') {\n const expression = readBalancedExpression(stringLiteral, index + 2, '}', { slashStartsRegExp: true });\n expressions.push(\n removeCommentsAndMaybeStringsInSourceCode(\n grammar,\n expression.content,\n { removeStrings: true },\n commentOrStringGrammars\n )\n );\n index = expression.endIndex + 1;\n continue;\n }\n index += 1;\n }\n\n return expressions.join('\\n');\n}\n\nfunction preservePythonFStringExpressions(\n grammar: SourceCodeGrammar,\n commentOrStringGrammars: readonly CommentOrStringGrammar[],\n stringLiteral: string\n): string {\n const quoteLength = getStringQuote(stringLiteral, 0).length;\n const expressions: string[] = [];\n let index = quoteLength;\n\n while (index < stringLiteral.length - quoteLength) {\n if (stringLiteral[index] === '{' && stringLiteral[index + 1] === '{') {\n index += 2;\n continue;\n }\n if (stringLiteral[index] === '{') {\n const expression = readBalancedExpression(stringLiteral, index + 1, '}', { slashStartsRegExp: false });\n expressions.push(\n removeCommentsAndMaybeStringsInSourceCode(\n grammar,\n expression.content,\n { removeStrings: true },\n commentOrStringGrammars\n )\n );\n index = expression.endIndex + 1;\n continue;\n }\n index += stringLiteral[index] === '\\\\' ? 2 : 1;\n }\n\n return expressions.join('\\n');\n}\n\nfunction readBalancedExpression(\n sourceCode: string,\n startIndex: number,\n closeChar: string,\n options: { slashStartsRegExp: boolean }\n): { content: string; endIndex: number } {\n let depth = 1;\n let index = startIndex;\n\n while (index < sourceCode.length) {\n const char = sourceCode[index];\n if (char === '\"' || char === \"'\" || char === '`') {\n index = skipQuotedSpan(sourceCode, index);\n continue;\n }\n if (options.slashStartsRegExp && sourceCode[index] === '/' && sourceCode[index + 1] === '/') {\n index = skipJavaScriptSingleLineComment(sourceCode, index);\n continue;\n }\n if (options.slashStartsRegExp && sourceCode[index] === '/' && sourceCode[index + 1] === '*') {\n index = skipJavaScriptBlockComment(sourceCode, index);\n continue;\n }\n if (options.slashStartsRegExp && char === '/') {\n index = skipJavaScriptRegExpLiteral(sourceCode, index);\n continue;\n }\n if (char === '{') depth += 1;\n if (char === closeChar) {\n depth -= 1;\n if (depth === 0) return { content: sourceCode.slice(startIndex, index), endIndex: index };\n }\n index += 1;\n }\n\n return { content: sourceCode.slice(startIndex), endIndex: sourceCode.length };\n}\n\nfunction skipQuotedSpan(sourceCode: string, startIndex: number): number {\n const quote = getStringQuote(sourceCode, startIndex);\n let index = startIndex + quote.length;\n\n while (index < sourceCode.length) {\n if (sourceCode[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (sourceCode.startsWith(quote, index)) return index + quote.length;\n index += 1;\n }\n\n return index;\n}\n\nfunction skipJavaScriptRegExpLiteral(sourceCode: string, startIndex: number): number {\n let index = startIndex + 1;\n let inCharacterClass = false;\n\n while (index < sourceCode.length) {\n if (sourceCode[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (sourceCode[index] === '[') inCharacterClass = true;\n if (sourceCode[index] === ']') inCharacterClass = false;\n if (sourceCode[index] === '/' && !inCharacterClass) {\n index += 1;\n while (/[A-Za-z]/.test(sourceCode[index] ?? '')) index += 1;\n return index;\n }\n if (sourceCode[index] === '\\n') return startIndex + 1;\n index += 1;\n }\n\n return startIndex + 1;\n}\n\nfunction skipJavaScriptSingleLineComment(sourceCode: string, startIndex: number): number {\n const newLineIndex = sourceCode.indexOf('\\n', startIndex + 2);\n return newLineIndex === -1 ? sourceCode.length : newLineIndex;\n}\n\nfunction skipJavaScriptBlockComment(sourceCode: string, startIndex: number): number {\n const endIndex = sourceCode.indexOf('*/', startIndex + 2);\n return endIndex === -1 ? sourceCode.length : endIndex + 2;\n}\n"],"mappings":"aAKA,SAAgB,EAA2B,EAA4B,EAA4B,CACjG,OAAO,EAA0C,EAAS,EAAY,CAAE,cAAe,EAAM,CAAC,CAChG,CAGA,SAAgB,EAAqC,EAA4B,EAA4B,CAC3G,OAAO,EAA0C,EAAS,EAAY,CAAE,cAAe,EAAK,CAAC,CAC/F,CAQA,SAAS,EACP,EACA,EACA,EACA,EAA0B,EAA+B,CAAO,EACxD,CACR,GAAI,CAAC,EAAQ,UAAU,SAAW,CAAC,EAAQ,eAAiB,CAAC,EAAQ,SAAS,QAAS,OAAO,EAE9F,IAAM,EAAgC,CAAC,EAEnC,EAAY,EAEhB,KAAO,EAAY,EAAW,QAAQ,CACpC,IAAI,EAEJ,IAAK,IAAM,KAA0B,EAAyB,CAC5D,IAAM,EAAc,EAAuB,WAC3C,EAAY,UAAY,EAExB,IAAM,EAAQ,EAAY,KAAK,CAAU,EAErC,GAAS,EAAkB,EAAO,EAAwB,EAAO,CAAO,IAC1E,EAAQ,CAAE,QAAS,EAAwB,OAAM,EAErD,CAEA,GAAI,EAAO,CACT,IAAI,EAAyB,EAAM,MAAM,MAMzC,GALI,CAAC,EAAM,QAAQ,WAAa,EAAQ,gBACtC,EAAyB,EAAgC,EAAY,EAAM,MAAM,KAAK,GAExF,EAAoB,KAAK,EAAW,MAAM,EAAW,CAAsB,CAAC,EAEvE,EAAM,QAAQ,UAgBZ,CACL,IAAM,EAAc,EAAM,QAAQ,YAClC,EAAY,UAAY,EAAM,MAAM,MAAQ,EAAM,MAAM,EAAE,CAAC,OAE3D,IAAM,EAAQ,EAAY,KAAK,CAAU,EAEzC,EAAY,EAAQ,EAAM,MAAQ,EAAM,EAAE,CAAC,OAAS,EAAW,MACjE,KAvB8B,CAC5B,EAAY,EAAmB,EAAY,EAAM,MAAM,MAAO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AW,WAAW,EAAO,CAAK,EAAG,OAAO,EAAQ,EAAM,OAC9D,GAAS,CACX,CAEA,OAAO,CACT,CAEA,SAAS,EAA4B,EAAoB,EAA4B,CACnF,IAAI,EAAQ,EAAa,EACrB,EAAmB,GAEvB,KAAO,EAAQ,EAAW,QAAQ,CAChC,GAAI,EAAW,KAAW,KAAM,CAC9B,GAAS,EACT,QACF,CAGA,GAFI,EAAW,KAAW,MAAK,EAAmB,IAC9C,EAAW,KAAW,MAAK,EAAmB,IAC9C,EAAW,KAAW,KAAO,CAAC,EAAkB,CAElD,IADA,GAAS,EACF,WAAW,KAAK,EAAW,IAAU,EAAE,GAAG,GAAS,EAC1D,OAAO,CACT,CACA,GAAI,EAAW,KAAW;EAAM,OAAO,EAAa,EACpD,GAAS,CACX,CAEA,OAAO,EAAa,CACtB,CAEA,SAAS,EAAgC,EAAoB,EAA4B,CACvF,IAAM,EAAe,EAAW,QAAQ;EAAM,EAAa,CAAC,EAC5D,OAAO,IAAiB,GAAK,EAAW,OAAS,CACnD,CAEA,SAAS,EAA2B,EAAoB,EAA4B,CAClF,IAAM,EAAW,EAAW,QAAQ,KAAM,EAAa,CAAC,EACxD,OAAO,IAAa,GAAK,EAAW,OAAS,EAAW,CAC1D"}
|
|
1
|
+
{"version":3,"file":"removeCommentsInSourceCode.cjs","names":[],"sources":["../../src/helpers/removeCommentsInSourceCode.ts"],"sourcesContent":["import type { LanguageDefinition } from '../types/language.js';\n\nexport type SourceCodeGrammar = NonNullable<LanguageDefinition['grammer']>;\n\n/** Removes comments from source code according to the provided language grammar. */\nexport function removeCommentsInSourceCode(grammar: SourceCodeGrammar, sourceCode: string): string {\n return removeCommentsAndMaybeStringsInSourceCode(grammar, sourceCode, { removeStrings: false });\n}\n\n/** Removes comments and string literal contents while preserving executable interpolation expressions. */\nexport function removeCommentsAndStringsInSourceCode(grammar: SourceCodeGrammar, sourceCode: string): string {\n return removeCommentsAndMaybeStringsInSourceCode(grammar, sourceCode, { removeStrings: true });\n}\n\ninterface CommentOrStringGrammar {\n closeRegExp: RegExp;\n isComment: boolean;\n openRegExp: RegExp;\n templateSyntax?: 'kotlin';\n}\n\ninterface BalancedExpressionOptions {\n slashStartsComments?: boolean;\n slashStartsRegExp: boolean;\n supportsKotlinStrings?: boolean;\n}\n\nfunction removeCommentsAndMaybeStringsInSourceCode(\n grammar: SourceCodeGrammar,\n sourceCode: string,\n options: { removeStrings: boolean },\n commentOrStringGrammars = compileCommentOrStringGrammars(grammar)\n): string {\n if (!grammar.comments?.length && (!options.removeStrings || !grammar.strings?.length)) return sourceCode;\n\n const newSourceCodeSlices: string[] = [];\n\n let lastIndex = 0;\n\n while (lastIndex < sourceCode.length) {\n let first: { grammar: CommentOrStringGrammar; match: RegExpExecArray } | undefined;\n\n for (const commentOrStringGrammer of commentOrStringGrammars) {\n const startRegExp = commentOrStringGrammer.openRegExp;\n startRegExp.lastIndex = lastIndex;\n\n const match = startRegExp.exec(sourceCode);\n\n if (match && shouldPreferMatch(match, commentOrStringGrammer, first, options)) {\n first = { grammar: commentOrStringGrammer, match };\n }\n }\n\n if (first) {\n let stringPrefixStartIndex = first.match.index;\n if (!first.grammar.isComment && options.removeStrings) {\n stringPrefixStartIndex = getPythonStringPrefixStartIndex(sourceCode, first.match.index);\n }\n newSourceCodeSlices.push(sourceCode.slice(lastIndex, stringPrefixStartIndex));\n\n if (!first.grammar.isComment) {\n lastIndex = findStringEndIndex(sourceCode, first.match.index, first.grammar);\n const stringLiteral = sourceCode.slice(first.match.index, lastIndex);\n if (options.removeStrings) {\n newSourceCodeSlices.push(\n preserveStringInterpolationExpressions(\n grammar,\n commentOrStringGrammars,\n first.grammar,\n sourceCode,\n first.match.index,\n stringLiteral\n )\n );\n } else {\n newSourceCodeSlices.push(stringLiteral);\n }\n } else {\n const closeRegExp = first.grammar.closeRegExp;\n closeRegExp.lastIndex = first.match.index + first.match[0].length;\n\n const match = closeRegExp.exec(sourceCode);\n\n lastIndex = match ? match.index + match[0].length : sourceCode.length;\n }\n } else {\n newSourceCodeSlices.push(sourceCode.slice(lastIndex));\n lastIndex = sourceCode.length;\n }\n }\n\n return newSourceCodeSlices.join('');\n}\n\nfunction compileCommentOrStringGrammars(grammar: SourceCodeGrammar): readonly CommentOrStringGrammar[] {\n return [\n ...(grammar.comments?.map((v) => ({\n closeRegExp: makeGlobalRegExp(v.close ?? /(?=\\n)/g),\n isComment: true,\n openRegExp: makeGlobalRegExp(v.open),\n })) ?? []),\n ...(grammar.strings?.map((v) => ({\n closeRegExp: makeGlobalRegExp(v.close),\n isComment: false,\n openRegExp: makeGlobalRegExp(v.open),\n templateSyntax: v.templateSyntax,\n })) ?? []),\n ] satisfies CommentOrStringGrammar[];\n}\n\nfunction shouldPreferMatch(\n match: RegExpExecArray,\n grammar: CommentOrStringGrammar,\n first: { grammar: CommentOrStringGrammar; match: RegExpExecArray } | undefined,\n options: { removeStrings: boolean }\n): boolean {\n if (!first) return true;\n if (match.index < first.match.index) return true;\n if (match.index > first.match.index) return false;\n return options.removeStrings && first.grammar.isComment && !grammar.isComment;\n}\n\nfunction makeGlobalRegExp(regExp: RegExp): RegExp {\n return new RegExp(regExp, regExp.flags.includes('g') ? regExp.flags : `${regExp.flags}g`);\n}\n\nfunction findStringEndIndex(sourceCode: string, stringStartIndex: number, grammar: CommentOrStringGrammar): number {\n if (grammar.templateSyntax === 'kotlin') return findKotlinStringEndIndex(sourceCode, stringStartIndex);\n if (sourceCode[stringStartIndex] === '`') return findJavaScriptTemplateEndIndex(sourceCode, stringStartIndex);\n if (hasPythonFStringPrefix(sourceCode, stringStartIndex))\n return findPythonFStringEndIndex(sourceCode, stringStartIndex);\n\n const closeRegExp = grammar.closeRegExp;\n closeRegExp.lastIndex = stringStartIndex + 1;\n const match = closeRegExp.exec(sourceCode);\n return match ? match.index + match[0].length : sourceCode.length;\n}\n\nfunction findKotlinStringEndIndex(sourceCode: string, stringStartIndex: number): number {\n const quote = getStringQuote(sourceCode, stringStartIndex);\n const isRawString = quote.length === 3;\n let index = stringStartIndex + quote.length;\n\n while (index < sourceCode.length) {\n if (sourceCode.startsWith(quote, index)) return index + quote.length;\n if (!isRawString && sourceCode[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (sourceCode[index] === '$' && sourceCode[index + 1] === '{') {\n index =\n readBalancedExpression(sourceCode, index + 2, '}', {\n slashStartsComments: true,\n slashStartsRegExp: false,\n supportsKotlinStrings: true,\n }).endIndex + 1;\n continue;\n }\n index += 1;\n }\n\n return sourceCode.length;\n}\n\nfunction findJavaScriptTemplateEndIndex(sourceCode: string, stringStartIndex: number): number {\n let index = stringStartIndex + 1;\n\n while (index < sourceCode.length) {\n if (sourceCode[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (sourceCode[index] === '`') return index + 1;\n if (sourceCode[index] === '$' && sourceCode[index + 1] === '{') {\n index = readBalancedExpression(sourceCode, index + 2, '}', { slashStartsRegExp: true }).endIndex + 1;\n continue;\n }\n index += 1;\n }\n\n return sourceCode.length;\n}\n\nfunction findPythonFStringEndIndex(sourceCode: string, stringStartIndex: number): number {\n const quote = getStringQuote(sourceCode, stringStartIndex);\n let index = stringStartIndex + quote.length;\n\n while (index < sourceCode.length) {\n if (sourceCode.startsWith(quote, index)) return index + quote.length;\n if (sourceCode[index] === '{' && sourceCode[index + 1] === '{') {\n index += 2;\n continue;\n }\n if (sourceCode[index] === '{') {\n index = readBalancedExpression(sourceCode, index + 1, '}', { slashStartsRegExp: false }).endIndex + 1;\n continue;\n }\n index += sourceCode[index] === '\\\\' ? 2 : 1;\n }\n\n return sourceCode.length;\n}\n\nfunction getStringQuote(sourceCode: string, stringStartIndex: number): string {\n const threeCharacterQuote = sourceCode.slice(stringStartIndex, stringStartIndex + 3);\n if (threeCharacterQuote === \"'''\" || threeCharacterQuote === '\"\"\"') return threeCharacterQuote;\n return sourceCode[stringStartIndex] ?? '';\n}\n\nfunction getPythonStringPrefixStartIndex(sourceCode: string, stringStartIndex: number): number {\n const prefix = getPythonStringPrefix(sourceCode, stringStartIndex);\n return prefix ? stringStartIndex - prefix.length : stringStartIndex;\n}\n\nfunction getPythonStringPrefix(sourceCode: string, stringStartIndex: number): string | undefined {\n if (sourceCode[stringStartIndex] !== '\"' && sourceCode[stringStartIndex] !== \"'\") return undefined;\n let index = stringStartIndex - 1;\n while (index >= 0 && /[A-Za-z]/.test(sourceCode[index] ?? '')) index -= 1;\n\n const prefix = sourceCode.slice(index + 1, stringStartIndex);\n if (!prefix || !/^[bfru]+$/i.test(prefix)) return undefined;\n if (index >= 0 && /[\\dA-Za-z_]/.test(sourceCode[index] ?? '')) return undefined;\n\n return prefix;\n}\n\nfunction preserveStringInterpolationExpressions(\n grammar: SourceCodeGrammar,\n commentOrStringGrammars: readonly CommentOrStringGrammar[],\n stringGrammar: CommentOrStringGrammar,\n sourceCode: string,\n stringStartIndex: number,\n stringLiteral: string\n): string {\n if (stringGrammar.templateSyntax === 'kotlin')\n return preserveKotlinStringTemplateExpressions(grammar, commentOrStringGrammars, stringLiteral);\n if (stringLiteral.startsWith('`'))\n return preserveJavaScriptTemplateExpressions(grammar, commentOrStringGrammars, stringLiteral);\n if (hasPythonFStringPrefix(sourceCode, stringStartIndex))\n return preservePythonFStringExpressions(grammar, commentOrStringGrammars, stringLiteral);\n return '';\n}\n\nfunction preserveKotlinStringTemplateExpressions(\n grammar: SourceCodeGrammar,\n commentOrStringGrammars: readonly CommentOrStringGrammar[],\n stringLiteral: string\n): string {\n const quoteLength = getStringQuote(stringLiteral, 0).length;\n const isRawString = quoteLength === 3;\n const expressions: string[] = [];\n let index = quoteLength;\n\n while (index < stringLiteral.length - quoteLength) {\n if (!isRawString && stringLiteral[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (stringLiteral[index] !== '$') {\n index += 1;\n continue;\n }\n if (stringLiteral[index + 1] === '{') {\n const expression = readBalancedExpression(stringLiteral, index + 2, '}', {\n slashStartsComments: true,\n slashStartsRegExp: false,\n supportsKotlinStrings: true,\n });\n expressions.push(\n removeCommentsAndMaybeStringsInSourceCode(\n grammar,\n expression.content,\n { removeStrings: true },\n commentOrStringGrammars\n )\n );\n index = expression.endIndex + 1;\n continue;\n }\n if (isKotlinIdentifierStart(stringLiteral[index + 1])) {\n let endIndex = index + 2;\n while (isKotlinIdentifierPart(stringLiteral[endIndex])) endIndex += 1;\n expressions.push(stringLiteral.slice(index + 1, endIndex));\n index = endIndex;\n continue;\n }\n index += 1;\n }\n\n return expressions.join('\\n');\n}\n\nfunction isKotlinIdentifierStart(character: string | undefined): boolean {\n return character !== undefined && /[\\p{L}_]/u.test(character);\n}\n\nfunction isKotlinIdentifierPart(character: string | undefined): boolean {\n return character !== undefined && /[\\p{L}\\p{N}_]/u.test(character);\n}\n\nfunction hasPythonFStringPrefix(sourceCode: string, stringStartIndex: number): boolean {\n return getPythonStringPrefix(sourceCode, stringStartIndex)?.toLowerCase().includes('f') ?? false;\n}\n\nfunction preserveJavaScriptTemplateExpressions(\n grammar: SourceCodeGrammar,\n commentOrStringGrammars: readonly CommentOrStringGrammar[],\n stringLiteral: string\n): string {\n const expressions: string[] = [];\n let index = 1;\n\n while (index < stringLiteral.length - 1) {\n if (stringLiteral[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (stringLiteral[index] === '$' && stringLiteral[index + 1] === '{') {\n const expression = readBalancedExpression(stringLiteral, index + 2, '}', { slashStartsRegExp: true });\n expressions.push(\n removeCommentsAndMaybeStringsInSourceCode(\n grammar,\n expression.content,\n { removeStrings: true },\n commentOrStringGrammars\n )\n );\n index = expression.endIndex + 1;\n continue;\n }\n index += 1;\n }\n\n return expressions.join('\\n');\n}\n\nfunction preservePythonFStringExpressions(\n grammar: SourceCodeGrammar,\n commentOrStringGrammars: readonly CommentOrStringGrammar[],\n stringLiteral: string\n): string {\n const quoteLength = getStringQuote(stringLiteral, 0).length;\n const expressions: string[] = [];\n let index = quoteLength;\n\n while (index < stringLiteral.length - quoteLength) {\n if (stringLiteral[index] === '{' && stringLiteral[index + 1] === '{') {\n index += 2;\n continue;\n }\n if (stringLiteral[index] === '{') {\n const expression = readBalancedExpression(stringLiteral, index + 1, '}', { slashStartsRegExp: false });\n expressions.push(\n removeCommentsAndMaybeStringsInSourceCode(\n grammar,\n expression.content,\n { removeStrings: true },\n commentOrStringGrammars\n )\n );\n index = expression.endIndex + 1;\n continue;\n }\n index += stringLiteral[index] === '\\\\' ? 2 : 1;\n }\n\n return expressions.join('\\n');\n}\n\nfunction readBalancedExpression(\n sourceCode: string,\n startIndex: number,\n closeChar: string,\n options: BalancedExpressionOptions\n): { content: string; endIndex: number } {\n let depth = 1;\n let index = startIndex;\n\n while (index < sourceCode.length) {\n const char = sourceCode[index];\n if (char === '\"' && options.supportsKotlinStrings) {\n index = findKotlinStringEndIndex(sourceCode, index);\n continue;\n }\n if (char === '\"' || char === \"'\" || char === '`') {\n index = skipQuotedSpan(sourceCode, index);\n continue;\n }\n if (\n (options.slashStartsComments || options.slashStartsRegExp) &&\n sourceCode[index] === '/' &&\n sourceCode[index + 1] === '/'\n ) {\n index = skipJavaScriptSingleLineComment(sourceCode, index);\n continue;\n }\n if (\n (options.slashStartsComments || options.slashStartsRegExp) &&\n sourceCode[index] === '/' &&\n sourceCode[index + 1] === '*'\n ) {\n index = skipJavaScriptBlockComment(sourceCode, index);\n continue;\n }\n if (options.slashStartsRegExp && char === '/') {\n index = skipJavaScriptRegExpLiteral(sourceCode, index);\n continue;\n }\n if (char === '{') depth += 1;\n if (char === closeChar) {\n depth -= 1;\n if (depth === 0) return { content: sourceCode.slice(startIndex, index), endIndex: index };\n }\n index += 1;\n }\n\n return { content: sourceCode.slice(startIndex), endIndex: sourceCode.length };\n}\n\nfunction skipQuotedSpan(sourceCode: string, startIndex: number): number {\n const quote = getStringQuote(sourceCode, startIndex);\n let index = startIndex + quote.length;\n\n while (index < sourceCode.length) {\n if (sourceCode[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (sourceCode.startsWith(quote, index)) return index + quote.length;\n index += 1;\n }\n\n return index;\n}\n\nfunction skipJavaScriptRegExpLiteral(sourceCode: string, startIndex: number): number {\n let index = startIndex + 1;\n let inCharacterClass = false;\n\n while (index < sourceCode.length) {\n if (sourceCode[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (sourceCode[index] === '[') inCharacterClass = true;\n if (sourceCode[index] === ']') inCharacterClass = false;\n if (sourceCode[index] === '/' && !inCharacterClass) {\n index += 1;\n while (/[A-Za-z]/.test(sourceCode[index] ?? '')) index += 1;\n return index;\n }\n if (sourceCode[index] === '\\n') return startIndex + 1;\n index += 1;\n }\n\n return startIndex + 1;\n}\n\nfunction skipJavaScriptSingleLineComment(sourceCode: string, startIndex: number): number {\n const newLineIndex = sourceCode.indexOf('\\n', startIndex + 2);\n return newLineIndex === -1 ? sourceCode.length : newLineIndex;\n}\n\nfunction skipJavaScriptBlockComment(sourceCode: string, startIndex: number): number {\n const endIndex = sourceCode.indexOf('*/', startIndex + 2);\n return endIndex === -1 ? sourceCode.length : endIndex + 2;\n}\n"],"mappings":"aAKA,SAAgB,EAA2B,EAA4B,EAA4B,CACjG,OAAO,EAA0C,EAAS,EAAY,CAAE,cAAe,EAAM,CAAC,CAChG,CAGA,SAAgB,EAAqC,EAA4B,EAA4B,CAC3G,OAAO,EAA0C,EAAS,EAAY,CAAE,cAAe,EAAK,CAAC,CAC/F,CAeA,SAAS,EACP,EACA,EACA,EACA,EAA0B,EAA+B,CAAO,EACxD,CACR,GAAI,CAAC,EAAQ,UAAU,SAAW,CAAC,EAAQ,eAAiB,CAAC,EAAQ,SAAS,QAAS,OAAO,EAE9F,IAAM,EAAgC,CAAC,EAEnC,EAAY,EAEhB,KAAO,EAAY,EAAW,QAAQ,CACpC,IAAI,EAEJ,IAAK,IAAM,KAA0B,EAAyB,CAC5D,IAAM,EAAc,EAAuB,WAC3C,EAAY,UAAY,EAExB,IAAM,EAAQ,EAAY,KAAK,CAAU,EAErC,GAAS,EAAkB,EAAO,EAAwB,EAAO,CAAO,IAC1E,EAAQ,CAAE,QAAS,EAAwB,OAA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9C,EAAW,KAAW,MAAK,EAAmB,IAC9C,EAAW,KAAW,KAAO,CAAC,EAAkB,CAElD,IADA,GAAS,EACF,WAAW,KAAK,EAAW,IAAU,EAAE,GAAG,GAAS,EAC1D,OAAO,CACT,CACA,GAAI,EAAW,KAAW;EAAM,OAAO,EAAa,EACpD,GAAS,CACX,CAEA,OAAO,EAAa,CACtB,CAEA,SAAS,EAAgC,EAAoB,EAA4B,CACvF,IAAM,EAAe,EAAW,QAAQ;EAAM,EAAa,CAAC,EAC5D,OAAO,IAAiB,GAAK,EAAW,OAAS,CACnD,CAEA,SAAS,EAA2B,EAAoB,EAA4B,CAClF,IAAM,EAAW,EAAW,QAAQ,KAAM,EAAa,CAAC,EACxD,OAAO,IAAa,GAAK,EAAW,OAAS,EAAW,CAC1D"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
function e(e,t){return n(e,t,{removeStrings:!1})}function t(e,t){return n(e,t,{removeStrings:!0})}function n(e,t,n,a=r(e)){if(!e.comments?.length&&(!n.removeStrings||!e.strings?.length))return t;let s=[],c=0;for(;c<t.length;){let r;for(let e of a){let a=e.openRegExp;a.lastIndex=c;let o=a.exec(t);o&&i(o,e,r,n)&&(r={grammar:e,match:o})}if(r){let i=r.match.index;if(!r.grammar.isComment&&n.removeStrings&&(i=
|
|
2
|
-
`)}function h(e,t
|
|
3
|
-
`)}function
|
|
4
|
-
`)
|
|
5
|
-
|
|
1
|
+
function e(e,t){return n(e,t,{removeStrings:!1})}function t(e,t){return n(e,t,{removeStrings:!0})}function n(e,t,n,a=r(e)){if(!e.comments?.length&&(!n.removeStrings||!e.strings?.length))return t;let s=[],c=0;for(;c<t.length;){let r;for(let e of a){let a=e.openRegExp;a.lastIndex=c;let o=a.exec(t);o&&i(o,e,r,n)&&(r={grammar:e,match:o})}if(r){let i=r.match.index;if(!r.grammar.isComment&&n.removeStrings&&(i=d(t,r.match.index)),s.push(t.slice(c,i)),r.grammar.isComment){let e=r.grammar.closeRegExp;e.lastIndex=r.match.index+r.match[0].length;let n=e.exec(t);c=n?n.index+n[0].length:t.length}else{c=o(t,r.match.index,r.grammar);let i=t.slice(r.match.index,c);n.removeStrings?s.push(p(e,a,r.grammar,t,r.match.index,i)):s.push(i)}}else s.push(t.slice(c)),c=t.length}return s.join(``)}function r(e){return[...e.comments?.map(e=>({closeRegExp:a(e.close??/(?=\n)/g),isComment:!0,openRegExp:a(e.open)}))??[],...e.strings?.map(e=>({closeRegExp:a(e.close),isComment:!1,openRegExp:a(e.open),templateSyntax:e.templateSyntax}))??[]]}function i(e,t,n,r){return!n||e.index<n.match.index?!0:e.index>n.match.index?!1:r.removeStrings&&n.grammar.isComment&&!t.isComment}function a(e){return new RegExp(e,e.flags.includes(`g`)?e.flags:`${e.flags}g`)}function o(e,t,n){if(n.templateSyntax===`kotlin`)return s(e,t);if(e[t]==="`")return c(e,t);if(_(e,t))return l(e,t);let r=n.closeRegExp;r.lastIndex=t+1;let i=r.exec(e);return i?i.index+i[0].length:e.length}function s(e,t){let n=u(e,t),r=n.length===3,i=t+n.length;for(;i<e.length;){if(e.startsWith(n,i))return i+n.length;if(!r&&e[i]===`\\`){i+=2;continue}if(e[i]===`$`&&e[i+1]===`{`){i=b(e,i+2,`}`,{slashStartsComments:!0,slashStartsRegExp:!1,supportsKotlinStrings:!0}).endIndex+1;continue}i+=1}return e.length}function c(e,t){let n=t+1;for(;n<e.length;){if(e[n]===`\\`){n+=2;continue}if(e[n]==="`")return n+1;if(e[n]===`$`&&e[n+1]===`{`){n=b(e,n+2,`}`,{slashStartsRegExp:!0}).endIndex+1;continue}n+=1}return e.length}function l(e,t){let n=u(e,t),r=t+n.length;for(;r<e.length;){if(e.startsWith(n,r))return r+n.length;if(e[r]===`{`&&e[r+1]===`{`){r+=2;continue}if(e[r]===`{`){r=b(e,r+1,`}`,{slashStartsRegExp:!1}).endIndex+1;continue}r+=e[r]===`\\`?2:1}return e.length}function u(e,t){let n=e.slice(t,t+3);return n===`'''`||n===`"""`?n:e[t]??``}function d(e,t){let n=f(e,t);return n?t-n.length:t}function f(e,t){if(e[t]!==`"`&&e[t]!==`'`)return;let n=t-1;for(;n>=0&&/[A-Za-z]/.test(e[n]??``);)--n;let r=e.slice(n+1,t);if(!(!r||!/^[bfru]+$/i.test(r))&&!(n>=0&&/[\dA-Za-z_]/.test(e[n]??``)))return r}function p(e,t,n,r,i,a){return n.templateSyntax===`kotlin`?m(e,t,a):a.startsWith("`")?v(e,t,a):_(r,i)?y(e,t,a):``}function m(e,t,r){let i=u(r,0).length,a=i===3,o=[],s=i;for(;s<r.length-i;){if(!a&&r[s]===`\\`){s+=2;continue}if(r[s]!==`$`){s+=1;continue}if(r[s+1]===`{`){let i=b(r,s+2,`}`,{slashStartsComments:!0,slashStartsRegExp:!1,supportsKotlinStrings:!0});o.push(n(e,i.content,{removeStrings:!0},t)),s=i.endIndex+1;continue}if(h(r[s+1])){let e=s+2;for(;g(r[e]);)e+=1;o.push(r.slice(s+1,e)),s=e;continue}s+=1}return o.join(`
|
|
2
|
+
`)}function h(e){return e!==void 0&&/[\p{L}_]/u.test(e)}function g(e){return e!==void 0&&/[\p{L}\p{N}_]/u.test(e)}function _(e,t){return f(e,t)?.toLowerCase().includes(`f`)??!1}function v(e,t,r){let i=[],a=1;for(;a<r.length-1;){if(r[a]===`\\`){a+=2;continue}if(r[a]===`$`&&r[a+1]===`{`){let o=b(r,a+2,`}`,{slashStartsRegExp:!0});i.push(n(e,o.content,{removeStrings:!0},t)),a=o.endIndex+1;continue}a+=1}return i.join(`
|
|
3
|
+
`)}function y(e,t,r){let i=u(r,0).length,a=[],o=i;for(;o<r.length-i;){if(r[o]===`{`&&r[o+1]===`{`){o+=2;continue}if(r[o]===`{`){let i=b(r,o+1,`}`,{slashStartsRegExp:!1});a.push(n(e,i.content,{removeStrings:!0},t)),o=i.endIndex+1;continue}o+=r[o]===`\\`?2:1}return a.join(`
|
|
4
|
+
`)}function b(e,t,n,r){let i=1,a=t;for(;a<e.length;){let o=e[a];if(o===`"`&&r.supportsKotlinStrings){a=s(e,a);continue}if(o===`"`||o===`'`||o==="`"){a=x(e,a);continue}if((r.slashStartsComments||r.slashStartsRegExp)&&e[a]===`/`&&e[a+1]===`/`){a=C(e,a);continue}if((r.slashStartsComments||r.slashStartsRegExp)&&e[a]===`/`&&e[a+1]===`*`){a=w(e,a);continue}if(r.slashStartsRegExp&&o===`/`){a=S(e,a);continue}if(o===`{`&&(i+=1),o===n&&(--i,i===0))return{content:e.slice(t,a),endIndex:a};a+=1}return{content:e.slice(t),endIndex:e.length}}function x(e,t){let n=u(e,t),r=t+n.length;for(;r<e.length;){if(e[r]===`\\`){r+=2;continue}if(e.startsWith(n,r))return r+n.length;r+=1}return r}function S(e,t){let n=t+1,r=!1;for(;n<e.length;){if(e[n]===`\\`){n+=2;continue}if(e[n]===`[`&&(r=!0),e[n]===`]`&&(r=!1),e[n]===`/`&&!r){for(n+=1;/[A-Za-z]/.test(e[n]??``);)n+=1;return n}if(e[n]===`
|
|
5
|
+
`)return t+1;n+=1}return t+1}function C(e,t){let n=e.indexOf(`
|
|
6
|
+
`,t+2);return n===-1?e.length:n}function w(e,t){let n=e.indexOf(`*/`,t+2);return n===-1?e.length:n+2}export{t as removeCommentsAndStringsInSourceCode,e as removeCommentsInSourceCode};
|
|
6
7
|
//# sourceMappingURL=removeCommentsInSourceCode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"removeCommentsInSourceCode.js","names":[],"sources":["../../src/helpers/removeCommentsInSourceCode.ts"],"sourcesContent":["import type { LanguageDefinition } from '../types/language.js';\n\nexport type SourceCodeGrammar = NonNullable<LanguageDefinition['grammer']>;\n\n/** Removes comments from source code according to the provided language grammar. */\nexport function removeCommentsInSourceCode(grammar: SourceCodeGrammar, sourceCode: string): string {\n return removeCommentsAndMaybeStringsInSourceCode(grammar, sourceCode, { removeStrings: false });\n}\n\n/** Removes comments and string literal contents while preserving executable interpolation expressions. */\nexport function removeCommentsAndStringsInSourceCode(grammar: SourceCodeGrammar, sourceCode: string): string {\n return removeCommentsAndMaybeStringsInSourceCode(grammar, sourceCode, { removeStrings: true });\n}\n\ninterface CommentOrStringGrammar {\n closeRegExp: RegExp;\n isComment: boolean;\n openRegExp: RegExp;\n}\n\nfunction removeCommentsAndMaybeStringsInSourceCode(\n grammar: SourceCodeGrammar,\n sourceCode: string,\n options: { removeStrings: boolean },\n commentOrStringGrammars = compileCommentOrStringGrammars(grammar)\n): string {\n if (!grammar.comments?.length && (!options.removeStrings || !grammar.strings?.length)) return sourceCode;\n\n const newSourceCodeSlices: string[] = [];\n\n let lastIndex = 0;\n\n while (lastIndex < sourceCode.length) {\n let first: { grammar: CommentOrStringGrammar; match: RegExpExecArray } | undefined;\n\n for (const commentOrStringGrammer of commentOrStringGrammars) {\n const startRegExp = commentOrStringGrammer.openRegExp;\n startRegExp.lastIndex = lastIndex;\n\n const match = startRegExp.exec(sourceCode);\n\n if (match && shouldPreferMatch(match, commentOrStringGrammer, first, options)) {\n first = { grammar: commentOrStringGrammer, match };\n }\n }\n\n if (first) {\n let stringPrefixStartIndex = first.match.index;\n if (!first.grammar.isComment && options.removeStrings) {\n stringPrefixStartIndex = getPythonStringPrefixStartIndex(sourceCode, first.match.index);\n }\n newSourceCodeSlices.push(sourceCode.slice(lastIndex, stringPrefixStartIndex));\n\n if (!first.grammar.isComment) {\n lastIndex = findStringEndIndex(sourceCode, first.match.index, first.grammar);\n const stringLiteral = sourceCode.slice(first.match.index, lastIndex);\n if (options.removeStrings) {\n newSourceCodeSlices.push(\n preserveStringInterpolationExpressions(\n grammar,\n commentOrStringGrammars,\n sourceCode,\n first.match.index,\n stringLiteral\n )\n );\n } else {\n newSourceCodeSlices.push(stringLiteral);\n }\n } else {\n const closeRegExp = first.grammar.closeRegExp;\n closeRegExp.lastIndex = first.match.index + first.match[0].length;\n\n const match = closeRegExp.exec(sourceCode);\n\n lastIndex = match ? match.index + match[0].length : sourceCode.length;\n }\n } else {\n newSourceCodeSlices.push(sourceCode.slice(lastIndex));\n lastIndex = sourceCode.length;\n }\n }\n\n return newSourceCodeSlices.join('');\n}\n\nfunction compileCommentOrStringGrammars(grammar: SourceCodeGrammar): readonly CommentOrStringGrammar[] {\n return [\n ...(grammar.comments?.map((v) => ({\n closeRegExp: makeGlobalRegExp(v.close ?? /(?=\\n)/g),\n isComment: true,\n openRegExp: makeGlobalRegExp(v.open),\n })) ?? []),\n ...(grammar.strings?.map((v) => ({\n closeRegExp: makeGlobalRegExp(v.close),\n isComment: false,\n openRegExp: makeGlobalRegExp(v.open),\n })) ?? []),\n ] satisfies CommentOrStringGrammar[];\n}\n\nfunction shouldPreferMatch(\n match: RegExpExecArray,\n grammar: CommentOrStringGrammar,\n first: { grammar: CommentOrStringGrammar; match: RegExpExecArray } | undefined,\n options: { removeStrings: boolean }\n): boolean {\n if (!first) return true;\n if (match.index < first.match.index) return true;\n if (match.index > first.match.index) return false;\n return options.removeStrings && first.grammar.isComment && !grammar.isComment;\n}\n\nfunction makeGlobalRegExp(regExp: RegExp): RegExp {\n return new RegExp(regExp, regExp.flags.includes('g') ? regExp.flags : `${regExp.flags}g`);\n}\n\nfunction findStringEndIndex(sourceCode: string, stringStartIndex: number, grammar: CommentOrStringGrammar): number {\n if (sourceCode[stringStartIndex] === '`') return findJavaScriptTemplateEndIndex(sourceCode, stringStartIndex);\n if (hasPythonFStringPrefix(sourceCode, stringStartIndex))\n return findPythonFStringEndIndex(sourceCode, stringStartIndex);\n\n const closeRegExp = grammar.closeRegExp;\n closeRegExp.lastIndex = stringStartIndex + 1;\n const match = closeRegExp.exec(sourceCode);\n return match ? match.index + match[0].length : sourceCode.length;\n}\n\nfunction findJavaScriptTemplateEndIndex(sourceCode: string, stringStartIndex: number): number {\n let index = stringStartIndex + 1;\n\n while (index < sourceCode.length) {\n if (sourceCode[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (sourceCode[index] === '`') return index + 1;\n if (sourceCode[index] === '$' && sourceCode[index + 1] === '{') {\n index = readBalancedExpression(sourceCode, index + 2, '}', { slashStartsRegExp: true }).endIndex + 1;\n continue;\n }\n index += 1;\n }\n\n return sourceCode.length;\n}\n\nfunction findPythonFStringEndIndex(sourceCode: string, stringStartIndex: number): number {\n const quote = getStringQuote(sourceCode, stringStartIndex);\n let index = stringStartIndex + quote.length;\n\n while (index < sourceCode.length) {\n if (sourceCode.startsWith(quote, index)) return index + quote.length;\n if (sourceCode[index] === '{' && sourceCode[index + 1] === '{') {\n index += 2;\n continue;\n }\n if (sourceCode[index] === '{') {\n index = readBalancedExpression(sourceCode, index + 1, '}', { slashStartsRegExp: false }).endIndex + 1;\n continue;\n }\n index += sourceCode[index] === '\\\\' ? 2 : 1;\n }\n\n return sourceCode.length;\n}\n\nfunction getStringQuote(sourceCode: string, stringStartIndex: number): string {\n const threeCharacterQuote = sourceCode.slice(stringStartIndex, stringStartIndex + 3);\n if (threeCharacterQuote === \"'''\" || threeCharacterQuote === '\"\"\"') return threeCharacterQuote;\n return sourceCode[stringStartIndex] ?? '';\n}\n\nfunction getPythonStringPrefixStartIndex(sourceCode: string, stringStartIndex: number): number {\n const prefix = getPythonStringPrefix(sourceCode, stringStartIndex);\n return prefix ? stringStartIndex - prefix.length : stringStartIndex;\n}\n\nfunction getPythonStringPrefix(sourceCode: string, stringStartIndex: number): string | undefined {\n if (sourceCode[stringStartIndex] !== '\"' && sourceCode[stringStartIndex] !== \"'\") return undefined;\n let index = stringStartIndex - 1;\n while (index >= 0 && /[A-Za-z]/.test(sourceCode[index] ?? '')) index -= 1;\n\n const prefix = sourceCode.slice(index + 1, stringStartIndex);\n if (!prefix || !/^[bfru]+$/i.test(prefix)) return undefined;\n if (index >= 0 && /[\\dA-Za-z_]/.test(sourceCode[index] ?? '')) return undefined;\n\n return prefix;\n}\n\nfunction preserveStringInterpolationExpressions(\n grammar: SourceCodeGrammar,\n commentOrStringGrammars: readonly CommentOrStringGrammar[],\n sourceCode: string,\n stringStartIndex: number,\n stringLiteral: string\n): string {\n if (stringLiteral.startsWith('`'))\n return preserveJavaScriptTemplateExpressions(grammar, commentOrStringGrammars, stringLiteral);\n if (hasPythonFStringPrefix(sourceCode, stringStartIndex))\n return preservePythonFStringExpressions(grammar, commentOrStringGrammars, stringLiteral);\n return '';\n}\n\nfunction hasPythonFStringPrefix(sourceCode: string, stringStartIndex: number): boolean {\n return getPythonStringPrefix(sourceCode, stringStartIndex)?.toLowerCase().includes('f') ?? false;\n}\n\nfunction preserveJavaScriptTemplateExpressions(\n grammar: SourceCodeGrammar,\n commentOrStringGrammars: readonly CommentOrStringGrammar[],\n stringLiteral: string\n): string {\n const expressions: string[] = [];\n let index = 1;\n\n while (index < stringLiteral.length - 1) {\n if (stringLiteral[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (stringLiteral[index] === '$' && stringLiteral[index + 1] === '{') {\n const expression = readBalancedExpression(stringLiteral, index + 2, '}', { slashStartsRegExp: true });\n expressions.push(\n removeCommentsAndMaybeStringsInSourceCode(\n grammar,\n expression.content,\n { removeStrings: true },\n commentOrStringGrammars\n )\n );\n index = expression.endIndex + 1;\n continue;\n }\n index += 1;\n }\n\n return expressions.join('\\n');\n}\n\nfunction preservePythonFStringExpressions(\n grammar: SourceCodeGrammar,\n commentOrStringGrammars: readonly CommentOrStringGrammar[],\n stringLiteral: string\n): string {\n const quoteLength = getStringQuote(stringLiteral, 0).length;\n const expressions: string[] = [];\n let index = quoteLength;\n\n while (index < stringLiteral.length - quoteLength) {\n if (stringLiteral[index] === '{' && stringLiteral[index + 1] === '{') {\n index += 2;\n continue;\n }\n if (stringLiteral[index] === '{') {\n const expression = readBalancedExpression(stringLiteral, index + 1, '}', { slashStartsRegExp: false });\n expressions.push(\n removeCommentsAndMaybeStringsInSourceCode(\n grammar,\n expression.content,\n { removeStrings: true },\n commentOrStringGrammars\n )\n );\n index = expression.endIndex + 1;\n continue;\n }\n index += stringLiteral[index] === '\\\\' ? 2 : 1;\n }\n\n return expressions.join('\\n');\n}\n\nfunction readBalancedExpression(\n sourceCode: string,\n startIndex: number,\n closeChar: string,\n options: { slashStartsRegExp: boolean }\n): { content: string; endIndex: number } {\n let depth = 1;\n let index = startIndex;\n\n while (index < sourceCode.length) {\n const char = sourceCode[index];\n if (char === '\"' || char === \"'\" || char === '`') {\n index = skipQuotedSpan(sourceCode, index);\n continue;\n }\n if (options.slashStartsRegExp && sourceCode[index] === '/' && sourceCode[index + 1] === '/') {\n index = skipJavaScriptSingleLineComment(sourceCode, index);\n continue;\n }\n if (options.slashStartsRegExp && sourceCode[index] === '/' && sourceCode[index + 1] === '*') {\n index = skipJavaScriptBlockComment(sourceCode, index);\n continue;\n }\n if (options.slashStartsRegExp && char === '/') {\n index = skipJavaScriptRegExpLiteral(sourceCode, index);\n continue;\n }\n if (char === '{') depth += 1;\n if (char === closeChar) {\n depth -= 1;\n if (depth === 0) return { content: sourceCode.slice(startIndex, index), endIndex: index };\n }\n index += 1;\n }\n\n return { content: sourceCode.slice(startIndex), endIndex: sourceCode.length };\n}\n\nfunction skipQuotedSpan(sourceCode: string, startIndex: number): number {\n const quote = getStringQuote(sourceCode, startIndex);\n let index = startIndex + quote.length;\n\n while (index < sourceCode.length) {\n if (sourceCode[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (sourceCode.startsWith(quote, index)) return index + quote.length;\n index += 1;\n }\n\n return index;\n}\n\nfunction skipJavaScriptRegExpLiteral(sourceCode: string, startIndex: number): number {\n let index = startIndex + 1;\n let inCharacterClass = false;\n\n while (index < sourceCode.length) {\n if (sourceCode[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (sourceCode[index] === '[') inCharacterClass = true;\n if (sourceCode[index] === ']') inCharacterClass = false;\n if (sourceCode[index] === '/' && !inCharacterClass) {\n index += 1;\n while (/[A-Za-z]/.test(sourceCode[index] ?? '')) index += 1;\n return index;\n }\n if (sourceCode[index] === '\\n') return startIndex + 1;\n index += 1;\n }\n\n return startIndex + 1;\n}\n\nfunction skipJavaScriptSingleLineComment(sourceCode: string, startIndex: number): number {\n const newLineIndex = sourceCode.indexOf('\\n', startIndex + 2);\n return newLineIndex === -1 ? sourceCode.length : newLineIndex;\n}\n\nfunction skipJavaScriptBlockComment(sourceCode: string, startIndex: number): number {\n const endIndex = sourceCode.indexOf('*/', startIndex + 2);\n return endIndex === -1 ? sourceCode.length : endIndex + 2;\n}\n"],"mappings":"AAKA,SAAgB,EAA2B,EAA4B,EAA4B,CACjG,OAAO,EAA0C,EAAS,EAAY,CAAE,cAAe,EAAM,CAAC,CAChG,CAGA,SAAgB,EAAqC,EAA4B,EAA4B,CAC3G,OAAO,EAA0C,EAAS,EAAY,CAAE,cAAe,EAAK,CAAC,CAC/F,CAQA,SAAS,EACP,EACA,EACA,EACA,EAA0B,EAA+B,CAAO,EACxD,CACR,GAAI,CAAC,EAAQ,UAAU,SAAW,CAAC,EAAQ,eAAiB,CAAC,EAAQ,SAAS,QAAS,OAAO,EAE9F,IAAM,EAAgC,CAAC,EAEnC,EAAY,EAEhB,KAAO,EAAY,EAAW,QAAQ,CACpC,IAAI,EAEJ,IAAK,IAAM,KAA0B,EAAyB,CAC5D,IAAM,EAAc,EAAuB,WAC3C,EAAY,UAAY,EAExB,IAAM,EAAQ,EAAY,KAAK,CAAU,EAErC,GAAS,EAAkB,EAAO,EAAwB,EAAO,CAAO,IAC1E,EAAQ,CAAE,QAAS,EAAwB,OAAM,EAErD,CAEA,GAAI,EAAO,CACT,IAAI,EAAyB,EAAM,MAAM,MAMzC,GALI,CAAC,EAAM,QAAQ,WAAa,EAAQ,gBACtC,EAAyB,EAAgC,EAAY,EAAM,MAAM,KAAK,GAExF,EAAoB,KAAK,EAAW,MAAM,EAAW,CAAsB,CAAC,EAEvE,EAAM,QAAQ,UAgBZ,CACL,IAAM,EAAc,EAAM,QAAQ,YAClC,EAAY,UAAY,EAAM,MAAM,MAAQ,EAAM,MAAM,EAAE,CAAC,OAE3D,IAAM,EAAQ,EAAY,KAAK,CAAU,EAEzC,EAAY,EAAQ,EAAM,MAAQ,EAAM,EAAE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AW,QAAQ,CAChC,GAAI,EAAW,KAAW,KAAM,CAC9B,GAAS,EACT,QACF,CACA,GAAI,EAAW,WAAW,EAAO,CAAK,EAAG,OAAO,EAAQ,EAAM,OAC9D,GAAS,CACX,CAEA,OAAO,CACT,CAEA,SAAS,EAA4B,EAAoB,EAA4B,CACnF,IAAI,EAAQ,EAAa,EACrB,EAAmB,GAEvB,KAAO,EAAQ,EAAW,QAAQ,CAChC,GAAI,EAAW,KAAW,KAAM,CAC9B,GAAS,EACT,QACF,CAGA,GAFI,EAAW,KAAW,MAAK,EAAmB,IAC9C,EAAW,KAAW,MAAK,EAAmB,IAC9C,EAAW,KAAW,KAAO,CAAC,EAAkB,CAElD,IADA,GAAS,EACF,WAAW,KAAK,EAAW,IAAU,EAAE,GAAG,GAAS,EAC1D,OAAO,CACT,CACA,GAAI,EAAW,KAAW;EAAM,OAAO,EAAa,EACpD,GAAS,CACX,CAEA,OAAO,EAAa,CACtB,CAEA,SAAS,EAAgC,EAAoB,EAA4B,CACvF,IAAM,EAAe,EAAW,QAAQ;EAAM,EAAa,CAAC,EAC5D,OAAO,IAAiB,GAAK,EAAW,OAAS,CACnD,CAEA,SAAS,EAA2B,EAAoB,EAA4B,CAClF,IAAM,EAAW,EAAW,QAAQ,KAAM,EAAa,CAAC,EACxD,OAAO,IAAa,GAAK,EAAW,OAAS,EAAW,CAC1D"}
|
|
1
|
+
{"version":3,"file":"removeCommentsInSourceCode.js","names":[],"sources":["../../src/helpers/removeCommentsInSourceCode.ts"],"sourcesContent":["import type { LanguageDefinition } from '../types/language.js';\n\nexport type SourceCodeGrammar = NonNullable<LanguageDefinition['grammer']>;\n\n/** Removes comments from source code according to the provided language grammar. */\nexport function removeCommentsInSourceCode(grammar: SourceCodeGrammar, sourceCode: string): string {\n return removeCommentsAndMaybeStringsInSourceCode(grammar, sourceCode, { removeStrings: false });\n}\n\n/** Removes comments and string literal contents while preserving executable interpolation expressions. */\nexport function removeCommentsAndStringsInSourceCode(grammar: SourceCodeGrammar, sourceCode: string): string {\n return removeCommentsAndMaybeStringsInSourceCode(grammar, sourceCode, { removeStrings: true });\n}\n\ninterface CommentOrStringGrammar {\n closeRegExp: RegExp;\n isComment: boolean;\n openRegExp: RegExp;\n templateSyntax?: 'kotlin';\n}\n\ninterface BalancedExpressionOptions {\n slashStartsComments?: boolean;\n slashStartsRegExp: boolean;\n supportsKotlinStrings?: boolean;\n}\n\nfunction removeCommentsAndMaybeStringsInSourceCode(\n grammar: SourceCodeGrammar,\n sourceCode: string,\n options: { removeStrings: boolean },\n commentOrStringGrammars = compileCommentOrStringGrammars(grammar)\n): string {\n if (!grammar.comments?.length && (!options.removeStrings || !grammar.strings?.length)) return sourceCode;\n\n const newSourceCodeSlices: string[] = [];\n\n let lastIndex = 0;\n\n while (lastIndex < sourceCode.length) {\n let first: { grammar: CommentOrStringGrammar; match: RegExpExecArray } | undefined;\n\n for (const commentOrStringGrammer of commentOrStringGrammars) {\n const startRegExp = commentOrStringGrammer.openRegExp;\n startRegExp.lastIndex = lastIndex;\n\n const match = startRegExp.exec(sourceCode);\n\n if (match && shouldPreferMatch(match, commentOrStringGrammer, first, options)) {\n first = { grammar: commentOrStringGrammer, match };\n }\n }\n\n if (first) {\n let stringPrefixStartIndex = first.match.index;\n if (!first.grammar.isComment && options.removeStrings) {\n stringPrefixStartIndex = getPythonStringPrefixStartIndex(sourceCode, first.match.index);\n }\n newSourceCodeSlices.push(sourceCode.slice(lastIndex, stringPrefixStartIndex));\n\n if (!first.grammar.isComment) {\n lastIndex = findStringEndIndex(sourceCode, first.match.index, first.grammar);\n const stringLiteral = sourceCode.slice(first.match.index, lastIndex);\n if (options.removeStrings) {\n newSourceCodeSlices.push(\n preserveStringInterpolationExpressions(\n grammar,\n commentOrStringGrammars,\n first.grammar,\n sourceCode,\n first.match.index,\n stringLiteral\n )\n );\n } else {\n newSourceCodeSlices.push(stringLiteral);\n }\n } else {\n const closeRegExp = first.grammar.closeRegExp;\n closeRegExp.lastIndex = first.match.index + first.match[0].length;\n\n const match = closeRegExp.exec(sourceCode);\n\n lastIndex = match ? match.index + match[0].length : sourceCode.length;\n }\n } else {\n newSourceCodeSlices.push(sourceCode.slice(lastIndex));\n lastIndex = sourceCode.length;\n }\n }\n\n return newSourceCodeSlices.join('');\n}\n\nfunction compileCommentOrStringGrammars(grammar: SourceCodeGrammar): readonly CommentOrStringGrammar[] {\n return [\n ...(grammar.comments?.map((v) => ({\n closeRegExp: makeGlobalRegExp(v.close ?? /(?=\\n)/g),\n isComment: true,\n openRegExp: makeGlobalRegExp(v.open),\n })) ?? []),\n ...(grammar.strings?.map((v) => ({\n closeRegExp: makeGlobalRegExp(v.close),\n isComment: false,\n openRegExp: makeGlobalRegExp(v.open),\n templateSyntax: v.templateSyntax,\n })) ?? []),\n ] satisfies CommentOrStringGrammar[];\n}\n\nfunction shouldPreferMatch(\n match: RegExpExecArray,\n grammar: CommentOrStringGrammar,\n first: { grammar: CommentOrStringGrammar; match: RegExpExecArray } | undefined,\n options: { removeStrings: boolean }\n): boolean {\n if (!first) return true;\n if (match.index < first.match.index) return true;\n if (match.index > first.match.index) return false;\n return options.removeStrings && first.grammar.isComment && !grammar.isComment;\n}\n\nfunction makeGlobalRegExp(regExp: RegExp): RegExp {\n return new RegExp(regExp, regExp.flags.includes('g') ? regExp.flags : `${regExp.flags}g`);\n}\n\nfunction findStringEndIndex(sourceCode: string, stringStartIndex: number, grammar: CommentOrStringGrammar): number {\n if (grammar.templateSyntax === 'kotlin') return findKotlinStringEndIndex(sourceCode, stringStartIndex);\n if (sourceCode[stringStartIndex] === '`') return findJavaScriptTemplateEndIndex(sourceCode, stringStartIndex);\n if (hasPythonFStringPrefix(sourceCode, stringStartIndex))\n return findPythonFStringEndIndex(sourceCode, stringStartIndex);\n\n const closeRegExp = grammar.closeRegExp;\n closeRegExp.lastIndex = stringStartIndex + 1;\n const match = closeRegExp.exec(sourceCode);\n return match ? match.index + match[0].length : sourceCode.length;\n}\n\nfunction findKotlinStringEndIndex(sourceCode: string, stringStartIndex: number): number {\n const quote = getStringQuote(sourceCode, stringStartIndex);\n const isRawString = quote.length === 3;\n let index = stringStartIndex + quote.length;\n\n while (index < sourceCode.length) {\n if (sourceCode.startsWith(quote, index)) return index + quote.length;\n if (!isRawString && sourceCode[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (sourceCode[index] === '$' && sourceCode[index + 1] === '{') {\n index =\n readBalancedExpression(sourceCode, index + 2, '}', {\n slashStartsComments: true,\n slashStartsRegExp: false,\n supportsKotlinStrings: true,\n }).endIndex + 1;\n continue;\n }\n index += 1;\n }\n\n return sourceCode.length;\n}\n\nfunction findJavaScriptTemplateEndIndex(sourceCode: string, stringStartIndex: number): number {\n let index = stringStartIndex + 1;\n\n while (index < sourceCode.length) {\n if (sourceCode[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (sourceCode[index] === '`') return index + 1;\n if (sourceCode[index] === '$' && sourceCode[index + 1] === '{') {\n index = readBalancedExpression(sourceCode, index + 2, '}', { slashStartsRegExp: true }).endIndex + 1;\n continue;\n }\n index += 1;\n }\n\n return sourceCode.length;\n}\n\nfunction findPythonFStringEndIndex(sourceCode: string, stringStartIndex: number): number {\n const quote = getStringQuote(sourceCode, stringStartIndex);\n let index = stringStartIndex + quote.length;\n\n while (index < sourceCode.length) {\n if (sourceCode.startsWith(quote, index)) return index + quote.length;\n if (sourceCode[index] === '{' && sourceCode[index + 1] === '{') {\n index += 2;\n continue;\n }\n if (sourceCode[index] === '{') {\n index = readBalancedExpression(sourceCode, index + 1, '}', { slashStartsRegExp: false }).endIndex + 1;\n continue;\n }\n index += sourceCode[index] === '\\\\' ? 2 : 1;\n }\n\n return sourceCode.length;\n}\n\nfunction getStringQuote(sourceCode: string, stringStartIndex: number): string {\n const threeCharacterQuote = sourceCode.slice(stringStartIndex, stringStartIndex + 3);\n if (threeCharacterQuote === \"'''\" || threeCharacterQuote === '\"\"\"') return threeCharacterQuote;\n return sourceCode[stringStartIndex] ?? '';\n}\n\nfunction getPythonStringPrefixStartIndex(sourceCode: string, stringStartIndex: number): number {\n const prefix = getPythonStringPrefix(sourceCode, stringStartIndex);\n return prefix ? stringStartIndex - prefix.length : stringStartIndex;\n}\n\nfunction getPythonStringPrefix(sourceCode: string, stringStartIndex: number): string | undefined {\n if (sourceCode[stringStartIndex] !== '\"' && sourceCode[stringStartIndex] !== \"'\") return undefined;\n let index = stringStartIndex - 1;\n while (index >= 0 && /[A-Za-z]/.test(sourceCode[index] ?? '')) index -= 1;\n\n const prefix = sourceCode.slice(index + 1, stringStartIndex);\n if (!prefix || !/^[bfru]+$/i.test(prefix)) return undefined;\n if (index >= 0 && /[\\dA-Za-z_]/.test(sourceCode[index] ?? '')) return undefined;\n\n return prefix;\n}\n\nfunction preserveStringInterpolationExpressions(\n grammar: SourceCodeGrammar,\n commentOrStringGrammars: readonly CommentOrStringGrammar[],\n stringGrammar: CommentOrStringGrammar,\n sourceCode: string,\n stringStartIndex: number,\n stringLiteral: string\n): string {\n if (stringGrammar.templateSyntax === 'kotlin')\n return preserveKotlinStringTemplateExpressions(grammar, commentOrStringGrammars, stringLiteral);\n if (stringLiteral.startsWith('`'))\n return preserveJavaScriptTemplateExpressions(grammar, commentOrStringGrammars, stringLiteral);\n if (hasPythonFStringPrefix(sourceCode, stringStartIndex))\n return preservePythonFStringExpressions(grammar, commentOrStringGrammars, stringLiteral);\n return '';\n}\n\nfunction preserveKotlinStringTemplateExpressions(\n grammar: SourceCodeGrammar,\n commentOrStringGrammars: readonly CommentOrStringGrammar[],\n stringLiteral: string\n): string {\n const quoteLength = getStringQuote(stringLiteral, 0).length;\n const isRawString = quoteLength === 3;\n const expressions: string[] = [];\n let index = quoteLength;\n\n while (index < stringLiteral.length - quoteLength) {\n if (!isRawString && stringLiteral[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (stringLiteral[index] !== '$') {\n index += 1;\n continue;\n }\n if (stringLiteral[index + 1] === '{') {\n const expression = readBalancedExpression(stringLiteral, index + 2, '}', {\n slashStartsComments: true,\n slashStartsRegExp: false,\n supportsKotlinStrings: true,\n });\n expressions.push(\n removeCommentsAndMaybeStringsInSourceCode(\n grammar,\n expression.content,\n { removeStrings: true },\n commentOrStringGrammars\n )\n );\n index = expression.endIndex + 1;\n continue;\n }\n if (isKotlinIdentifierStart(stringLiteral[index + 1])) {\n let endIndex = index + 2;\n while (isKotlinIdentifierPart(stringLiteral[endIndex])) endIndex += 1;\n expressions.push(stringLiteral.slice(index + 1, endIndex));\n index = endIndex;\n continue;\n }\n index += 1;\n }\n\n return expressions.join('\\n');\n}\n\nfunction isKotlinIdentifierStart(character: string | undefined): boolean {\n return character !== undefined && /[\\p{L}_]/u.test(character);\n}\n\nfunction isKotlinIdentifierPart(character: string | undefined): boolean {\n return character !== undefined && /[\\p{L}\\p{N}_]/u.test(character);\n}\n\nfunction hasPythonFStringPrefix(sourceCode: string, stringStartIndex: number): boolean {\n return getPythonStringPrefix(sourceCode, stringStartIndex)?.toLowerCase().includes('f') ?? false;\n}\n\nfunction preserveJavaScriptTemplateExpressions(\n grammar: SourceCodeGrammar,\n commentOrStringGrammars: readonly CommentOrStringGrammar[],\n stringLiteral: string\n): string {\n const expressions: string[] = [];\n let index = 1;\n\n while (index < stringLiteral.length - 1) {\n if (stringLiteral[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (stringLiteral[index] === '$' && stringLiteral[index + 1] === '{') {\n const expression = readBalancedExpression(stringLiteral, index + 2, '}', { slashStartsRegExp: true });\n expressions.push(\n removeCommentsAndMaybeStringsInSourceCode(\n grammar,\n expression.content,\n { removeStrings: true },\n commentOrStringGrammars\n )\n );\n index = expression.endIndex + 1;\n continue;\n }\n index += 1;\n }\n\n return expressions.join('\\n');\n}\n\nfunction preservePythonFStringExpressions(\n grammar: SourceCodeGrammar,\n commentOrStringGrammars: readonly CommentOrStringGrammar[],\n stringLiteral: string\n): string {\n const quoteLength = getStringQuote(stringLiteral, 0).length;\n const expressions: string[] = [];\n let index = quoteLength;\n\n while (index < stringLiteral.length - quoteLength) {\n if (stringLiteral[index] === '{' && stringLiteral[index + 1] === '{') {\n index += 2;\n continue;\n }\n if (stringLiteral[index] === '{') {\n const expression = readBalancedExpression(stringLiteral, index + 1, '}', { slashStartsRegExp: false });\n expressions.push(\n removeCommentsAndMaybeStringsInSourceCode(\n grammar,\n expression.content,\n { removeStrings: true },\n commentOrStringGrammars\n )\n );\n index = expression.endIndex + 1;\n continue;\n }\n index += stringLiteral[index] === '\\\\' ? 2 : 1;\n }\n\n return expressions.join('\\n');\n}\n\nfunction readBalancedExpression(\n sourceCode: string,\n startIndex: number,\n closeChar: string,\n options: BalancedExpressionOptions\n): { content: string; endIndex: number } {\n let depth = 1;\n let index = startIndex;\n\n while (index < sourceCode.length) {\n const char = sourceCode[index];\n if (char === '\"' && options.supportsKotlinStrings) {\n index = findKotlinStringEndIndex(sourceCode, index);\n continue;\n }\n if (char === '\"' || char === \"'\" || char === '`') {\n index = skipQuotedSpan(sourceCode, index);\n continue;\n }\n if (\n (options.slashStartsComments || options.slashStartsRegExp) &&\n sourceCode[index] === '/' &&\n sourceCode[index + 1] === '/'\n ) {\n index = skipJavaScriptSingleLineComment(sourceCode, index);\n continue;\n }\n if (\n (options.slashStartsComments || options.slashStartsRegExp) &&\n sourceCode[index] === '/' &&\n sourceCode[index + 1] === '*'\n ) {\n index = skipJavaScriptBlockComment(sourceCode, index);\n continue;\n }\n if (options.slashStartsRegExp && char === '/') {\n index = skipJavaScriptRegExpLiteral(sourceCode, index);\n continue;\n }\n if (char === '{') depth += 1;\n if (char === closeChar) {\n depth -= 1;\n if (depth === 0) return { content: sourceCode.slice(startIndex, index), endIndex: index };\n }\n index += 1;\n }\n\n return { content: sourceCode.slice(startIndex), endIndex: sourceCode.length };\n}\n\nfunction skipQuotedSpan(sourceCode: string, startIndex: number): number {\n const quote = getStringQuote(sourceCode, startIndex);\n let index = startIndex + quote.length;\n\n while (index < sourceCode.length) {\n if (sourceCode[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (sourceCode.startsWith(quote, index)) return index + quote.length;\n index += 1;\n }\n\n return index;\n}\n\nfunction skipJavaScriptRegExpLiteral(sourceCode: string, startIndex: number): number {\n let index = startIndex + 1;\n let inCharacterClass = false;\n\n while (index < sourceCode.length) {\n if (sourceCode[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (sourceCode[index] === '[') inCharacterClass = true;\n if (sourceCode[index] === ']') inCharacterClass = false;\n if (sourceCode[index] === '/' && !inCharacterClass) {\n index += 1;\n while (/[A-Za-z]/.test(sourceCode[index] ?? '')) index += 1;\n return index;\n }\n if (sourceCode[index] === '\\n') return startIndex + 1;\n index += 1;\n }\n\n return startIndex + 1;\n}\n\nfunction skipJavaScriptSingleLineComment(sourceCode: string, startIndex: number): number {\n const newLineIndex = sourceCode.indexOf('\\n', startIndex + 2);\n return newLineIndex === -1 ? sourceCode.length : newLineIndex;\n}\n\nfunction skipJavaScriptBlockComment(sourceCode: string, startIndex: number): number {\n const endIndex = sourceCode.indexOf('*/', startIndex + 2);\n return endIndex === -1 ? sourceCode.length : endIndex + 2;\n}\n"],"mappings":"AAKA,SAAgB,EAA2B,EAA4B,EAA4B,CACjG,OAAO,EAA0C,EAAS,EAAY,CAAE,cAAe,EAAM,CAAC,CAChG,CAGA,SAAgB,EAAqC,EAA4B,EAA4B,CAC3G,OAAO,EAA0C,EAAS,EAAY,CAAE,cAAe,EAAK,CAAC,CAC/F,CAeA,SAAS,EACP,EACA,EACA,EACA,EAA0B,EAA+B,CAAO,EACxD,CACR,GAAI,CAAC,EAAQ,UAAU,SAAW,CAAC,EAAQ,eAAiB,CAAC,EAAQ,SAAS,QAAS,OAAO,EAE9F,IAAM,EAAgC,CAAC,EAEnC,EAAY,EAEhB,KAAO,EAAY,EAAW,QAAQ,CACpC,IAAI,EAEJ,IAAK,IAAM,KAA0B,EAAyB,CAC5D,IAAM,EAAc,EAAuB,WAC3C,EAAY,UAAY,EAExB,IAAM,EAAQ,EAAY,KAAK,CAAU,EAErC,G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AAW,KAAM,CAC9B,GAAS,EACT,QACF,CAGA,GAFI,EAAW,KAAW,MAAK,EAAmB,IAC9C,EAAW,KAAW,MAAK,EAAmB,IAC9C,EAAW,KAAW,KAAO,CAAC,EAAkB,CAElD,IADA,GAAS,EACF,WAAW,KAAK,EAAW,IAAU,EAAE,GAAG,GAAS,EAC1D,OAAO,CACT,CACA,GAAI,EAAW,KAAW;EAAM,OAAO,EAAa,EACpD,GAAS,CACX,CAEA,OAAO,EAAa,CACtB,CAEA,SAAS,EAAgC,EAAoB,EAA4B,CACvF,IAAM,EAAe,EAAW,QAAQ;EAAM,EAAa,CAAC,EAC5D,OAAO,IAAiB,GAAK,EAAW,OAAS,CACnD,CAEA,SAAS,EAA2B,EAAoB,EAA4B,CAClF,IAAM,EAAW,EAAW,QAAQ,KAAM,EAAa,CAAC,EACxD,OAAO,IAAa,GAAK,EAAW,OAAS,EAAW,CAC1D"}
|
package/dist/types/language.cjs
CHANGED
|
@@ -7,5 +7,5 @@
|
|
|
7
7
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
|
8
8
|
<AssemblyName>Main</AssemblyName>
|
|
9
9
|
</PropertyGroup>
|
|
10
|
-
</Project>`)},buildCommand:()=>[`dotnet`,`build`,`Main.csproj`,`--configuration`,`Release`,`--verbosity`,`quiet`],command:()=>[`dotnet`,`bin/Release/net8.0/Main.dll`],grammer:a},css:{fileExtensions:[`.css`],command:()=>[`echo`,``],grammer:{strings:[{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*\/\*/,close:/\*\//}]}},dart:{fileExtensions:[`.dart`],buildCommand:e=>[`dart`,`compile`,`exe`,e,`-o`,`main`],command:()=>[`./main`],grammer:a},java:{fileExtensions:[`.java`],prebuild:async e=>{let n=/\bpublic\s+class\s+(\w+)\b/;for(let o of await i.default.promises.readdir(e,{withFileTypes:!0})){if(!o.isFile()||!o.name.endsWith(`.java`))continue;let s=await i.default.promises.readFile(r.default.join(e,o.name),`utf8`),[,c]=n.exec(t.removeCommentsInSourceCode(a,s))??[];c&&await i.default.promises.rename(r.default.join(e,o.name),r.default.join(e,`${c}.java`))}},buildCommand:e=>[`javac`,e],command:e=>[`java`,`-Xmx1024m`,e.replace(/\.java$/,``)],grammer:a},javascript:{fileExtensions:[`.js`,`.cjs`,`.mjs`],command:e=>[`bun`,e],grammer:o},jsp:{fileExtensions:[`.jsp`],command:()=>[`echo`,``],grammer:{strings:[{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*<!--/,close:/-->/},{open:/\n?[ \t]*<%--/,close:/--%>/},{open:/\n?[ \t]*\/\*/,close:/\*\//},{open:/\n?[ \t]*\/\//}]}},haskell:{fileExtensions:[`.hs`],buildCommand:e=>[`ghc`,`-o`,`main`,e],command:()=>[`./main`],grammer:{strings:[{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*\{-/,close:/-\}/},{open:/\n?[ \t]*--/}]}},html:{fileExtensions:[`.html`],command:()=>[`echo`,``],grammer:{strings:[{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*<!--/,close:/-->/}]}},php:{fileExtensions:[`.php`],command:e=>[`php`,e],grammer:{strings:[{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*\/\*/,close:/\*\//},{open:/\n?[ \t]*\/\//},{open:/\n?[ \t]*#/}]}},python:{fileExtensions:[`.py`],command:e=>[`python3`,e],grammer:{strings:[{open:/'''/,close:/(?<!\\)(?:\\{2})*'''/},{open:/"""/,close:/(?<!\\)(?:\\{2})*"""/},{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*'''/,close:/'''/},{open:/\n?[ \t]*"""/,close:/"""/},{open:/\n?[ \t]*#/}]}},ruby:{fileExtensions:[`.rb`],buildCommand:e=>[`ruby`,`-c`,e],command:e=>[`ruby`,`--jit`,e],grammer:{strings:[{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*=begin/,close:/=end/},{open:/\n?[ \t]*#/}]}},rust:{fileExtensions:[`.rs`],buildCommand:e=>[`rustc`,e,`-o`,`main`],command:()=>[`./main`],grammer:a},zig:{fileExtensions:[`.zig`],buildCommand:e=>[`zig`,`build-exe`,e],command:e=>[`./`+e.replace(/\.zig$/,``)],grammer:a},typescript:{fileExtensions:[`.ts`,`.cts`,`.mts`],command:e=>[`bun`,e],grammer:o},text:{fileExtensions:[`.txt`],command:e=>[`cat`,e]}};exports.languageIdToDefinition=s;
|
|
10
|
+
</Project>`)},buildCommand:()=>[`dotnet`,`build`,`Main.csproj`,`--configuration`,`Release`,`--verbosity`,`quiet`],command:()=>[`dotnet`,`bin/Release/net8.0/Main.dll`],grammer:a},css:{fileExtensions:[`.css`],command:()=>[`echo`,``],grammer:{strings:[{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*\/\*/,close:/\*\//}]}},dart:{fileExtensions:[`.dart`],buildCommand:e=>[`dart`,`compile`,`exe`,e,`-o`,`main`],command:()=>[`./main`],grammer:a},java:{fileExtensions:[`.java`],prebuild:async e=>{let n=/\bpublic\s+class\s+(\w+)\b/;for(let o of await i.default.promises.readdir(e,{withFileTypes:!0})){if(!o.isFile()||!o.name.endsWith(`.java`))continue;let s=await i.default.promises.readFile(r.default.join(e,o.name),`utf8`),[,c]=n.exec(t.removeCommentsInSourceCode(a,s))??[];c&&await i.default.promises.rename(r.default.join(e,o.name),r.default.join(e,`${c}.java`))}},buildCommand:e=>[`javac`,e],command:e=>[`java`,`-Xmx1024m`,e.replace(/\.java$/,``)],grammer:a},kotlin:{fileExtensions:[`.kt`],buildCommand:e=>[`kotlinc`,e,`-include-runtime`,`-d`,`main.jar`],command:()=>[`java`,`-Xmx1024m`,`-jar`,`main.jar`],grammer:{strings:[{open:/"""/,close:/"""/,templateSyntax:`kotlin`},{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/,templateSyntax:`kotlin`}],comments:a.comments}},javascript:{fileExtensions:[`.js`,`.cjs`,`.mjs`],command:e=>[`bun`,e],grammer:o},jsp:{fileExtensions:[`.jsp`],command:()=>[`echo`,``],grammer:{strings:[{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*<!--/,close:/-->/},{open:/\n?[ \t]*<%--/,close:/--%>/},{open:/\n?[ \t]*\/\*/,close:/\*\//},{open:/\n?[ \t]*\/\//}]}},haskell:{fileExtensions:[`.hs`],buildCommand:e=>[`ghc`,`-o`,`main`,e],command:()=>[`./main`],grammer:{strings:[{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*\{-/,close:/-\}/},{open:/\n?[ \t]*--/}]}},html:{fileExtensions:[`.html`],command:()=>[`echo`,``],grammer:{strings:[{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*<!--/,close:/-->/}]}},php:{fileExtensions:[`.php`],command:e=>[`php`,e],grammer:{strings:[{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*\/\*/,close:/\*\//},{open:/\n?[ \t]*\/\//},{open:/\n?[ \t]*#/}]}},python:{fileExtensions:[`.py`],command:e=>[`python3`,e],grammer:{strings:[{open:/'''/,close:/(?<!\\)(?:\\{2})*'''/},{open:/"""/,close:/(?<!\\)(?:\\{2})*"""/},{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*'''/,close:/'''/},{open:/\n?[ \t]*"""/,close:/"""/},{open:/\n?[ \t]*#/}]}},ruby:{fileExtensions:[`.rb`],buildCommand:e=>[`ruby`,`-c`,e],command:e=>[`ruby`,`--jit`,e],grammer:{strings:[{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*=begin/,close:/=end/},{open:/\n?[ \t]*#/}]}},rust:{fileExtensions:[`.rs`],buildCommand:e=>[`rustc`,e,`-o`,`main`],command:()=>[`./main`],grammer:a},zig:{fileExtensions:[`.zig`],buildCommand:e=>[`zig`,`build-exe`,e],command:e=>[`./`+e.replace(/\.zig$/,``)],grammer:a},typescript:{fileExtensions:[`.ts`,`.cts`,`.mts`],command:e=>[`bun`,e],grammer:o},text:{fileExtensions:[`.txt`],command:e=>[`cat`,e]}};exports.languageIdToDefinition=s;
|
|
11
11
|
//# sourceMappingURL=language.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"language.cjs","names":["writeFileWithoutFollowingSymlinks","path","fs","removeCommentsInSourceCode"],"sources":["../../src/types/language.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport { removeCommentsInSourceCode } from '../helpers/removeCommentsInSourceCode.js';\nimport { writeFileWithoutFollowingSymlinks } from '../helpers/safeFs.js';\n\nexport interface LanguageDefinition {\n /** File extensions to judge with this config. */\n fileExtensions: readonly string[];\n\n /** Function executed before the build. */\n prebuild?(cwd: string): Promise<void>;\n\n /** Returns the command to build a user program. */\n buildCommand?(filePath: string): [string, ...string[]];\n\n /** Returns the command to run a user program. */\n command(filePath: string): [string, ...string[]];\n\n /** Grammer definition for static analysis. */\n grammer?: {\n strings?: readonly { open: RegExp; close: RegExp }[];\n comments?: readonly { open: RegExp; close?: RegExp }[];\n };\n}\n\nconst cLikeGrammer = {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [{ open: /\\n?[ \\t]*\\/\\*/, close: /\\*\\// }, { open: /\\n?[ \\t]*\\/\\// }],\n} as const satisfies LanguageDefinition['grammer'];\n\nconst javaScriptLikeGrammer = {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n { open: /`/, close: /(?<!\\\\)(?:\\\\{2})*`/ },\n ],\n comments: [{ open: /\\n?[ \\t]*\\/\\*/, close: /\\*\\// }, { open: /\\n?[ \\t]*\\/\\// }],\n} as const satisfies LanguageDefinition['grammer'];\n\nexport const languageIdToDefinition: Readonly<Record<string, Readonly<LanguageDefinition>>> = {\n c: {\n fileExtensions: ['.c'],\n buildCommand: (filePath) => ['gcc', '--std=c17', '-O2', filePath, '-o', 'main'],\n command: () => ['./main'],\n grammer: cLikeGrammer,\n },\n\n cpp: {\n fileExtensions: ['.cpp'],\n buildCommand: (filePath) => ['g++', '--std=c++20', '-O2', filePath, '-o', 'main'],\n command: () => ['./main'],\n grammer: cLikeGrammer,\n },\n\n csharp: {\n fileExtensions: ['.cs'],\n prebuild: async (cwd) => {\n // No-follow write: the submission owns `cwd` and could point `Main.csproj` at a file only the\n // trusted harness user can write.\n await writeFileWithoutFollowingSymlinks(\n path.join(cwd, 'Main.csproj'),\n `<Project Sdk=\"Microsoft.NET.Sdk\">\n <PropertyGroup>\n <OutputType>Exe</OutputType>\n <TargetFramework>net8.0</TargetFramework>\n <ImplicitUsings>enable</ImplicitUsings>\n <Nullable>enable</Nullable>\n <AllowUnsafeBlocks>true</AllowUnsafeBlocks>\n <AssemblyName>Main</AssemblyName>\n </PropertyGroup>\n</Project>`\n );\n },\n buildCommand: () => ['dotnet', 'build', 'Main.csproj', '--configuration', 'Release', '--verbosity', 'quiet'],\n command: () => ['dotnet', 'bin/Release/net8.0/Main.dll'],\n grammer: cLikeGrammer,\n },\n\n css: {\n fileExtensions: ['.css'],\n command: () => ['echo', ''],\n grammer: {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [{ open: /\\n?[ \\t]*\\/\\*/, close: /\\*\\// }],\n },\n },\n\n dart: {\n fileExtensions: ['.dart'],\n buildCommand: (filePath) => ['dart', 'compile', 'exe', filePath, '-o', 'main'],\n command: () => ['./main'],\n grammer: cLikeGrammer,\n },\n\n java: {\n fileExtensions: ['.java'],\n prebuild: async (cwd) => {\n const publicClassRegex = /\\bpublic\\s+class\\s+(\\w+)\\b/;\n for (const dirent of await fs.promises.readdir(cwd, { withFileTypes: true })) {\n if (!dirent.isFile() || !dirent.name.endsWith('.java')) continue;\n const data = await fs.promises.readFile(path.join(cwd, dirent.name), 'utf8');\n const [, className] = publicClassRegex.exec(removeCommentsInSourceCode(cLikeGrammer, data)) ?? [];\n if (className) await fs.promises.rename(path.join(cwd, dirent.name), path.join(cwd, `${className}.java`));\n }\n },\n buildCommand: (fileName) => ['javac', fileName],\n // For example, Problem 7-3 in WillBooster's Java lecture uses at least 256MB.\n command: (fileName) => ['java', '-Xmx1024m', fileName.replace(/\\.java$/, '')],\n grammer: cLikeGrammer,\n },\n\n javascript: {\n fileExtensions: ['.js', '.cjs', '.mjs'],\n command: (fileName) => ['bun', fileName],\n grammer: javaScriptLikeGrammer,\n },\n\n jsp: {\n fileExtensions: ['.jsp'],\n command: () => ['echo', ''],\n grammer: {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [\n { open: /\\n?[ \\t]*<!--/, close: /-->/ },\n { open: /\\n?[ \\t]*<%--/, close: /--%>/ },\n { open: /\\n?[ \\t]*\\/\\*/, close: /\\*\\// },\n { open: /\\n?[ \\t]*\\/\\// },\n ],\n },\n },\n\n haskell: {\n fileExtensions: ['.hs'],\n buildCommand: (filePath) => ['ghc', '-o', 'main', filePath],\n command: () => ['./main'],\n grammer: {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [{ open: /\\n?[ \\t]*\\{-/, close: /-\\}/ }, { open: /\\n?[ \\t]*--/ }],\n },\n },\n\n html: {\n fileExtensions: ['.html'],\n command: () => ['echo', ''],\n grammer: {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [{ open: /\\n?[ \\t]*<!--/, close: /-->/ }],\n },\n },\n\n php: {\n fileExtensions: ['.php'],\n command: (fileName) => ['php', fileName],\n grammer: {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [{ open: /\\n?[ \\t]*\\/\\*/, close: /\\*\\// }, { open: /\\n?[ \\t]*\\/\\// }, { open: /\\n?[ \\t]*#/ }],\n },\n },\n\n python: {\n fileExtensions: ['.py'],\n command: (fileName) => ['python3', fileName],\n grammer: {\n strings: [\n { open: /'''/, close: /(?<!\\\\)(?:\\\\{2})*'''/ },\n { open: /\"\"\"/, close: /(?<!\\\\)(?:\\\\{2})*\"\"\"/ },\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [\n { open: /\\n?[ \\t]*'''/, close: /'''/ },\n { open: /\\n?[ \\t]*\"\"\"/, close: /\"\"\"/ },\n { open: /\\n?[ \\t]*#/ },\n ],\n },\n },\n\n ruby: {\n fileExtensions: ['.rb'],\n buildCommand: (fileName) => ['ruby', '-c', fileName],\n command: (fileName) => ['ruby', '--jit', fileName],\n grammer: {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [{ open: /\\n?[ \\t]*=begin/, close: /=end/ }, { open: /\\n?[ \\t]*#/ }],\n },\n },\n\n rust: {\n fileExtensions: ['.rs'],\n buildCommand: (filePath) => ['rustc', filePath, '-o', 'main'],\n command: () => ['./main'],\n grammer: cLikeGrammer,\n },\n\n zig: {\n fileExtensions: ['.zig'],\n buildCommand: (filePath) => ['zig', 'build-exe', filePath],\n command: (filePath) => ['./' + filePath.replace(/\\.zig$/, '')],\n grammer: cLikeGrammer,\n },\n\n typescript: {\n fileExtensions: ['.ts', '.cts', '.mts'],\n command: (fileName) => ['bun', fileName],\n grammer: javaScriptLikeGrammer,\n },\n\n text: {\n fileExtensions: ['.txt'],\n command: (fileName) => ['cat', fileName],\n },\n} as const;\n"],"mappings":"kPA0BA,MAAM,EAAe,CACnB,QAAS,CACP,CAAE,KAAM,IAAK,MAAO,oBAAqB,EACzC,CAAE,KAAM,IAAK,MAAO,oBAAqB,CAC3C,EACA,SAAU,CAAC,CAAE,KAAM,gBAAiB,MAAO,MAAO,EAAG,CAAE,KAAM,eAAgB,CAAC,CAChF,EAEM,EAAwB,CAC5B,QAAS,CACP,CAAE,KAAM,IAAK,MAAO,oBAAqB,EACzC,CAAE,KAAM,IAAK,MAAO,oBAAqB,EACzC,CAAE,KAAM,IAAK,MAAO,oBAAqB,CAC3C,EACA,SAAU,CAAC,CAAE,KAAM,gBAAiB,MAAO,MAAO,EAAG,CAAE,KAAM,eAAgB,CAAC,CAChF,EAEa,EAAiF,CAC5F,EAAG,CACD,eAAgB,CAAC,IAAI,EACrB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AQ,EACxB,QAAS,CACX,EAEA,IAAK,CACH,eAAgB,CAAC,MAAM,EACvB,aAAe,GAAa,CAAC,MAAO,YAAa,CAAQ,EACzD,QAAU,GAAa,CAAC,KAAO,EAAS,QAAQ,SAAU,EAAE,CAAC,EAC7D,QAAS,CACX,EAEA,WAAY,CACV,eAAgB,CAAC,MAAO,OAAQ,MAAM,EACtC,QAAU,GAAa,CAAC,MAAO,CAAQ,EACvC,QAAS,CACX,EAEA,KAAM,CACJ,eAAgB,CAAC,MAAM,EACvB,QAAU,GAAa,CAAC,MAAO,CAAQ,CACzC,CACF"}
|
|
1
|
+
{"version":3,"file":"language.cjs","names":["writeFileWithoutFollowingSymlinks","path","fs","removeCommentsInSourceCode"],"sources":["../../src/types/language.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport { removeCommentsInSourceCode } from '../helpers/removeCommentsInSourceCode.js';\nimport { writeFileWithoutFollowingSymlinks } from '../helpers/safeFs.js';\n\nexport interface LanguageDefinition {\n /** File extensions to judge with this config. */\n fileExtensions: readonly string[];\n\n /** Function executed before the build. */\n prebuild?(cwd: string): Promise<void>;\n\n /** Returns the command to build a user program. */\n buildCommand?(filePath: string): [string, ...string[]];\n\n /** Returns the command to run a user program. */\n command(filePath: string): [string, ...string[]];\n\n /** Grammer definition for static analysis. */\n grammer?: {\n strings?: readonly { open: RegExp; close: RegExp; templateSyntax?: 'kotlin' }[];\n comments?: readonly { open: RegExp; close?: RegExp }[];\n };\n}\n\nconst cLikeGrammer = {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [{ open: /\\n?[ \\t]*\\/\\*/, close: /\\*\\// }, { open: /\\n?[ \\t]*\\/\\// }],\n} as const satisfies LanguageDefinition['grammer'];\n\nconst javaScriptLikeGrammer = {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n { open: /`/, close: /(?<!\\\\)(?:\\\\{2})*`/ },\n ],\n comments: [{ open: /\\n?[ \\t]*\\/\\*/, close: /\\*\\// }, { open: /\\n?[ \\t]*\\/\\// }],\n} as const satisfies LanguageDefinition['grammer'];\n\nexport const languageIdToDefinition: Readonly<Record<string, Readonly<LanguageDefinition>>> = {\n c: {\n fileExtensions: ['.c'],\n buildCommand: (filePath) => ['gcc', '--std=c17', '-O2', filePath, '-o', 'main'],\n command: () => ['./main'],\n grammer: cLikeGrammer,\n },\n\n cpp: {\n fileExtensions: ['.cpp'],\n buildCommand: (filePath) => ['g++', '--std=c++20', '-O2', filePath, '-o', 'main'],\n command: () => ['./main'],\n grammer: cLikeGrammer,\n },\n\n csharp: {\n fileExtensions: ['.cs'],\n prebuild: async (cwd) => {\n // No-follow write: the submission owns `cwd` and could point `Main.csproj` at a file only the\n // trusted harness user can write.\n await writeFileWithoutFollowingSymlinks(\n path.join(cwd, 'Main.csproj'),\n `<Project Sdk=\"Microsoft.NET.Sdk\">\n <PropertyGroup>\n <OutputType>Exe</OutputType>\n <TargetFramework>net8.0</TargetFramework>\n <ImplicitUsings>enable</ImplicitUsings>\n <Nullable>enable</Nullable>\n <AllowUnsafeBlocks>true</AllowUnsafeBlocks>\n <AssemblyName>Main</AssemblyName>\n </PropertyGroup>\n</Project>`\n );\n },\n buildCommand: () => ['dotnet', 'build', 'Main.csproj', '--configuration', 'Release', '--verbosity', 'quiet'],\n command: () => ['dotnet', 'bin/Release/net8.0/Main.dll'],\n grammer: cLikeGrammer,\n },\n\n css: {\n fileExtensions: ['.css'],\n command: () => ['echo', ''],\n grammer: {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [{ open: /\\n?[ \\t]*\\/\\*/, close: /\\*\\// }],\n },\n },\n\n dart: {\n fileExtensions: ['.dart'],\n buildCommand: (filePath) => ['dart', 'compile', 'exe', filePath, '-o', 'main'],\n command: () => ['./main'],\n grammer: cLikeGrammer,\n },\n\n java: {\n fileExtensions: ['.java'],\n prebuild: async (cwd) => {\n const publicClassRegex = /\\bpublic\\s+class\\s+(\\w+)\\b/;\n for (const dirent of await fs.promises.readdir(cwd, { withFileTypes: true })) {\n if (!dirent.isFile() || !dirent.name.endsWith('.java')) continue;\n const data = await fs.promises.readFile(path.join(cwd, dirent.name), 'utf8');\n const [, className] = publicClassRegex.exec(removeCommentsInSourceCode(cLikeGrammer, data)) ?? [];\n if (className) await fs.promises.rename(path.join(cwd, dirent.name), path.join(cwd, `${className}.java`));\n }\n },\n buildCommand: (fileName) => ['javac', fileName],\n // For example, Problem 7-3 in WillBooster's Java lecture uses at least 256MB.\n command: (fileName) => ['java', '-Xmx1024m', fileName.replace(/\\.java$/, '')],\n grammer: cLikeGrammer,\n },\n\n kotlin: {\n fileExtensions: ['.kt'],\n buildCommand: (filePath) => ['kotlinc', filePath, '-include-runtime', '-d', 'main.jar'],\n command: () => ['java', '-Xmx1024m', '-jar', 'main.jar'],\n grammer: {\n strings: [\n { open: /\"\"\"/, close: /\"\"\"/, templateSyntax: 'kotlin' },\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/, templateSyntax: 'kotlin' },\n ],\n comments: cLikeGrammer.comments,\n },\n },\n\n javascript: {\n fileExtensions: ['.js', '.cjs', '.mjs'],\n command: (fileName) => ['bun', fileName],\n grammer: javaScriptLikeGrammer,\n },\n\n jsp: {\n fileExtensions: ['.jsp'],\n command: () => ['echo', ''],\n grammer: {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [\n { open: /\\n?[ \\t]*<!--/, close: /-->/ },\n { open: /\\n?[ \\t]*<%--/, close: /--%>/ },\n { open: /\\n?[ \\t]*\\/\\*/, close: /\\*\\// },\n { open: /\\n?[ \\t]*\\/\\// },\n ],\n },\n },\n\n haskell: {\n fileExtensions: ['.hs'],\n buildCommand: (filePath) => ['ghc', '-o', 'main', filePath],\n command: () => ['./main'],\n grammer: {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [{ open: /\\n?[ \\t]*\\{-/, close: /-\\}/ }, { open: /\\n?[ \\t]*--/ }],\n },\n },\n\n html: {\n fileExtensions: ['.html'],\n command: () => ['echo', ''],\n grammer: {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [{ open: /\\n?[ \\t]*<!--/, close: /-->/ }],\n },\n },\n\n php: {\n fileExtensions: ['.php'],\n command: (fileName) => ['php', fileName],\n grammer: {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [{ open: /\\n?[ \\t]*\\/\\*/, close: /\\*\\// }, { open: /\\n?[ \\t]*\\/\\// }, { open: /\\n?[ \\t]*#/ }],\n },\n },\n\n python: {\n fileExtensions: ['.py'],\n command: (fileName) => ['python3', fileName],\n grammer: {\n strings: [\n { open: /'''/, close: /(?<!\\\\)(?:\\\\{2})*'''/ },\n { open: /\"\"\"/, close: /(?<!\\\\)(?:\\\\{2})*\"\"\"/ },\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [\n { open: /\\n?[ \\t]*'''/, close: /'''/ },\n { open: /\\n?[ \\t]*\"\"\"/, close: /\"\"\"/ },\n { open: /\\n?[ \\t]*#/ },\n ],\n },\n },\n\n ruby: {\n fileExtensions: ['.rb'],\n buildCommand: (fileName) => ['ruby', '-c', fileName],\n command: (fileName) => ['ruby', '--jit', fileName],\n grammer: {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [{ open: /\\n?[ \\t]*=begin/, close: /=end/ }, { open: /\\n?[ \\t]*#/ }],\n },\n },\n\n rust: {\n fileExtensions: ['.rs'],\n buildCommand: (filePath) => ['rustc', filePath, '-o', 'main'],\n command: () => ['./main'],\n grammer: cLikeGrammer,\n },\n\n zig: {\n fileExtensions: ['.zig'],\n buildCommand: (filePath) => ['zig', 'build-exe', filePath],\n command: (filePath) => ['./' + filePath.replace(/\\.zig$/, '')],\n grammer: cLikeGrammer,\n },\n\n typescript: {\n fileExtensions: ['.ts', '.cts', '.mts'],\n command: (fileName) => ['bun', fileName],\n grammer: javaScriptLikeGrammer,\n },\n\n text: {\n fileExtensions: ['.txt'],\n command: (fileName) => ['cat', fileName],\n },\n} as const;\n"],"mappings":"kPA0BA,MAAM,EAAe,CACnB,QAAS,CACP,CAAE,KAAM,IAAK,MAAO,oBAAqB,EACzC,CAAE,KAAM,IAAK,MAAO,oBAAqB,CAC3C,EACA,SAAU,CAAC,CAAE,KAAM,gBAAiB,MAAO,MAAO,EAAG,CAAE,KAAM,eAAgB,CAAC,CAChF,EAEM,EAAwB,CAC5B,QAAS,CACP,CAAE,KAAM,IAAK,MAAO,oBAAqB,EACzC,CAAE,KAAM,IAAK,MAAO,oBAAqB,EACzC,CAAE,KAAM,IAAK,MAAO,oBAAqB,CAC3C,EACA,SAAU,CAAC,CAAE,KAAM,gBAAiB,MAAO,MAAO,EAAG,CAAE,KAAM,eAAgB,CAAC,CAChF,EAEa,EAAiF,CAC5F,EAAG,CACD,eAAgB,CAAC,IAAI,EACrB,aAAe,GAAa,CAAC,MAAO,YAAa,MAAO,EAAU,KAAM,MAAM,EAC9E,YAAe,CAAC,QAAQ,EACxB,QAAS,CAC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AAE,KAAM,IAAK,MAAO,oBAAqB,CAC3C,EACA,SAAU,CAAC,CAAE,KAAM,kBAAmB,MAAO,MAAO,EAAG,CAAE,KAAM,YAAa,CAAC,CAC/E,CACF,EAEA,KAAM,CACJ,eAAgB,CAAC,KAAK,EACtB,aAAe,GAAa,CAAC,QAAS,EAAU,KAAM,MAAM,EAC5D,YAAe,CAAC,QAAQ,EACxB,QAAS,CACX,EAEA,IAAK,CACH,eAAgB,CAAC,MAAM,EACvB,aAAe,GAAa,CAAC,MAAO,YAAa,CAAQ,EACzD,QAAU,GAAa,CAAC,KAAO,EAAS,QAAQ,SAAU,EAAE,CAAC,EAC7D,QAAS,CACX,EAEA,WAAY,CACV,eAAgB,CAAC,MAAO,OAAQ,MAAM,EACtC,QAAU,GAAa,CAAC,MAAO,CAAQ,EACvC,QAAS,CACX,EAEA,KAAM,CACJ,eAAgB,CAAC,MAAM,EACvB,QAAU,GAAa,CAAC,MAAO,CAAQ,CACzC,CACF"}
|
package/dist/types/language.d.ts
CHANGED
package/dist/types/language.js
CHANGED
|
@@ -7,5 +7,5 @@ import{removeCommentsInSourceCode as e}from"../helpers/removeCommentsInSourceCod
|
|
|
7
7
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
|
8
8
|
<AssemblyName>Main</AssemblyName>
|
|
9
9
|
</PropertyGroup>
|
|
10
|
-
</Project>`)},buildCommand:()=>[`dotnet`,`build`,`Main.csproj`,`--configuration`,`Release`,`--verbosity`,`quiet`],command:()=>[`dotnet`,`bin/Release/net8.0/Main.dll`],grammer:i},css:{fileExtensions:[`.css`],command:()=>[`echo`,``],grammer:{strings:[{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*\/\*/,close:/\*\//}]}},dart:{fileExtensions:[`.dart`],buildCommand:e=>[`dart`,`compile`,`exe`,e,`-o`,`main`],command:()=>[`./main`],grammer:i},java:{fileExtensions:[`.java`],prebuild:async t=>{let a=/\bpublic\s+class\s+(\w+)\b/;for(let o of await r.promises.readdir(t,{withFileTypes:!0})){if(!o.isFile()||!o.name.endsWith(`.java`))continue;let s=await r.promises.readFile(n.join(t,o.name),`utf8`),[,c]=a.exec(e(i,s))??[];c&&await r.promises.rename(n.join(t,o.name),n.join(t,`${c}.java`))}},buildCommand:e=>[`javac`,e],command:e=>[`java`,`-Xmx1024m`,e.replace(/\.java$/,``)],grammer:i},javascript:{fileExtensions:[`.js`,`.cjs`,`.mjs`],command:e=>[`bun`,e],grammer:a},jsp:{fileExtensions:[`.jsp`],command:()=>[`echo`,``],grammer:{strings:[{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*<!--/,close:/-->/},{open:/\n?[ \t]*<%--/,close:/--%>/},{open:/\n?[ \t]*\/\*/,close:/\*\//},{open:/\n?[ \t]*\/\//}]}},haskell:{fileExtensions:[`.hs`],buildCommand:e=>[`ghc`,`-o`,`main`,e],command:()=>[`./main`],grammer:{strings:[{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*\{-/,close:/-\}/},{open:/\n?[ \t]*--/}]}},html:{fileExtensions:[`.html`],command:()=>[`echo`,``],grammer:{strings:[{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*<!--/,close:/-->/}]}},php:{fileExtensions:[`.php`],command:e=>[`php`,e],grammer:{strings:[{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*\/\*/,close:/\*\//},{open:/\n?[ \t]*\/\//},{open:/\n?[ \t]*#/}]}},python:{fileExtensions:[`.py`],command:e=>[`python3`,e],grammer:{strings:[{open:/'''/,close:/(?<!\\)(?:\\{2})*'''/},{open:/"""/,close:/(?<!\\)(?:\\{2})*"""/},{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*'''/,close:/'''/},{open:/\n?[ \t]*"""/,close:/"""/},{open:/\n?[ \t]*#/}]}},ruby:{fileExtensions:[`.rb`],buildCommand:e=>[`ruby`,`-c`,e],command:e=>[`ruby`,`--jit`,e],grammer:{strings:[{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*=begin/,close:/=end/},{open:/\n?[ \t]*#/}]}},rust:{fileExtensions:[`.rs`],buildCommand:e=>[`rustc`,e,`-o`,`main`],command:()=>[`./main`],grammer:i},zig:{fileExtensions:[`.zig`],buildCommand:e=>[`zig`,`build-exe`,e],command:e=>[`./`+e.replace(/\.zig$/,``)],grammer:i},typescript:{fileExtensions:[`.ts`,`.cts`,`.mts`],command:e=>[`bun`,e],grammer:a},text:{fileExtensions:[`.txt`],command:e=>[`cat`,e]}};export{o as languageIdToDefinition};
|
|
10
|
+
</Project>`)},buildCommand:()=>[`dotnet`,`build`,`Main.csproj`,`--configuration`,`Release`,`--verbosity`,`quiet`],command:()=>[`dotnet`,`bin/Release/net8.0/Main.dll`],grammer:i},css:{fileExtensions:[`.css`],command:()=>[`echo`,``],grammer:{strings:[{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*\/\*/,close:/\*\//}]}},dart:{fileExtensions:[`.dart`],buildCommand:e=>[`dart`,`compile`,`exe`,e,`-o`,`main`],command:()=>[`./main`],grammer:i},java:{fileExtensions:[`.java`],prebuild:async t=>{let a=/\bpublic\s+class\s+(\w+)\b/;for(let o of await r.promises.readdir(t,{withFileTypes:!0})){if(!o.isFile()||!o.name.endsWith(`.java`))continue;let s=await r.promises.readFile(n.join(t,o.name),`utf8`),[,c]=a.exec(e(i,s))??[];c&&await r.promises.rename(n.join(t,o.name),n.join(t,`${c}.java`))}},buildCommand:e=>[`javac`,e],command:e=>[`java`,`-Xmx1024m`,e.replace(/\.java$/,``)],grammer:i},kotlin:{fileExtensions:[`.kt`],buildCommand:e=>[`kotlinc`,e,`-include-runtime`,`-d`,`main.jar`],command:()=>[`java`,`-Xmx1024m`,`-jar`,`main.jar`],grammer:{strings:[{open:/"""/,close:/"""/,templateSyntax:`kotlin`},{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/,templateSyntax:`kotlin`}],comments:i.comments}},javascript:{fileExtensions:[`.js`,`.cjs`,`.mjs`],command:e=>[`bun`,e],grammer:a},jsp:{fileExtensions:[`.jsp`],command:()=>[`echo`,``],grammer:{strings:[{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*<!--/,close:/-->/},{open:/\n?[ \t]*<%--/,close:/--%>/},{open:/\n?[ \t]*\/\*/,close:/\*\//},{open:/\n?[ \t]*\/\//}]}},haskell:{fileExtensions:[`.hs`],buildCommand:e=>[`ghc`,`-o`,`main`,e],command:()=>[`./main`],grammer:{strings:[{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*\{-/,close:/-\}/},{open:/\n?[ \t]*--/}]}},html:{fileExtensions:[`.html`],command:()=>[`echo`,``],grammer:{strings:[{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*<!--/,close:/-->/}]}},php:{fileExtensions:[`.php`],command:e=>[`php`,e],grammer:{strings:[{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*\/\*/,close:/\*\//},{open:/\n?[ \t]*\/\//},{open:/\n?[ \t]*#/}]}},python:{fileExtensions:[`.py`],command:e=>[`python3`,e],grammer:{strings:[{open:/'''/,close:/(?<!\\)(?:\\{2})*'''/},{open:/"""/,close:/(?<!\\)(?:\\{2})*"""/},{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*'''/,close:/'''/},{open:/\n?[ \t]*"""/,close:/"""/},{open:/\n?[ \t]*#/}]}},ruby:{fileExtensions:[`.rb`],buildCommand:e=>[`ruby`,`-c`,e],command:e=>[`ruby`,`--jit`,e],grammer:{strings:[{open:/'/,close:/(?<!\\)(?:\\{2})*'/},{open:/"/,close:/(?<!\\)(?:\\{2})*"/}],comments:[{open:/\n?[ \t]*=begin/,close:/=end/},{open:/\n?[ \t]*#/}]}},rust:{fileExtensions:[`.rs`],buildCommand:e=>[`rustc`,e,`-o`,`main`],command:()=>[`./main`],grammer:i},zig:{fileExtensions:[`.zig`],buildCommand:e=>[`zig`,`build-exe`,e],command:e=>[`./`+e.replace(/\.zig$/,``)],grammer:i},typescript:{fileExtensions:[`.ts`,`.cts`,`.mts`],command:e=>[`bun`,e],grammer:a},text:{fileExtensions:[`.txt`],command:e=>[`cat`,e]}};export{o as languageIdToDefinition};
|
|
11
11
|
//# sourceMappingURL=language.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"language.js","names":[],"sources":["../../src/types/language.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport { removeCommentsInSourceCode } from '../helpers/removeCommentsInSourceCode.js';\nimport { writeFileWithoutFollowingSymlinks } from '../helpers/safeFs.js';\n\nexport interface LanguageDefinition {\n /** File extensions to judge with this config. */\n fileExtensions: readonly string[];\n\n /** Function executed before the build. */\n prebuild?(cwd: string): Promise<void>;\n\n /** Returns the command to build a user program. */\n buildCommand?(filePath: string): [string, ...string[]];\n\n /** Returns the command to run a user program. */\n command(filePath: string): [string, ...string[]];\n\n /** Grammer definition for static analysis. */\n grammer?: {\n strings?: readonly { open: RegExp; close: RegExp }[];\n comments?: readonly { open: RegExp; close?: RegExp }[];\n };\n}\n\nconst cLikeGrammer = {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [{ open: /\\n?[ \\t]*\\/\\*/, close: /\\*\\// }, { open: /\\n?[ \\t]*\\/\\// }],\n} as const satisfies LanguageDefinition['grammer'];\n\nconst javaScriptLikeGrammer = {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n { open: /`/, close: /(?<!\\\\)(?:\\\\{2})*`/ },\n ],\n comments: [{ open: /\\n?[ \\t]*\\/\\*/, close: /\\*\\// }, { open: /\\n?[ \\t]*\\/\\// }],\n} as const satisfies LanguageDefinition['grammer'];\n\nexport const languageIdToDefinition: Readonly<Record<string, Readonly<LanguageDefinition>>> = {\n c: {\n fileExtensions: ['.c'],\n buildCommand: (filePath) => ['gcc', '--std=c17', '-O2', filePath, '-o', 'main'],\n command: () => ['./main'],\n grammer: cLikeGrammer,\n },\n\n cpp: {\n fileExtensions: ['.cpp'],\n buildCommand: (filePath) => ['g++', '--std=c++20', '-O2', filePath, '-o', 'main'],\n command: () => ['./main'],\n grammer: cLikeGrammer,\n },\n\n csharp: {\n fileExtensions: ['.cs'],\n prebuild: async (cwd) => {\n // No-follow write: the submission owns `cwd` and could point `Main.csproj` at a file only the\n // trusted harness user can write.\n await writeFileWithoutFollowingSymlinks(\n path.join(cwd, 'Main.csproj'),\n `<Project Sdk=\"Microsoft.NET.Sdk\">\n <PropertyGroup>\n <OutputType>Exe</OutputType>\n <TargetFramework>net8.0</TargetFramework>\n <ImplicitUsings>enable</ImplicitUsings>\n <Nullable>enable</Nullable>\n <AllowUnsafeBlocks>true</AllowUnsafeBlocks>\n <AssemblyName>Main</AssemblyName>\n </PropertyGroup>\n</Project>`\n );\n },\n buildCommand: () => ['dotnet', 'build', 'Main.csproj', '--configuration', 'Release', '--verbosity', 'quiet'],\n command: () => ['dotnet', 'bin/Release/net8.0/Main.dll'],\n grammer: cLikeGrammer,\n },\n\n css: {\n fileExtensions: ['.css'],\n command: () => ['echo', ''],\n grammer: {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [{ open: /\\n?[ \\t]*\\/\\*/, close: /\\*\\// }],\n },\n },\n\n dart: {\n fileExtensions: ['.dart'],\n buildCommand: (filePath) => ['dart', 'compile', 'exe', filePath, '-o', 'main'],\n command: () => ['./main'],\n grammer: cLikeGrammer,\n },\n\n java: {\n fileExtensions: ['.java'],\n prebuild: async (cwd) => {\n const publicClassRegex = /\\bpublic\\s+class\\s+(\\w+)\\b/;\n for (const dirent of await fs.promises.readdir(cwd, { withFileTypes: true })) {\n if (!dirent.isFile() || !dirent.name.endsWith('.java')) continue;\n const data = await fs.promises.readFile(path.join(cwd, dirent.name), 'utf8');\n const [, className] = publicClassRegex.exec(removeCommentsInSourceCode(cLikeGrammer, data)) ?? [];\n if (className) await fs.promises.rename(path.join(cwd, dirent.name), path.join(cwd, `${className}.java`));\n }\n },\n buildCommand: (fileName) => ['javac', fileName],\n // For example, Problem 7-3 in WillBooster's Java lecture uses at least 256MB.\n command: (fileName) => ['java', '-Xmx1024m', fileName.replace(/\\.java$/, '')],\n grammer: cLikeGrammer,\n },\n\n javascript: {\n fileExtensions: ['.js', '.cjs', '.mjs'],\n command: (fileName) => ['bun', fileName],\n grammer: javaScriptLikeGrammer,\n },\n\n jsp: {\n fileExtensions: ['.jsp'],\n command: () => ['echo', ''],\n grammer: {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [\n { open: /\\n?[ \\t]*<!--/, close: /-->/ },\n { open: /\\n?[ \\t]*<%--/, close: /--%>/ },\n { open: /\\n?[ \\t]*\\/\\*/, close: /\\*\\// },\n { open: /\\n?[ \\t]*\\/\\// },\n ],\n },\n },\n\n haskell: {\n fileExtensions: ['.hs'],\n buildCommand: (filePath) => ['ghc', '-o', 'main', filePath],\n command: () => ['./main'],\n grammer: {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [{ open: /\\n?[ \\t]*\\{-/, close: /-\\}/ }, { open: /\\n?[ \\t]*--/ }],\n },\n },\n\n html: {\n fileExtensions: ['.html'],\n command: () => ['echo', ''],\n grammer: {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [{ open: /\\n?[ \\t]*<!--/, close: /-->/ }],\n },\n },\n\n php: {\n fileExtensions: ['.php'],\n command: (fileName) => ['php', fileName],\n grammer: {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [{ open: /\\n?[ \\t]*\\/\\*/, close: /\\*\\// }, { open: /\\n?[ \\t]*\\/\\// }, { open: /\\n?[ \\t]*#/ }],\n },\n },\n\n python: {\n fileExtensions: ['.py'],\n command: (fileName) => ['python3', fileName],\n grammer: {\n strings: [\n { open: /'''/, close: /(?<!\\\\)(?:\\\\{2})*'''/ },\n { open: /\"\"\"/, close: /(?<!\\\\)(?:\\\\{2})*\"\"\"/ },\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [\n { open: /\\n?[ \\t]*'''/, close: /'''/ },\n { open: /\\n?[ \\t]*\"\"\"/, close: /\"\"\"/ },\n { open: /\\n?[ \\t]*#/ },\n ],\n },\n },\n\n ruby: {\n fileExtensions: ['.rb'],\n buildCommand: (fileName) => ['ruby', '-c', fileName],\n command: (fileName) => ['ruby', '--jit', fileName],\n grammer: {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [{ open: /\\n?[ \\t]*=begin/, close: /=end/ }, { open: /\\n?[ \\t]*#/ }],\n },\n },\n\n rust: {\n fileExtensions: ['.rs'],\n buildCommand: (filePath) => ['rustc', filePath, '-o', 'main'],\n command: () => ['./main'],\n grammer: cLikeGrammer,\n },\n\n zig: {\n fileExtensions: ['.zig'],\n buildCommand: (filePath) => ['zig', 'build-exe', filePath],\n command: (filePath) => ['./' + filePath.replace(/\\.zig$/, '')],\n grammer: cLikeGrammer,\n },\n\n typescript: {\n fileExtensions: ['.ts', '.cts', '.mts'],\n command: (fileName) => ['bun', fileName],\n grammer: javaScriptLikeGrammer,\n },\n\n text: {\n fileExtensions: ['.txt'],\n command: (fileName) => ['cat', fileName],\n },\n} as const;\n"],"mappings":"+MA0BA,MAAM,EAAe,CACnB,QAAS,CACP,CAAE,KAAM,IAAK,MAAO,oBAAqB,EACzC,CAAE,KAAM,IAAK,MAAO,oBAAqB,CAC3C,EACA,SAAU,CAAC,CAAE,KAAM,gBAAiB,MAAO,MAAO,EAAG,CAAE,KAAM,eAAgB,CAAC,CAChF,EAEM,EAAwB,CAC5B,QAAS,CACP,CAAE,KAAM,IAAK,MAAO,oBAAqB,EACzC,CAAE,KAAM,IAAK,MAAO,oBAAqB,EACzC,CAAE,KAAM,IAAK,MAAO,oBAAqB,CAC3C,EACA,SAAU,CAAC,CAAE,KAAM,gBAAiB,MAAO,MAAO,EAAG,CAAE,KAAM,eAAgB,CAAC,CAChF,EAEa,EAAiF,CAC5F,EAAG,CACD,eAAgB,CAAC,IAAI,EACrB,aA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C,MAAO,YAAa,CAAQ,EACzD,QAAU,GAAa,CAAC,KAAO,EAAS,QAAQ,SAAU,EAAE,CAAC,EAC7D,QAAS,CACX,EAEA,WAAY,CACV,eAAgB,CAAC,MAAO,OAAQ,MAAM,EACtC,QAAU,GAAa,CAAC,MAAO,CAAQ,EACvC,QAAS,CACX,EAEA,KAAM,CACJ,eAAgB,CAAC,MAAM,EACvB,QAAU,GAAa,CAAC,MAAO,CAAQ,CACzC,CACF"}
|
|
1
|
+
{"version":3,"file":"language.js","names":[],"sources":["../../src/types/language.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport { removeCommentsInSourceCode } from '../helpers/removeCommentsInSourceCode.js';\nimport { writeFileWithoutFollowingSymlinks } from '../helpers/safeFs.js';\n\nexport interface LanguageDefinition {\n /** File extensions to judge with this config. */\n fileExtensions: readonly string[];\n\n /** Function executed before the build. */\n prebuild?(cwd: string): Promise<void>;\n\n /** Returns the command to build a user program. */\n buildCommand?(filePath: string): [string, ...string[]];\n\n /** Returns the command to run a user program. */\n command(filePath: string): [string, ...string[]];\n\n /** Grammer definition for static analysis. */\n grammer?: {\n strings?: readonly { open: RegExp; close: RegExp; templateSyntax?: 'kotlin' }[];\n comments?: readonly { open: RegExp; close?: RegExp }[];\n };\n}\n\nconst cLikeGrammer = {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [{ open: /\\n?[ \\t]*\\/\\*/, close: /\\*\\// }, { open: /\\n?[ \\t]*\\/\\// }],\n} as const satisfies LanguageDefinition['grammer'];\n\nconst javaScriptLikeGrammer = {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n { open: /`/, close: /(?<!\\\\)(?:\\\\{2})*`/ },\n ],\n comments: [{ open: /\\n?[ \\t]*\\/\\*/, close: /\\*\\// }, { open: /\\n?[ \\t]*\\/\\// }],\n} as const satisfies LanguageDefinition['grammer'];\n\nexport const languageIdToDefinition: Readonly<Record<string, Readonly<LanguageDefinition>>> = {\n c: {\n fileExtensions: ['.c'],\n buildCommand: (filePath) => ['gcc', '--std=c17', '-O2', filePath, '-o', 'main'],\n command: () => ['./main'],\n grammer: cLikeGrammer,\n },\n\n cpp: {\n fileExtensions: ['.cpp'],\n buildCommand: (filePath) => ['g++', '--std=c++20', '-O2', filePath, '-o', 'main'],\n command: () => ['./main'],\n grammer: cLikeGrammer,\n },\n\n csharp: {\n fileExtensions: ['.cs'],\n prebuild: async (cwd) => {\n // No-follow write: the submission owns `cwd` and could point `Main.csproj` at a file only the\n // trusted harness user can write.\n await writeFileWithoutFollowingSymlinks(\n path.join(cwd, 'Main.csproj'),\n `<Project Sdk=\"Microsoft.NET.Sdk\">\n <PropertyGroup>\n <OutputType>Exe</OutputType>\n <TargetFramework>net8.0</TargetFramework>\n <ImplicitUsings>enable</ImplicitUsings>\n <Nullable>enable</Nullable>\n <AllowUnsafeBlocks>true</AllowUnsafeBlocks>\n <AssemblyName>Main</AssemblyName>\n </PropertyGroup>\n</Project>`\n );\n },\n buildCommand: () => ['dotnet', 'build', 'Main.csproj', '--configuration', 'Release', '--verbosity', 'quiet'],\n command: () => ['dotnet', 'bin/Release/net8.0/Main.dll'],\n grammer: cLikeGrammer,\n },\n\n css: {\n fileExtensions: ['.css'],\n command: () => ['echo', ''],\n grammer: {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [{ open: /\\n?[ \\t]*\\/\\*/, close: /\\*\\// }],\n },\n },\n\n dart: {\n fileExtensions: ['.dart'],\n buildCommand: (filePath) => ['dart', 'compile', 'exe', filePath, '-o', 'main'],\n command: () => ['./main'],\n grammer: cLikeGrammer,\n },\n\n java: {\n fileExtensions: ['.java'],\n prebuild: async (cwd) => {\n const publicClassRegex = /\\bpublic\\s+class\\s+(\\w+)\\b/;\n for (const dirent of await fs.promises.readdir(cwd, { withFileTypes: true })) {\n if (!dirent.isFile() || !dirent.name.endsWith('.java')) continue;\n const data = await fs.promises.readFile(path.join(cwd, dirent.name), 'utf8');\n const [, className] = publicClassRegex.exec(removeCommentsInSourceCode(cLikeGrammer, data)) ?? [];\n if (className) await fs.promises.rename(path.join(cwd, dirent.name), path.join(cwd, `${className}.java`));\n }\n },\n buildCommand: (fileName) => ['javac', fileName],\n // For example, Problem 7-3 in WillBooster's Java lecture uses at least 256MB.\n command: (fileName) => ['java', '-Xmx1024m', fileName.replace(/\\.java$/, '')],\n grammer: cLikeGrammer,\n },\n\n kotlin: {\n fileExtensions: ['.kt'],\n buildCommand: (filePath) => ['kotlinc', filePath, '-include-runtime', '-d', 'main.jar'],\n command: () => ['java', '-Xmx1024m', '-jar', 'main.jar'],\n grammer: {\n strings: [\n { open: /\"\"\"/, close: /\"\"\"/, templateSyntax: 'kotlin' },\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/, templateSyntax: 'kotlin' },\n ],\n comments: cLikeGrammer.comments,\n },\n },\n\n javascript: {\n fileExtensions: ['.js', '.cjs', '.mjs'],\n command: (fileName) => ['bun', fileName],\n grammer: javaScriptLikeGrammer,\n },\n\n jsp: {\n fileExtensions: ['.jsp'],\n command: () => ['echo', ''],\n grammer: {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [\n { open: /\\n?[ \\t]*<!--/, close: /-->/ },\n { open: /\\n?[ \\t]*<%--/, close: /--%>/ },\n { open: /\\n?[ \\t]*\\/\\*/, close: /\\*\\// },\n { open: /\\n?[ \\t]*\\/\\// },\n ],\n },\n },\n\n haskell: {\n fileExtensions: ['.hs'],\n buildCommand: (filePath) => ['ghc', '-o', 'main', filePath],\n command: () => ['./main'],\n grammer: {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [{ open: /\\n?[ \\t]*\\{-/, close: /-\\}/ }, { open: /\\n?[ \\t]*--/ }],\n },\n },\n\n html: {\n fileExtensions: ['.html'],\n command: () => ['echo', ''],\n grammer: {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [{ open: /\\n?[ \\t]*<!--/, close: /-->/ }],\n },\n },\n\n php: {\n fileExtensions: ['.php'],\n command: (fileName) => ['php', fileName],\n grammer: {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [{ open: /\\n?[ \\t]*\\/\\*/, close: /\\*\\// }, { open: /\\n?[ \\t]*\\/\\// }, { open: /\\n?[ \\t]*#/ }],\n },\n },\n\n python: {\n fileExtensions: ['.py'],\n command: (fileName) => ['python3', fileName],\n grammer: {\n strings: [\n { open: /'''/, close: /(?<!\\\\)(?:\\\\{2})*'''/ },\n { open: /\"\"\"/, close: /(?<!\\\\)(?:\\\\{2})*\"\"\"/ },\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [\n { open: /\\n?[ \\t]*'''/, close: /'''/ },\n { open: /\\n?[ \\t]*\"\"\"/, close: /\"\"\"/ },\n { open: /\\n?[ \\t]*#/ },\n ],\n },\n },\n\n ruby: {\n fileExtensions: ['.rb'],\n buildCommand: (fileName) => ['ruby', '-c', fileName],\n command: (fileName) => ['ruby', '--jit', fileName],\n grammer: {\n strings: [\n { open: /'/, close: /(?<!\\\\)(?:\\\\{2})*'/ },\n { open: /\"/, close: /(?<!\\\\)(?:\\\\{2})*\"/ },\n ],\n comments: [{ open: /\\n?[ \\t]*=begin/, close: /=end/ }, { open: /\\n?[ \\t]*#/ }],\n },\n },\n\n rust: {\n fileExtensions: ['.rs'],\n buildCommand: (filePath) => ['rustc', filePath, '-o', 'main'],\n command: () => ['./main'],\n grammer: cLikeGrammer,\n },\n\n zig: {\n fileExtensions: ['.zig'],\n buildCommand: (filePath) => ['zig', 'build-exe', filePath],\n command: (filePath) => ['./' + filePath.replace(/\\.zig$/, '')],\n grammer: cLikeGrammer,\n },\n\n typescript: {\n fileExtensions: ['.ts', '.cts', '.mts'],\n command: (fileName) => ['bun', fileName],\n grammer: javaScriptLikeGrammer,\n },\n\n text: {\n fileExtensions: ['.txt'],\n command: (fileName) => ['cat', fileName],\n },\n} as const;\n"],"mappings":"+MA0BA,MAAM,EAAe,CACnB,QAAS,CACP,CAAE,KAAM,IAAK,MAAO,oBAAqB,EACzC,CAAE,KAAM,IAAK,MAAO,oBAAqB,CAC3C,EACA,SAAU,CAAC,CAAE,KAAM,gBAAiB,MAAO,MAAO,EAAG,CAAE,KAAM,eAAgB,CAAC,CAChF,EAEM,EAAwB,CAC5B,QAAS,CACP,CAAE,KAAM,IAAK,MAAO,oBAAqB,EACzC,CAAE,KAAM,IAAK,MAAO,oBAAqB,EACzC,CAAE,KAAM,IAAK,MAAO,oBAAqB,CAC3C,EACA,SAAU,CAAC,CAAE,KAAM,gBAAiB,MAAO,MAAO,EAAG,CAAE,KAAM,eAAgB,CAAC,CAChF,EAEa,EAAiF,CAC5F,EAAG,CACD,eAAgB,CAAC,IAAI,EACrB,aAAe,GAAa,CAAC,MAAO,YAAa,MAAO,EAAU,KAAM,MAAM,EAC9E,YAAe,CAAC,QAAQ,EACxB,QAAS,CACX,EAEA,IAAK,CACH,eAAgB,CAAC,MAAM,EACvB,aAAe,GAAa,CAAC,MAAO,cAAe,MAAO,EAAU,KAAM,MAAM,EAChF,YAAe,CAAC,QAAQ,E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