@likec4/mcp 1.59.1 → 1.59.2
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/chunks/src.mjs +21 -342
- package/dist/cli.mjs +1 -5
- package/package.json +22 -21
- package/dist/chunks/libs/@chevrotain/cst-dts-gen.mjs +0 -1
- package/dist/chunks/libs/@chevrotain/regexp-to-ast.mjs +0 -9
- package/dist/chunks/libs/@hono/mcp.mjs +0 -70
- package/dist/chunks/libs/@hono/node-server.mjs +0 -3
- package/dist/chunks/libs/@logtape/logtape.mjs +0 -5
- package/dist/chunks/libs/@modelcontextprotocol/sdk.mjs +0 -5
- package/dist/chunks/libs/@radix-ui/colors.mjs +0 -1
- package/dist/chunks/libs/@ts-graphviz/ast.mjs +0 -3
- package/dist/chunks/libs/@ts-graphviz/core.mjs +0 -1
- package/dist/chunks/libs/@ungap/structured-clone.mjs +0 -1
- package/dist/chunks/libs/character-entities.mjs +0 -2
- package/dist/chunks/libs/chevrotain-allstar.mjs +0 -2
- package/dist/chunks/libs/chevrotain.mjs +0 -58
- package/dist/chunks/libs/chokidar.mjs +0 -3
- package/dist/chunks/libs/chroma-js.mjs +0 -15
- package/dist/chunks/libs/eventemitter3.mjs +0 -1
- package/dist/chunks/libs/graphology-dag.mjs +0 -1
- package/dist/chunks/libs/graphology.mjs +0 -1
- package/dist/chunks/libs/hast-util-sanitize.mjs +0 -1
- package/dist/chunks/libs/hast-util-to-html.mjs +0 -9
- package/dist/chunks/libs/hono.mjs +0 -1
- package/dist/chunks/libs/immer.mjs +0 -1
- package/dist/chunks/libs/khroma.mjs +0 -1
- package/dist/chunks/libs/langium.mjs +0 -19
- package/dist/chunks/libs/markdown-table.mjs +0 -2
- package/dist/chunks/libs/mdast-util-find-and-replace.mjs +0 -1
- package/dist/chunks/libs/mdast-util-from-markdown.mjs +0 -3
- package/dist/chunks/libs/mdast-util-gfm.mjs +0 -15
- package/dist/chunks/libs/mdast-util-to-hast.mjs +0 -11
- package/dist/chunks/libs/merge-error-cause.mjs +0 -2
- package/dist/chunks/libs/micromark-extension-gfm.mjs +0 -1
- package/dist/chunks/libs/mnemonist.mjs +0 -1
- package/dist/chunks/libs/nano-spawn.mjs +0 -3
- package/dist/chunks/libs/p-queue.mjs +0 -1
- package/dist/chunks/libs/pathe.mjs +0 -1
- package/dist/chunks/libs/picomatch.mjs +0 -1
- package/dist/chunks/libs/pretty-ms.mjs +0 -1
- package/dist/chunks/libs/remark-github-blockquote-alert.mjs +0 -3
- package/dist/chunks/libs/remark-rehype.mjs +0 -1
- package/dist/chunks/libs/remeda.mjs +0 -1
- package/dist/chunks/libs/ufo.mjs +0 -1
- package/dist/chunks/libs/unified.mjs +0 -1
- package/dist/chunks/libs/unstorage.mjs +0 -1
- package/dist/chunks/rolldown-runtime.mjs +0 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{
|
|
3
|
-
`)}function resolveValue(e){return typeof e==`function`?e():e}var CLIError=class extends Error{code;constructor(e,t){super(e),this.name=`CLIError`,this.code=t}};function parseRawArgs(e=[],t={}){let n=new Set(t.boolean||[]),r=new Set(t.string||[]),a=t.alias||{},o=t.default||{},s=new Map,c=new Map;for(let[e,t]of Object.entries(a)){let n=t;for(let t of n)s.set(e,t),c.has(t)||c.set(t,[]),c.get(t).push(e),s.set(t,e),c.has(e)||c.set(e,[]),c.get(e).push(t)}let l={};function getType(e){if(n.has(e))return`boolean`;let t=c.get(e)||[];for(let e of t)if(n.has(e))return`boolean`;return`string`}function isStringType(e){if(r.has(e))return!0;let t=c.get(e)||[];for(let e of t)if(r.has(e))return!0;return!1}let u=new Set([...n,...r,...Object.keys(a),...Object.values(a).flat(),...Object.keys(o)]);for(let e of u)l[e]||(l[e]={type:getType(e),default:o[e]});for(let[e,t]of s.entries())e.length===1&&l[t]&&!l[t].short&&(l[t].short=e);let d=[],f={};for(let t=0;t<e.length;t++){let n=e[t];if(n===`--`){d.push(...e.slice(t));break}if(n.startsWith(`--no-`)){let e=n.slice(5);f[e]=!0;continue}d.push(n)}let p;try{p=i({args:d,options:Object.keys(l).length>0?l:void 0,allowPositionals:!0,strict:!1})}catch{p={values:{},positionals:d}}let m={_:[]};m._=p.positionals;for(let[e,t]of Object.entries(p.values)){let n=t;getType(e)===`boolean`&&typeof t==`string`?n=t!==`false`:isStringType(e)&&typeof t==`boolean`&&(n=``),m[e]=n}for(let[e]of Object.entries(f)){m[e]=!1;let t=s.get(e);t&&(m[t]=!1);let n=c.get(e);if(n)for(let e of n)m[e]=!1}for(let[e,t]of s.entries())m[e]!==void 0&&m[t]===void 0&&(m[t]=m[e]),m[t]!==void 0&&m[e]===void 0&&(m[e]=m[t]),m[e]!==m[t]&&o[t]===m[t]&&(m[t]=m[e]);return m}const s=(()=>{let e=globalThis.process?.env??{};return e.NO_COLOR===`1`||e.TERM===`dumb`||e.TEST||e.CI})(),_c=(e,t=39)=>n=>s?n:`\u001B[${e}m${n}\u001B[${t}m`,c=_c(1,22),l=_c(36),u=_c(90),d=_c(4,24);function parseArgs$1(e,t){let n={boolean:[],string:[],alias:{},default:{}},r=resolveArgs(t);for(let e of r){if(e.type===`positional`)continue;e.type===`string`||e.type===`enum`?n.string.push(e.name):e.type===`boolean`&&n.boolean.push(e.name),e.default!==void 0&&(n.default[e.name]=e.default),e.alias&&(n.alias[e.name]=e.alias);let t=camelCase(e.name),r=kebabCase(e.name);if(t!==e.name||r!==e.name){let i=toArray(n.alias[e.name]||[]);t!==e.name&&!i.includes(t)&&i.push(t),r!==e.name&&!i.includes(r)&&i.push(r),i.length>0&&(n.alias[e.name]=i)}}let i=parseRawArgs(e,n),[...a]=i._,o=new Proxy(i,{get(e,t){return e[t]??e[camelCase(t)]??e[kebabCase(t)]}});for(let[,e]of r.entries())if(e.type===`positional`){let t=a.shift();if(t!==void 0)o[e.name]=t;else if(e.default===void 0&&e.required!==!1)throw new CLIError(`Missing required positional argument: ${e.name.toUpperCase()}`,`EARG`);else o[e.name]=e.default}else if(e.type===`enum`){let t=o[e.name],n=e.options||[];if(t!==void 0&&n.length>0&&!n.includes(t))throw new CLIError(`Invalid value for argument: ${l(`--${e.name}`)} (${l(t)}). Expected one of: ${n.map(e=>l(e)).join(`, `)}.`,`EARG`)}else if(e.required&&o[e.name]===void 0)throw new CLIError(`Missing required argument: --${e.name}`,`EARG`);return o}e(parseArgs$1,`parseArgs`);function resolveArgs(e){let t=[];for(let[n,r]of Object.entries(e||{}))t.push({...r,name:n,alias:toArray(r.alias)});return t}async function resolvePlugins(e){return Promise.all(e.map(e=>resolveValue(e)))}function defineCommand(e){return e}async function runCommand(e,t){let n=await resolveValue(e.args||{}),r=parseArgs$1(t.rawArgs,n),i={rawArgs:t.rawArgs,args:r,data:t.data,cmd:e},a=await resolvePlugins(e.plugins??[]),o,s;try{for(let e of a)await e.setup?.(i);typeof e.setup==`function`&&await e.setup(i);let r=await resolveValue(e.subCommands);if(r&&Object.keys(r).length>0){let i=findSubCommandIndex(t.rawArgs,n),a=t.rawArgs[i];if(a){let e=await _findSubCommand(r,a);if(!e)throw new CLIError(`Unknown command ${l(a)}`,`E_UNKNOWN_COMMAND`);await runCommand(e,{rawArgs:t.rawArgs.slice(i+1)})}else{let n=await resolveValue(e.default);if(n){if(e.run)throw new CLIError(`Cannot specify both 'run' and 'default' on the same command.`,`E_DEFAULT_CONFLICT`);let i=await _findSubCommand(r,n);if(!i)throw new CLIError(`Default sub command ${l(n)} not found in subCommands.`,`E_UNKNOWN_COMMAND`);await runCommand(i,{rawArgs:t.rawArgs})}else if(!e.run)throw new CLIError(`No command specified.`,`E_NO_COMMAND`)}}typeof e.run==`function`&&(o=await e.run(i))}catch(e){s=e}let c=[];if(typeof e.cleanup==`function`)try{await e.cleanup(i)}catch(e){c.push(e)}for(let e of[...a].reverse())try{await e.cleanup?.(i)}catch(e){c.push(e)}if(s)throw s;if(c.length===1)throw c[0];if(c.length>1)throw Error(`Multiple cleanup errors`,{cause:c});return{result:o}}async function resolveSubCommand(e,t,n){let r=await resolveValue(e.subCommands);if(r&&Object.keys(r).length>0){let n=findSubCommandIndex(t,await resolveValue(e.args||{})),i=t[n],a=await _findSubCommand(r,i);if(a)return resolveSubCommand(a,t.slice(n+1),e)}return[e,n]}async function _findSubCommand(e,t){if(t in e)return resolveValue(e[t]);for(let n of Object.values(e)){let e=await resolveValue(n),r=await resolveValue(e?.meta);if(r?.alias&&toArray(r.alias).includes(t))return e}}function findSubCommandIndex(e,t){for(let n=0;n<e.length;n++){let r=e[n];if(r===`--`)return-1;if(r.startsWith(`-`)){!r.includes(`=`)&&_isValueFlag(r,t)&&n++;continue}return n}return-1}function _isValueFlag(e,t){let n=e.replace(/^-{1,2}/,``),r=camelCase(n);for(let[e,i]of Object.entries(t))if((i.type===`string`||i.type===`enum`)&&(r===camelCase(e)||(Array.isArray(i.alias)?i.alias:i.alias?[i.alias]:[]).includes(n)))return!0;return!1}async function showUsage(e,t){try{console.log(await renderUsage(e,t)+`
|
|
4
|
-
`)}catch(e){console.error(e)}}const f=/^no[-A-Z]/;async function renderUsage(e,t){let n=await resolveValue(e.meta||{}),r=resolveArgs(await resolveValue(e.args||{})),i=await resolveValue(t?.meta||{}),a=`${i.name?`${i.name} `:``}`+(n.name||process.argv[1]),o=[],s=[],p=[],m=[];for(let e of r)if(e.type===`positional`){let t=e.name.toUpperCase(),n=e.required!==!1&&e.default===void 0;s.push([l(t+renderValueHint(e)),renderDescription(e,n)]),m.push(n?`<${t}>`:`[${t}]`)}else{let t=e.required===!0&&e.default===void 0,n=[...(e.alias||[]).map(e=>`-${e}`),`--${e.name}`].join(`, `)+renderValueHint(e);if(o.push([l(n),renderDescription(e,t)]),e.type===`boolean`&&(e.default===!0||e.negativeDescription)&&!f.test(e.name)){let n=[...(e.alias||[]).map(e=>`--no-${e}`),`--no-${e.name}`].join(`, `);o.push([l(n),[e.negativeDescription,t?u(`(Required)`):``].filter(Boolean).join(` `)])}t&&m.push(`--${e.name}`+renderValueHint(e))}if(e.subCommands){let t=[],n=await resolveValue(e.subCommands);for(let[e,r]of Object.entries(n)){let n=await resolveValue((await resolveValue(r))?.meta);if(n?.hidden)continue;let i=toArray(n?.alias),a=[e,...i].join(`, `);p.push([l(a),n?.description||``]),t.push(e,...i)}m.push(t.join(`|`))}let h=[],g=n.version||i.version;h.push(u(`${n.description} (${a+(g?` v${g}`:``)})`),``);let _=o.length>0||s.length>0;return h.push(`${d(c(`USAGE`))} ${l(`${a}${_?` [OPTIONS]`:``} ${m.join(` `)}`)}`,``),s.length>0&&(h.push(d(c(`ARGUMENTS`)),``),h.push(formatLineColumns(s,` `)),h.push(``)),o.length>0&&(h.push(d(c(`OPTIONS`)),``),h.push(formatLineColumns(o,` `)),h.push(``)),p.length>0&&(h.push(d(c(`COMMANDS`)),``),h.push(formatLineColumns(p,` `)),h.push(``,`Use ${l(`${a} <command> --help`)} for more information about a command.`)),h.filter(e=>typeof e==`string`).join(`
|
|
5
|
-
`)}function renderValueHint(e){let t=e.valueHint?`=<${e.valueHint}>`:``,n=t||`=<${snakeCase(e.name)}>`;return!e.type||e.type===`positional`||e.type===`boolean`?t:e.type===`enum`&&e.options?.length?`=<${e.options.join(`|`)}>`:n}function renderDescription(e,t){let n=t?u(`(Required)`):``,r=e.default===void 0?``:u(`(Default: ${e.default})`);return[e.description,n,r].filter(Boolean).join(` `)}async function runMain(e,t={}){let n=t.rawArgs||process.argv.slice(2),r=t.showUsage||showUsage;try{let t=await _resolveBuiltinFlags(e);if(t.help.length>0&&n.some(e=>t.help.includes(e)))await r(...await resolveSubCommand(e,n)),process.exit(0);else if(n.length===1&&t.version.includes(n[0])){let t=typeof e.meta==`function`?await e.meta():await e.meta;if(!t?.version)throw new CLIError(`No version specified`,`E_NO_VERSION`);console.log(t.version)}else await runCommand(e,{rawArgs:n})}catch(t){t instanceof CLIError?(await r(...await resolveSubCommand(e,n)),console.error(t.message)):console.error(t,`
|
|
6
|
-
`),process.exit(1)}}async function _resolveBuiltinFlags(e){let t=await resolveValue(e.args||{}),n=new Set,r=new Set;for(let[e,i]of Object.entries(t)){n.add(e);for(let e of toArray(i.alias))r.add(e)}return{help:_getBuiltinFlags(`help`,`h`,n,r),version:_getBuiltinFlags(`version`,`v`,n,r)}}function _getBuiltinFlags(e,t,n,r){return n.has(e)||r.has(e)?[]:n.has(t)||r.has(t)?[`--${e}`]:[`--${e}`,`-${t}`]}runMain(defineCommand({meta:{name:`likec4-mcp-server`,description:`LikeC4 MCP server`},args:{stdio:{type:`boolean`,description:`use stdio transport (default)`,required:!1},http:{type:`boolean`,description:`use streamable http transport`,required:!1},port:{type:`string`,description:`change http port`,valueHint:`number`,required:!1},graphviz:{type:`enum`,options:[`binary`,`wasm`],description:`use binary or wasm graphviz`,default:`wasm`,required:!1},watch:{type:`boolean`,description:`disable watch for changes`,default:!0,required:!1},workspace:{type:`positional`,description:`change workspace, can be set by LIKEC4_WORKSPACE env`,valueHint:`directory`,required:!1,default:process.env.LIKEC4_WORKSPACE||`.`}},setup({args:e}){if(e.stdio&&(e.http||e.port))throw Error(`stdio and http are mutually exclusive`)},async run({args:e}){let i=e.stdio||!e.http&&!e.port,a=e.port?parseInt(e.port):33335,o=r(e.workspace||`.`);e.watch&&n.warn`watch for changes enabled, use ${`--no-watch`} to consume less resources`,await t({workspacePath:o,graphviz:e.graphviz,mcp:i?`stdio`:{port:a},configureLogger:!0,watch:e.watch})}})).catch(e=>{n.error(e),process.exit(1)});
|
|
2
|
+
import{n as e,r as t}from"./chunks/src.mjs";import{resolve as n}from"node:path";import{defineCommand as r,runMain as i}from"citty";i(r({meta:{name:`likec4-mcp-server`,description:`LikeC4 MCP server`},args:{stdio:{type:`boolean`,description:`use stdio transport (default)`,required:!1},http:{type:`boolean`,description:`use streamable http transport`,required:!1},port:{type:`string`,description:`change http port`,valueHint:`number`,required:!1},graphviz:{type:`enum`,options:[`binary`,`wasm`],description:`use binary or wasm graphviz`,default:`wasm`,required:!1},watch:{type:`boolean`,description:`disable watch for changes`,default:!0,required:!1},workspace:{type:`positional`,description:`change workspace, can be set by LIKEC4_WORKSPACE env`,valueHint:`directory`,required:!1,default:process.env.LIKEC4_WORKSPACE||`.`}},setup({args:e}){if(e.stdio&&(e.http||e.port))throw Error(`stdio and http are mutually exclusive`)},async run({args:r}){let i=r.stdio||!r.http&&!r.port,a=r.port?parseInt(r.port):33335,o=n(r.workspace||`.`);r.watch&&t.warn`watch for changes enabled, use ${`--no-watch`} to consume less resources`,await e({workspacePath:o,graphviz:r.graphviz,mcp:i?`stdio`:{port:a},configureLogger:!0,watch:r.watch})}})).catch(e=>{t.error(e),process.exit(1)});
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@likec4/mcp",
|
|
3
3
|
"description": "Model Context Protocol server for LikeC4",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "1.59.
|
|
5
|
+
"version": "1.59.2",
|
|
6
6
|
"bugs": "https://github.com/likec4/likec4/issues",
|
|
7
7
|
"homepage": "https://likec4.dev",
|
|
8
8
|
"author": "Denis Davydkov <denis@davydkov.com>",
|
|
@@ -41,40 +41,40 @@
|
|
|
41
41
|
"server"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
+
"@hono/mcp": "^0.3.1",
|
|
45
|
+
"@hono/node-server": "^2.0.10",
|
|
44
46
|
"@hpcc-js/wasm-graphviz": "1.22.2",
|
|
47
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
45
48
|
"bundle-require": "^5.1.0",
|
|
49
|
+
"citty": "^0.2.2",
|
|
50
|
+
"defu": "^6.1.7",
|
|
46
51
|
"esbuild": "0.28.1",
|
|
47
|
-
"
|
|
52
|
+
"hono": "^4.12.31",
|
|
53
|
+
"remeda": "^2.37.0",
|
|
54
|
+
"std-env": "^4.1.0",
|
|
55
|
+
"tinyrainbow": "^3.1.0",
|
|
56
|
+
"unctx": "^2.5.0",
|
|
57
|
+
"vscode-uri": "3.1.0",
|
|
58
|
+
"zod": "^4.4.3",
|
|
59
|
+
"@likec4/config": "1.59.2",
|
|
60
|
+
"@likec4/language-services": "1.59.2",
|
|
61
|
+
"@likec4/language-server": "1.59.2",
|
|
62
|
+
"@likec4/log": "1.59.2",
|
|
63
|
+
"@likec4/core": "1.59.2",
|
|
64
|
+
"@likec4/layouts": "1.59.2"
|
|
48
65
|
},
|
|
49
66
|
"devDependencies": {
|
|
50
|
-
"@hono/mcp": "^0.3.0",
|
|
51
|
-
"@hono/node-server": "^2.0.8",
|
|
52
|
-
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
53
67
|
"@types/node": "~22.19.19",
|
|
54
68
|
"@vitest/ui": "4.1.9",
|
|
55
|
-
"citty": "^0.2.2",
|
|
56
|
-
"defu": "^6.1.7",
|
|
57
|
-
"hono": "^4.12.27",
|
|
58
69
|
"langium": "3.5.0",
|
|
59
|
-
"remeda": "^2.37.0",
|
|
60
|
-
"tinyrainbow": "^3.1.0",
|
|
61
70
|
"tsdown": "^0.22.9",
|
|
62
71
|
"tsx": "4.22.5",
|
|
63
72
|
"turbo": "2.10.5",
|
|
64
73
|
"typescript": "6.0.3",
|
|
65
74
|
"type-fest": "^4.41.0",
|
|
66
|
-
"unctx": "^2.5.0",
|
|
67
75
|
"vitest": "4.1.9",
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"@likec4/config": "1.59.1",
|
|
71
|
-
"@likec4/devops": "1.59.1",
|
|
72
|
-
"@likec4/language-server": "1.59.1",
|
|
73
|
-
"@likec4/language-services": "1.59.1",
|
|
74
|
-
"@likec4/core": "1.59.1",
|
|
75
|
-
"@likec4/layouts": "1.59.1",
|
|
76
|
-
"@likec4/log": "1.59.1",
|
|
77
|
-
"@likec4/tsconfig": "1.59.1"
|
|
76
|
+
"@likec4/devops": "1.59.2",
|
|
77
|
+
"@likec4/tsconfig": "1.59.2"
|
|
78
78
|
},
|
|
79
79
|
"scripts": {
|
|
80
80
|
"typecheck": "tsc -b --verbose",
|
|
@@ -82,6 +82,7 @@
|
|
|
82
82
|
"preinspector": "tsdown",
|
|
83
83
|
"inspector": "DANGEROUSLY_OMIT_AUTH=1 LIKEC4_WORKSPACE=../../examples pnpx @modelcontextprotocol/inspector node bin/likec4-mcp.mjs",
|
|
84
84
|
"pack": "pnpm pack",
|
|
85
|
+
"smoke:pack": "node scripts/smoke-packed-install.mjs",
|
|
85
86
|
"clean": "likec4ops clean",
|
|
86
87
|
"test": "vitest run --no-isolate",
|
|
87
88
|
"vitest:ui": "vitest --no-isolate --ui",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"../../rolldown-runtime.mjs";import{assign as e,every as t,forEach as n,includes as r,isRegExp as i,isString as a,map as o,pickBy as s,some as c}from"lodash-es";function tokenLabel(e){return hasTokenLabel(e)?e.LABEL:e.name}function hasTokenLabel(e){return a(e.LABEL)&&e.LABEL!==``}var AbstractProduction=class{get definition(){return this._definition}set definition(e){this._definition=e}constructor(e){this._definition=e}accept(e){e.visit(this),n(this.definition,t=>{t.accept(e)})}},NonTerminal=class extends AbstractProduction{constructor(t){super([]),this.idx=1,e(this,s(t,e=>e!==void 0))}set definition(e){}get definition(){return this.referencedRule===void 0?[]:this.referencedRule.definition}accept(e){e.visit(this)}},Rule=class extends AbstractProduction{constructor(t){super(t.definition),this.orgText=``,e(this,s(t,e=>e!==void 0))}},Alternative=class extends AbstractProduction{constructor(t){super(t.definition),this.ignoreAmbiguities=!1,e(this,s(t,e=>e!==void 0))}},Option=class extends AbstractProduction{constructor(t){super(t.definition),this.idx=1,e(this,s(t,e=>e!==void 0))}},RepetitionMandatory=class extends AbstractProduction{constructor(t){super(t.definition),this.idx=1,e(this,s(t,e=>e!==void 0))}},RepetitionMandatoryWithSeparator=class extends AbstractProduction{constructor(t){super(t.definition),this.idx=1,e(this,s(t,e=>e!==void 0))}},Repetition=class extends AbstractProduction{constructor(t){super(t.definition),this.idx=1,e(this,s(t,e=>e!==void 0))}},RepetitionWithSeparator=class extends AbstractProduction{constructor(t){super(t.definition),this.idx=1,e(this,s(t,e=>e!==void 0))}},Alternation=class extends AbstractProduction{get definition(){return this._definition}set definition(e){this._definition=e}constructor(t){super(t.definition),this.idx=1,this.ignoreAmbiguities=!1,this.hasPredicates=!1,e(this,s(t,e=>e!==void 0))}},Terminal=class{constructor(t){this.idx=1,e(this,s(t,e=>e!==void 0))}accept(e){e.visit(this)}};function serializeGrammar(e){return o(e,serializeProduction)}function serializeProduction(e){function convertDefinition(e){return o(e,serializeProduction)}if(e instanceof NonTerminal){let t={type:`NonTerminal`,name:e.nonTerminalName,idx:e.idx};return a(e.label)&&(t.label=e.label),t}else if(e instanceof Alternative)return{type:`Alternative`,definition:convertDefinition(e.definition)};else if(e instanceof Option)return{type:`Option`,idx:e.idx,definition:convertDefinition(e.definition)};else if(e instanceof RepetitionMandatory)return{type:`RepetitionMandatory`,idx:e.idx,definition:convertDefinition(e.definition)};else if(e instanceof RepetitionMandatoryWithSeparator)return{type:`RepetitionMandatoryWithSeparator`,idx:e.idx,separator:serializeProduction(new Terminal({terminalType:e.separator})),definition:convertDefinition(e.definition)};else if(e instanceof RepetitionWithSeparator)return{type:`RepetitionWithSeparator`,idx:e.idx,separator:serializeProduction(new Terminal({terminalType:e.separator})),definition:convertDefinition(e.definition)};else if(e instanceof Repetition)return{type:`Repetition`,idx:e.idx,definition:convertDefinition(e.definition)};else if(e instanceof Alternation)return{type:`Alternation`,idx:e.idx,definition:convertDefinition(e.definition)};else if(e instanceof Terminal){let t={type:`Terminal`,name:e.terminalType.name,label:tokenLabel(e.terminalType),idx:e.idx};a(e.label)&&(t.terminalLabel=e.label);let n=e.terminalType.PATTERN;return e.terminalType.PATTERN&&(t.pattern=i(n)?n.source:n),t}else if(e instanceof Rule)return{type:`Rule`,name:e.name,orgText:e.orgText,definition:convertDefinition(e.definition)};else throw Error(`non exhaustive match`)}var GAstVisitor=class{visit(e){let t=e;switch(t.constructor){case NonTerminal:return this.visitNonTerminal(t);case Alternative:return this.visitAlternative(t);case Option:return this.visitOption(t);case RepetitionMandatory:return this.visitRepetitionMandatory(t);case RepetitionMandatoryWithSeparator:return this.visitRepetitionMandatoryWithSeparator(t);case RepetitionWithSeparator:return this.visitRepetitionWithSeparator(t);case Repetition:return this.visitRepetition(t);case Alternation:return this.visitAlternation(t);case Terminal:return this.visitTerminal(t);case Rule:return this.visitRule(t);default:throw Error(`non exhaustive match`)}}visitNonTerminal(e){}visitAlternative(e){}visitOption(e){}visitRepetition(e){}visitRepetitionMandatory(e){}visitRepetitionMandatoryWithSeparator(e){}visitRepetitionWithSeparator(e){}visitAlternation(e){}visitTerminal(e){}visitRule(e){}};function isSequenceProd(e){return e instanceof Alternative||e instanceof Option||e instanceof Repetition||e instanceof RepetitionMandatory||e instanceof RepetitionMandatoryWithSeparator||e instanceof RepetitionWithSeparator||e instanceof Terminal||e instanceof Rule}function isOptionalProd(e,n=[]){return e instanceof Option||e instanceof Repetition||e instanceof RepetitionWithSeparator?!0:e instanceof Alternation?c(e.definition,e=>isOptionalProd(e,n)):e instanceof NonTerminal&&r(n,e)?!1:e instanceof AbstractProduction?(e instanceof NonTerminal&&n.push(e),t(e.definition,e=>isOptionalProd(e,n))):!1}function isBranchingProd(e){return e instanceof Alternation}function getProductionDslName(e){if(e instanceof NonTerminal)return`SUBRULE`;if(e instanceof Option)return`OPTION`;if(e instanceof Alternation)return`OR`;if(e instanceof RepetitionMandatory)return`AT_LEAST_ONE`;if(e instanceof RepetitionMandatoryWithSeparator)return`AT_LEAST_ONE_SEP`;if(e instanceof RepetitionWithSeparator)return`MANY_SEP`;if(e instanceof Repetition)return`MANY`;if(e instanceof Terminal)return`CONSUME`;throw Error(`non exhaustive match`)}export{GAstVisitor as a,NonTerminal as c,RepetitionMandatory as d,RepetitionMandatoryWithSeparator as f,serializeGrammar as g,Terminal as h,isSequenceProd as i,Option as l,Rule as m,isBranchingProd as n,Alternation as o,RepetitionWithSeparator as p,isOptionalProd as r,Alternative as s,getProductionDslName as t,Repetition as u};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import"../../rolldown-runtime.mjs";function cc(e){return e.charCodeAt(0)}function insertToSet(e,t){Array.isArray(e)?e.forEach(function(e){t.push(e)}):t.push(e)}function addFlag(e,t){if(e[t]===!0)throw`duplicate flag `+t;e[t],e[t]=!0}function ASSERT_EXISTS(e){if(e===void 0)throw Error(`Internal Error - Should never get here!`);return!0}function ASSERT_NEVER_REACH_HERE(){throw Error(`Internal Error - Should never get here!`)}function isCharacter(e){return e.type===`Character`}const e=[];for(let t=cc(`0`);t<=cc(`9`);t++)e.push(t);const t=[cc(`_`)].concat(e);for(let e=cc(`a`);e<=cc(`z`);e++)t.push(e);for(let e=cc(`A`);e<=cc(`Z`);e++)t.push(e);const n=[cc(` `),cc(`\f`),cc(`
|
|
2
|
-
`),cc(`\r`),cc(` `),cc(`\v`),cc(` `),cc(`\xA0`),cc(` `),cc(` `),cc(` `),cc(` `),cc(` `),cc(` `),cc(` `),cc(` `),cc(` `),cc(` `),cc(` `),cc(` `),cc(`\u2028`),cc(`\u2029`),cc(` `),cc(` `),cc(` `),cc(``)],r=/[0-9a-fA-F]/,i=/[0-9]/,a=/[1-9]/;var RegExpParser=class{constructor(){this.idx=0,this.input=``,this.groupIdx=0}saveState(){return{idx:this.idx,input:this.input,groupIdx:this.groupIdx}}restoreState(e){this.idx=e.idx,this.input=e.input,this.groupIdx=e.groupIdx}pattern(e){this.idx=0,this.input=e,this.groupIdx=0,this.consumeChar(`/`);let t=this.disjunction();this.consumeChar(`/`);let n={type:`Flags`,loc:{begin:this.idx,end:e.length},global:!1,ignoreCase:!1,multiLine:!1,unicode:!1,sticky:!1};for(;this.isRegExpFlag();)switch(this.popChar()){case`g`:addFlag(n,`global`);break;case`i`:addFlag(n,`ignoreCase`);break;case`m`:addFlag(n,`multiLine`);break;case`u`:addFlag(n,`unicode`);break;case`y`:addFlag(n,`sticky`);break}if(this.idx!==this.input.length)throw Error(`Redundant input: `+this.input.substring(this.idx));return{type:`Pattern`,flags:n,value:t,loc:this.loc(0)}}disjunction(){let e=[],t=this.idx;for(e.push(this.alternative());this.peekChar()===`|`;)this.consumeChar(`|`),e.push(this.alternative());return{type:`Disjunction`,value:e,loc:this.loc(t)}}alternative(){let e=[],t=this.idx;for(;this.isTerm();)e.push(this.term());return{type:`Alternative`,value:e,loc:this.loc(t)}}term(){return this.isAssertion()?this.assertion():this.atom()}assertion(){let e=this.idx;switch(this.popChar()){case`^`:return{type:`StartAnchor`,loc:this.loc(e)};case`$`:return{type:`EndAnchor`,loc:this.loc(e)};case`\\`:switch(this.popChar()){case`b`:return{type:`WordBoundary`,loc:this.loc(e)};case`B`:return{type:`NonWordBoundary`,loc:this.loc(e)}}throw Error(`Invalid Assertion Escape`);case`(`:this.consumeChar(`?`);let t;switch(this.popChar()){case`=`:t=`Lookahead`;break;case`!`:t=`NegativeLookahead`;break}ASSERT_EXISTS(t);let n=this.disjunction();return this.consumeChar(`)`),{type:t,value:n,loc:this.loc(e)}}return ASSERT_NEVER_REACH_HERE()}quantifier(e=!1){let t,n=this.idx;switch(this.popChar()){case`*`:t={atLeast:0,atMost:1/0};break;case`+`:t={atLeast:1,atMost:1/0};break;case`?`:t={atLeast:0,atMost:1};break;case`{`:let n=this.integerIncludingZero();switch(this.popChar()){case`}`:t={atLeast:n,atMost:n};break;case`,`:let e;this.isDigit()?(e=this.integerIncludingZero(),t={atLeast:n,atMost:e}):t={atLeast:n,atMost:1/0},this.consumeChar(`}`);break}if(e===!0&&t===void 0)return;ASSERT_EXISTS(t);break}if((e!==!0||t!==void 0)&&ASSERT_EXISTS(t))return this.peekChar(0)===`?`?(this.consumeChar(`?`),t.greedy=!1):t.greedy=!0,t.type=`Quantifier`,t.loc=this.loc(n),t}atom(){let e,t=this.idx;switch(this.peekChar()){case`.`:e=this.dotAll();break;case`\\`:e=this.atomEscape();break;case`[`:e=this.characterClass();break;case`(`:e=this.group();break}return e===void 0&&this.isPatternCharacter()&&(e=this.patternCharacter()),ASSERT_EXISTS(e)?(e.loc=this.loc(t),this.isQuantifier()&&(e.quantifier=this.quantifier()),e):ASSERT_NEVER_REACH_HERE()}dotAll(){return this.consumeChar(`.`),{type:`Set`,complement:!0,value:[cc(`
|
|
3
|
-
`),cc(`\r`),cc(`\u2028`),cc(`\u2029`)]}}atomEscape(){switch(this.consumeChar(`\\`),this.peekChar()){case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:return this.decimalEscapeAtom();case`d`:case`D`:case`s`:case`S`:case`w`:case`W`:return this.characterClassEscape();case`f`:case`n`:case`r`:case`t`:case`v`:return this.controlEscapeAtom();case`c`:return this.controlLetterEscapeAtom();case`0`:return this.nulCharacterAtom();case`x`:return this.hexEscapeSequenceAtom();case`u`:return this.regExpUnicodeEscapeSequenceAtom();default:return this.identityEscapeAtom()}}decimalEscapeAtom(){return{type:`GroupBackReference`,value:this.positiveInteger()}}characterClassEscape(){let r,i=!1;switch(this.popChar()){case`d`:r=e;break;case`D`:r=e,i=!0;break;case`s`:r=n;break;case`S`:r=n,i=!0;break;case`w`:r=t;break;case`W`:r=t,i=!0;break}return ASSERT_EXISTS(r)?{type:`Set`,value:r,complement:i}:ASSERT_NEVER_REACH_HERE()}controlEscapeAtom(){let e;switch(this.popChar()){case`f`:e=cc(`\f`);break;case`n`:e=cc(`
|
|
4
|
-
`);break;case`r`:e=cc(`\r`);break;case`t`:e=cc(` `);break;case`v`:e=cc(`\v`);break}return ASSERT_EXISTS(e)?{type:`Character`,value:e}:ASSERT_NEVER_REACH_HERE()}controlLetterEscapeAtom(){this.consumeChar(`c`);let e=this.popChar();if(/[a-zA-Z]/.test(e)===!1)throw Error(`Invalid `);return{type:`Character`,value:e.toUpperCase().charCodeAt(0)-64}}nulCharacterAtom(){return this.consumeChar(`0`),{type:`Character`,value:cc(`\0`)}}hexEscapeSequenceAtom(){return this.consumeChar(`x`),this.parseHexDigits(2)}regExpUnicodeEscapeSequenceAtom(){return this.consumeChar(`u`),this.parseHexDigits(4)}identityEscapeAtom(){return{type:`Character`,value:cc(this.popChar())}}classPatternCharacterAtom(){switch(this.peekChar()){case`
|
|
5
|
-
`:case`\r`:case`\u2028`:case`\u2029`:case`\\`:case`]`:throw Error(`TBD`);default:return{type:`Character`,value:cc(this.popChar())}}}characterClass(){let e=[],t=!1;for(this.consumeChar(`[`),this.peekChar(0)===`^`&&(this.consumeChar(`^`),t=!0);this.isClassAtom();){let t=this.classAtom();if(t.type,isCharacter(t)&&this.isRangeDash()){this.consumeChar(`-`);let n=this.classAtom();if(n.type,isCharacter(n)){if(n.value<t.value)throw Error(`Range out of order in character class`);e.push({from:t.value,to:n.value})}else insertToSet(t.value,e),e.push(cc(`-`)),insertToSet(n.value,e)}else insertToSet(t.value,e)}return this.consumeChar(`]`),{type:`Set`,complement:t,value:e}}classAtom(){switch(this.peekChar()){case`]`:case`
|
|
6
|
-
`:case`\r`:case`\u2028`:case`\u2029`:throw Error(`TBD`);case`\\`:return this.classEscape();default:return this.classPatternCharacterAtom()}}classEscape(){switch(this.consumeChar(`\\`),this.peekChar()){case`b`:return this.consumeChar(`b`),{type:`Character`,value:cc(`\b`)};case`d`:case`D`:case`s`:case`S`:case`w`:case`W`:return this.characterClassEscape();case`f`:case`n`:case`r`:case`t`:case`v`:return this.controlEscapeAtom();case`c`:return this.controlLetterEscapeAtom();case`0`:return this.nulCharacterAtom();case`x`:return this.hexEscapeSequenceAtom();case`u`:return this.regExpUnicodeEscapeSequenceAtom();default:return this.identityEscapeAtom()}}group(){let e=!0;switch(this.consumeChar(`(`),this.peekChar(0)){case`?`:this.consumeChar(`?`),this.consumeChar(`:`),e=!1;break;default:this.groupIdx++;break}let t=this.disjunction();this.consumeChar(`)`);let n={type:`Group`,capturing:e,value:t};return e&&(n.idx=this.groupIdx),n}positiveInteger(){let e=this.popChar();if(a.test(e)===!1)throw Error(`Expecting a positive integer`);for(;i.test(this.peekChar(0));)e+=this.popChar();return parseInt(e,10)}integerIncludingZero(){let e=this.popChar();if(i.test(e)===!1)throw Error(`Expecting an integer`);for(;i.test(this.peekChar(0));)e+=this.popChar();return parseInt(e,10)}patternCharacter(){let e=this.popChar();switch(e){case`
|
|
7
|
-
`:case`\r`:case`\u2028`:case`\u2029`:case`^`:case`$`:case`\\`:case`.`:case`*`:case`+`:case`?`:case`(`:case`)`:case`[`:case`|`:throw Error(`TBD`);default:return{type:`Character`,value:cc(e)}}}isRegExpFlag(){switch(this.peekChar(0)){case`g`:case`i`:case`m`:case`u`:case`y`:return!0;default:return!1}}isRangeDash(){return this.peekChar()===`-`&&this.isClassAtom(1)}isDigit(){return i.test(this.peekChar(0))}isClassAtom(e=0){switch(this.peekChar(e)){case`]`:case`
|
|
8
|
-
`:case`\r`:case`\u2028`:case`\u2029`:return!1;default:return!0}}isTerm(){return this.isAtom()||this.isAssertion()}isAtom(){if(this.isPatternCharacter())return!0;switch(this.peekChar(0)){case`.`:case`\\`:case`[`:case`(`:return!0;default:return!1}}isAssertion(){switch(this.peekChar(0)){case`^`:case`$`:return!0;case`\\`:switch(this.peekChar(1)){case`b`:case`B`:return!0;default:return!1}case`(`:return this.peekChar(1)===`?`&&(this.peekChar(2)===`=`||this.peekChar(2)===`!`);default:return!1}}isQuantifier(){let e=this.saveState();try{return this.quantifier(!0)!==void 0}catch{return!1}finally{this.restoreState(e)}}isPatternCharacter(){switch(this.peekChar()){case`^`:case`$`:case`\\`:case`.`:case`*`:case`+`:case`?`:case`(`:case`)`:case`[`:case`|`:case`/`:case`
|
|
9
|
-
`:case`\r`:case`\u2028`:case`\u2029`:return!1;default:return!0}}parseHexDigits(e){let t=``;for(let n=0;n<e;n++){let e=this.popChar();if(r.test(e)===!1)throw Error(`Expecting a HexDecimal digits`);t+=e}return{type:`Character`,value:parseInt(t,16)}}peekChar(e=0){return this.input[this.idx+e]}popChar(){let e=this.peekChar(0);return this.consumeChar(void 0),e}consumeChar(e){if(e!==void 0&&this.input[this.idx]!==e)throw Error(`Expected: '`+e+`' but found: '`+this.input[this.idx]+`' at offset: `+this.idx);if(this.idx>=this.input.length)throw Error(`Unexpected end of input`);this.idx++}loc(e){return{begin:e,end:this.idx}}},BaseRegExpVisitor=class{visitChildren(e){for(let t in e){let n=e[t];e.hasOwnProperty(t)&&(n.type===void 0?Array.isArray(n)&&n.forEach(e=>{this.visit(e)},this):this.visit(n))}}visit(e){switch(e.type){case`Pattern`:this.visitPattern(e);break;case`Flags`:this.visitFlags(e);break;case`Disjunction`:this.visitDisjunction(e);break;case`Alternative`:this.visitAlternative(e);break;case`StartAnchor`:this.visitStartAnchor(e);break;case`EndAnchor`:this.visitEndAnchor(e);break;case`WordBoundary`:this.visitWordBoundary(e);break;case`NonWordBoundary`:this.visitNonWordBoundary(e);break;case`Lookahead`:this.visitLookahead(e);break;case`NegativeLookahead`:this.visitNegativeLookahead(e);break;case`Character`:this.visitCharacter(e);break;case`Set`:this.visitSet(e);break;case`Group`:this.visitGroup(e);break;case`GroupBackReference`:this.visitGroupBackReference(e);break;case`Quantifier`:this.visitQuantifier(e);break}this.visitChildren(e)}visitPattern(e){}visitFlags(e){}visitDisjunction(e){}visitAlternative(e){}visitStartAnchor(e){}visitEndAnchor(e){}visitWordBoundary(e){}visitNonWordBoundary(e){}visitLookahead(e){}visitNegativeLookahead(e){}visitCharacter(e){}visitSet(e){}visitGroup(e){}visitGroupBackReference(e){}visitQuantifier(e){}};export{RegExpParser as n,BaseRegExpVisitor as t};
|