@semacode/cli 1.5.14 → 1.5.16
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/README.md +2 -1
- package/dist/index.js +76 -43
- package/package.json +26 -35
- package/semacode-cli-1.3.1.tgz +0 -0
- package/src/angular-consumer-standalone.ts +312 -0
- package/src/cpp-symbols.ts +82 -0
- package/src/docs.ts +535 -0
- package/src/dotnet-http.ts +355 -0
- package/src/drift.ts +4933 -0
- package/src/go-http.ts +118 -0
- package/src/importador.ts +3891 -0
- package/src/index.ts +5641 -0
- package/src/java-http.ts +247 -0
- package/src/lua-symbols.ts +114 -0
- package/src/php-symbols.ts +462 -0
- package/src/projeto.ts +862 -0
- package/src/python-http.ts +258 -0
- package/src/rust-http.ts +125 -0
- package/src/tipos.ts +24 -0
- package/src/typescript-http.ts +1076 -0
- package/tsconfig.json +20 -0
- package/AGENTS.md +0 -272
- package/LICENSE +0 -22
- package/SEMA_BRIEF.curto.txt +0 -9
- package/SEMA_BRIEF.md +0 -63
- package/SEMA_BRIEF.micro.txt +0 -7
- package/SEMA_INDEX.json +0 -799
- package/dist/angular-consumer-standalone.d.ts +0 -6
- package/dist/angular-consumer-standalone.js.map +0 -1
- package/dist/cpp-symbols.d.ts +0 -10
- package/dist/cpp-symbols.js.map +0 -1
- package/dist/docs.d.ts +0 -56
- package/dist/docs.js.map +0 -1
- package/dist/dotnet-http.d.ts +0 -23
- package/dist/dotnet-http.js.map +0 -1
- package/dist/drift.d.ts +0 -225
- package/dist/drift.js.map +0 -1
- package/dist/go-http.d.ts +0 -23
- package/dist/go-http.js.map +0 -1
- package/dist/importador.d.ts +0 -31
- package/dist/importador.js.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js.map +0 -1
- package/dist/java-http.d.ts +0 -23
- package/dist/java-http.js.map +0 -1
- package/dist/lua-symbols.d.ts +0 -10
- package/dist/lua-symbols.js.map +0 -1
- package/dist/php-symbols.d.ts +0 -24
- package/dist/php-symbols.js.map +0 -1
- package/dist/projeto.d.ts +0 -53
- package/dist/projeto.js.map +0 -1
- package/dist/python-http.d.ts +0 -23
- package/dist/python-http.js.map +0 -1
- package/dist/rust-http.d.ts +0 -23
- package/dist/rust-http.js.map +0 -1
- package/dist/tipos.d.ts +0 -3
- package/dist/tipos.js.map +0 -1
- package/dist/typescript-http.d.ts +0 -35
- package/dist/typescript-http.js.map +0 -1
- package/docs/AGENT_STARTER.md +0 -102
- package/docs/cli.md +0 -117
- package/docs/como-ensinar-a-sema-para-ia.md +0 -149
- package/docs/deploy.md +0 -70
- package/docs/documentacao.md +0 -63
- package/docs/env.md +0 -56
- package/docs/extensao-vscode.md +0 -45
- package/docs/fluxo-pratico-ia-sema.md +0 -177
- package/docs/instalacao-e-primeiro-uso.md +0 -112
- package/docs/integracao-com-ia.md +0 -101
- package/docs/mcp.md +0 -53
- package/docs/pagamento-ponta-a-ponta.md +0 -155
- package/docs/persistencia-vendor-first.md +0 -145
- package/docs/prompt-base-ia-sema.md +0 -104
- package/docs/rollback.md +0 -47
- package/docs/sintaxe.md +0 -410
- package/exemplos/agendamento.sema +0 -106
- package/exemplos/assinatura.sema +0 -136
- package/exemplos/auditoria.sema +0 -88
- package/exemplos/autenticacao.sema +0 -125
- package/exemplos/automacao.sema +0 -107
- package/exemplos/cadastro_usuario.sema +0 -54
- package/exemplos/calculadora.sema +0 -78
- package/exemplos/crud_simples.sema +0 -89
- package/exemplos/estoque.sema +0 -126
- package/exemplos/exportacao.sema +0 -94
- package/exemplos/fila.sema +0 -131
- package/exemplos/integracao_externa.sema +0 -94
- package/exemplos/multi_tenant.sema +0 -140
- package/exemplos/notificacao.sema +0 -98
- package/exemplos/operacao_estrategia.sema +0 -402
- package/exemplos/pagamento.sema +0 -222
- package/exemplos/pagamento_dominio.sema +0 -35
- package/exemplos/pedido.sema +0 -119
- package/exemplos/permissao.sema +0 -121
- package/exemplos/persistencia_vendor_first.sema +0 -86
- package/exemplos/relatorio.sema +0 -93
- package/exemplos/testes_embutidos.sema +0 -45
- package/exemplos/tratamento_erro.sema +0 -157
- package/exemplos/upload_arquivo.sema +0 -93
- package/exemplos/webhook.sema +0 -96
- package/llms-full.txt +0 -34
- package/llms.txt +0 -17
- package/node_modules/@sema/gerador-css/dist/index.d.ts +0 -3
- package/node_modules/@sema/gerador-css/dist/index.js +0 -592
- package/node_modules/@sema/gerador-css/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-css/package.json +0 -7
- package/node_modules/@sema/gerador-dart/dist/index.d.ts +0 -3
- package/node_modules/@sema/gerador-dart/dist/index.js +0 -44
- package/node_modules/@sema/gerador-dart/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-dart/package.json +0 -7
- package/node_modules/@sema/gerador-html/dist/index.d.ts +0 -3
- package/node_modules/@sema/gerador-html/dist/index.js +0 -163
- package/node_modules/@sema/gerador-html/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-html/package.json +0 -7
- package/node_modules/@sema/gerador-javascript/dist/index.d.ts +0 -3
- package/node_modules/@sema/gerador-javascript/dist/index.js +0 -421
- package/node_modules/@sema/gerador-javascript/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-javascript/package.json +0 -7
- package/node_modules/@sema/gerador-lua/dist/index.d.ts +0 -3
- package/node_modules/@sema/gerador-lua/dist/index.js +0 -328
- package/node_modules/@sema/gerador-lua/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-lua/package.json +0 -7
- package/node_modules/@sema/gerador-python/dist/index.d.ts +0 -6
- package/node_modules/@sema/gerador-python/dist/index.js +0 -729
- package/node_modules/@sema/gerador-python/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-python/package.json +0 -7
- package/node_modules/@sema/gerador-typescript/dist/index.d.ts +0 -6
- package/node_modules/@sema/gerador-typescript/dist/index.js +0 -793
- package/node_modules/@sema/gerador-typescript/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-typescript/package.json +0 -7
- package/node_modules/@sema/nucleo/dist/ast/tipos.d.ts +0 -125
- package/node_modules/@sema/nucleo/dist/ast/tipos.js +0 -2
- package/node_modules/@sema/nucleo/dist/ast/tipos.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/diagnosticos/index.d.ts +0 -21
- package/node_modules/@sema/nucleo/dist/diagnosticos/index.js +0 -12
- package/node_modules/@sema/nucleo/dist/diagnosticos/index.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/formatador/index.d.ts +0 -9
- package/node_modules/@sema/nucleo/dist/formatador/index.js +0 -487
- package/node_modules/@sema/nucleo/dist/formatador/index.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/index.d.ts +0 -35
- package/node_modules/@sema/nucleo/dist/index.js +0 -96
- package/node_modules/@sema/nucleo/dist/index.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/ir/conversor.d.ts +0 -5
- package/node_modules/@sema/nucleo/dist/ir/conversor.js +0 -1058
- package/node_modules/@sema/nucleo/dist/ir/conversor.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/ir/modelos.d.ts +0 -377
- package/node_modules/@sema/nucleo/dist/ir/modelos.js +0 -2
- package/node_modules/@sema/nucleo/dist/ir/modelos.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/lexer/lexer.d.ts +0 -7
- package/node_modules/@sema/nucleo/dist/lexer/lexer.js +0 -122
- package/node_modules/@sema/nucleo/dist/lexer/lexer.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/lexer/tokens.d.ts +0 -8
- package/node_modules/@sema/nucleo/dist/lexer/tokens.js +0 -82
- package/node_modules/@sema/nucleo/dist/lexer/tokens.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/parser/parser.d.ts +0 -9
- package/node_modules/@sema/nucleo/dist/parser/parser.js +0 -807
- package/node_modules/@sema/nucleo/dist/parser/parser.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/persistencia/contratos.d.ts +0 -39
- package/node_modules/@sema/nucleo/dist/persistencia/contratos.js +0 -294
- package/node_modules/@sema/nucleo/dist/persistencia/contratos.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/analisador.d.ts +0 -58
- package/node_modules/@sema/nucleo/dist/semantico/analisador.js +0 -1912
- package/node_modules/@sema/nucleo/dist/semantico/analisador.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/estruturas.d.ts +0 -104
- package/node_modules/@sema/nucleo/dist/semantico/estruturas.js +0 -445
- package/node_modules/@sema/nucleo/dist/semantico/estruturas.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/seguranca.d.ts +0 -91
- package/node_modules/@sema/nucleo/dist/semantico/seguranca.js +0 -258
- package/node_modules/@sema/nucleo/dist/semantico/seguranca.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/util/arquivos.d.ts +0 -2
- package/node_modules/@sema/nucleo/dist/util/arquivos.js +0 -25
- package/node_modules/@sema/nucleo/dist/util/arquivos.js.map +0 -1
- package/node_modules/@sema/nucleo/package.json +0 -7
- package/node_modules/@sema/padroes/dist/index.d.ts +0 -25
- package/node_modules/@sema/padroes/dist/index.js +0 -316
- package/node_modules/@sema/padroes/dist/index.js.map +0 -1
- package/node_modules/@sema/padroes/package.json +0 -7
package/src/java-http.ts
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
export interface ParametroRotaJava {
|
|
2
|
+
nome: string;
|
|
3
|
+
tipoSema: "Texto" | "Inteiro" | "Decimal" | "Id";
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface SimboloJavaExtraido {
|
|
7
|
+
simbolo: string;
|
|
8
|
+
retorno?: string;
|
|
9
|
+
parametros: Array<{ nome: string; tipoTexto?: string; obrigatorio: boolean }>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface RotaJavaExtraida {
|
|
13
|
+
origem: "java";
|
|
14
|
+
metodo: string;
|
|
15
|
+
caminho: string;
|
|
16
|
+
simbolo: string;
|
|
17
|
+
parametros: ParametroRotaJava[];
|
|
18
|
+
retorno?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const METODOS_HTTP = new Set(["GET", "POST", "PUT", "PATCH", "DELETE"]);
|
|
22
|
+
|
|
23
|
+
function contarChar(texto: string, alvo: string): number {
|
|
24
|
+
return [...texto].filter((char) => char === alvo).length;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function juntarCaminho(base: string | undefined, sufixo: string | undefined): string {
|
|
28
|
+
const partes = [base, sufixo]
|
|
29
|
+
.map((parte) => (parte ?? "").trim())
|
|
30
|
+
.filter(Boolean)
|
|
31
|
+
.map((parte) => parte.replace(/^\/+|\/+$/g, ""));
|
|
32
|
+
return `/${partes.join("/")}`.replace(/\/+/g, "/");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function extrairParametrosAssinaturaJava(assinatura: string): Array<{ nome: string; tipoTexto?: string; obrigatorio: boolean }> {
|
|
36
|
+
return assinatura.split(",").map((parametroBruto) => {
|
|
37
|
+
const parametro = parametroBruto.trim();
|
|
38
|
+
if (!parametro) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
const limpo = parametro.replace(/^@\w+(?:\([^)]*\))?\s*/g, "").trim();
|
|
42
|
+
const partes = limpo.split(/\s+/).filter(Boolean);
|
|
43
|
+
if (partes.length < 2) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
nome: partes.at(-1)!,
|
|
48
|
+
tipoTexto: partes.slice(0, -1).join(" "),
|
|
49
|
+
obrigatorio: true,
|
|
50
|
+
};
|
|
51
|
+
}).filter((item): item is NonNullable<typeof item> => Boolean(item));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function mapearTipoJava(tipo?: string): ParametroRotaJava["tipoSema"] {
|
|
55
|
+
const normalizado = (tipo ?? "").toLowerCase();
|
|
56
|
+
if (/(^|\.)(int|integer|long|short)$/.test(normalizado)) {
|
|
57
|
+
return "Inteiro";
|
|
58
|
+
}
|
|
59
|
+
if (/(^|\.)(float|double|bigdecimal|decimal)$/.test(normalizado)) {
|
|
60
|
+
return "Decimal";
|
|
61
|
+
}
|
|
62
|
+
if (/uuid|id$/i.test(normalizado)) {
|
|
63
|
+
return "Id";
|
|
64
|
+
}
|
|
65
|
+
return "Texto";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function extrairAtributosJava(linhas: string[], inicio: number): { atributos: string[]; proximoIndice: number } {
|
|
69
|
+
const atributos: string[] = [];
|
|
70
|
+
let indice = inicio;
|
|
71
|
+
|
|
72
|
+
while (indice < linhas.length) {
|
|
73
|
+
const linha = linhas[indice]!.trim();
|
|
74
|
+
if (!linha.startsWith("@")) {
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
let atual = linha;
|
|
78
|
+
let saldo = contarChar(linha, "(") - contarChar(linha, ")");
|
|
79
|
+
while (saldo > 0 && indice + 1 < linhas.length) {
|
|
80
|
+
indice += 1;
|
|
81
|
+
const complemento = linhas[indice]!.trim();
|
|
82
|
+
atual += ` ${complemento}`;
|
|
83
|
+
saldo += contarChar(complemento, "(") - contarChar(complemento, ")");
|
|
84
|
+
}
|
|
85
|
+
atributos.push(atual);
|
|
86
|
+
indice += 1;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return { atributos, proximoIndice: indice };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function extrairCaminhoJava(atributo: string): string | undefined {
|
|
93
|
+
return atributo.match(/"([^"]+)"/)?.[1];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function extrairMetodosJava(atributo: string): string[] {
|
|
97
|
+
const direto = atributo.match(/@(Get|Post|Put|Patch|Delete)Mapping/i)?.[1]?.toUpperCase();
|
|
98
|
+
if (direto && METODOS_HTTP.has(direto)) {
|
|
99
|
+
return [direto];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const requestMethod = [...atributo.matchAll(/RequestMethod\.(GET|POST|PUT|PATCH|DELETE)/gi)]
|
|
103
|
+
.map((match) => match[1]!.toUpperCase())
|
|
104
|
+
.filter((metodo) => METODOS_HTTP.has(metodo));
|
|
105
|
+
if (requestMethod.length > 0) {
|
|
106
|
+
return [...new Set(requestMethod)];
|
|
107
|
+
}
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function normalizarCaminhoJava(caminho: string): string {
|
|
112
|
+
return caminho.replace(/\{([^}:]+):[^}]+\}/g, "{$1}").replace(/\/+/g, "/");
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function extrairParametrosRotaJava(caminho: string, assinatura: string): ParametroRotaJava[] {
|
|
116
|
+
const assinaturaMap = new Map<string, string>();
|
|
117
|
+
for (const parametro of extrairParametrosAssinaturaJava(assinatura)) {
|
|
118
|
+
assinaturaMap.set(parametro.nome, parametro.tipoTexto ?? "");
|
|
119
|
+
}
|
|
120
|
+
return [...caminho.matchAll(/\{([^}:]+)(?::[^}]+)?\}/g)].map((match) => {
|
|
121
|
+
const nome = match[1]!;
|
|
122
|
+
return {
|
|
123
|
+
nome,
|
|
124
|
+
tipoSema: mapearTipoJava(assinaturaMap.get(nome)),
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function extrairSimbolosJava(codigo: string): SimboloJavaExtraido[] {
|
|
130
|
+
const simbolos = new Map<string, SimboloJavaExtraido>();
|
|
131
|
+
const linhas = codigo.split(/\r?\n/);
|
|
132
|
+
const pilhaClasses: Array<{ nome: string; profundidade: number }> = [];
|
|
133
|
+
let profundidade = 0;
|
|
134
|
+
|
|
135
|
+
for (let indice = 0; indice < linhas.length; indice += 1) {
|
|
136
|
+
const linhaOriginal = linhas[indice]!;
|
|
137
|
+
const { atributos, proximoIndice } = extrairAtributosJava(linhas, indice);
|
|
138
|
+
if (atributos.length > 0) {
|
|
139
|
+
indice = proximoIndice;
|
|
140
|
+
}
|
|
141
|
+
const linha = (linhas[indice] ?? linhaOriginal).trim();
|
|
142
|
+
if (!linha || linha.startsWith("//")) {
|
|
143
|
+
profundidade += contarChar(linhaOriginal, "{") - contarChar(linhaOriginal, "}");
|
|
144
|
+
while (pilhaClasses.length > 0 && profundidade < pilhaClasses[pilhaClasses.length - 1]!.profundidade) {
|
|
145
|
+
pilhaClasses.pop();
|
|
146
|
+
}
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const classe = linha.match(/\bclass\s+([A-Za-z_]\w*)/);
|
|
151
|
+
if (classe) {
|
|
152
|
+
pilhaClasses.push({ nome: classe[1]!, profundidade: profundidade + 1 });
|
|
153
|
+
profundidade += contarChar(linha, "{") - contarChar(linha, "}");
|
|
154
|
+
while (pilhaClasses.length > 0 && profundidade < pilhaClasses[pilhaClasses.length - 1]!.profundidade) {
|
|
155
|
+
pilhaClasses.pop();
|
|
156
|
+
}
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const metodo = linha.match(/\b(?:public|protected|private)\s+(?:static\s+|final\s+|synchronized\s+)*([A-Za-z0-9_<>,.?[\]\s]+)\s+([A-Za-z_]\w*)\s*\(([^)]*)\)/);
|
|
161
|
+
if (metodo) {
|
|
162
|
+
const classeAtual = pilhaClasses[pilhaClasses.length - 1];
|
|
163
|
+
const simbolo = classeAtual ? `${classeAtual.nome}.${metodo[2]!}` : metodo[2]!;
|
|
164
|
+
simbolos.set(simbolo, {
|
|
165
|
+
simbolo,
|
|
166
|
+
retorno: metodo[1]!.trim(),
|
|
167
|
+
parametros: extrairParametrosAssinaturaJava(metodo[3]!),
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
profundidade += contarChar(linha, "{") - contarChar(linha, "}");
|
|
172
|
+
while (pilhaClasses.length > 0 && profundidade < pilhaClasses[pilhaClasses.length - 1]!.profundidade) {
|
|
173
|
+
pilhaClasses.pop();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return [...simbolos.values()];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function extrairRotasJava(codigo: string): RotaJavaExtraida[] {
|
|
181
|
+
const rotas = new Map<string, RotaJavaExtraida>();
|
|
182
|
+
const linhas = codigo.split(/\r?\n/);
|
|
183
|
+
const pilhaClasses: Array<{ nome: string; profundidade: number; rotaBase?: string; rest: boolean }> = [];
|
|
184
|
+
let profundidade = 0;
|
|
185
|
+
|
|
186
|
+
for (let indice = 0; indice < linhas.length; indice += 1) {
|
|
187
|
+
const linhaOriginal = linhas[indice]!;
|
|
188
|
+
const { atributos, proximoIndice } = extrairAtributosJava(linhas, indice);
|
|
189
|
+
if (atributos.length > 0) {
|
|
190
|
+
indice = proximoIndice;
|
|
191
|
+
}
|
|
192
|
+
const linha = (linhas[indice] ?? linhaOriginal).trim();
|
|
193
|
+
if (!linha || linha.startsWith("//")) {
|
|
194
|
+
profundidade += contarChar(linhaOriginal, "{") - contarChar(linhaOriginal, "}");
|
|
195
|
+
while (pilhaClasses.length > 0 && profundidade < pilhaClasses[pilhaClasses.length - 1]!.profundidade) {
|
|
196
|
+
pilhaClasses.pop();
|
|
197
|
+
}
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const classe = linha.match(/\bclass\s+([A-Za-z_]\w*)/);
|
|
202
|
+
if (classe) {
|
|
203
|
+
const rotaBase = atributos
|
|
204
|
+
.filter((atributo) => /@RequestMapping/i.test(atributo))
|
|
205
|
+
.map((atributo) => extrairCaminhoJava(atributo))
|
|
206
|
+
.find(Boolean);
|
|
207
|
+
pilhaClasses.push({
|
|
208
|
+
nome: classe[1]!,
|
|
209
|
+
profundidade: profundidade + 1,
|
|
210
|
+
rotaBase,
|
|
211
|
+
rest: atributos.some((atributo) => /@RestController/i.test(atributo)),
|
|
212
|
+
});
|
|
213
|
+
profundidade += contarChar(linha, "{") - contarChar(linha, "}");
|
|
214
|
+
while (pilhaClasses.length > 0 && profundidade < pilhaClasses[pilhaClasses.length - 1]!.profundidade) {
|
|
215
|
+
pilhaClasses.pop();
|
|
216
|
+
}
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const classeAtual = pilhaClasses[pilhaClasses.length - 1];
|
|
221
|
+
const metodo = linha.match(/\b(?:public|protected)\s+(?:static\s+|final\s+)*([A-Za-z0-9_<>,.?[\]\s]+)\s+([A-Za-z_]\w*)\s*\(([^)]*)\)/);
|
|
222
|
+
if (classeAtual && metodo) {
|
|
223
|
+
for (const atributo of atributos.filter((item) => /@(Get|Post|Put|Patch|Delete)Mapping|@RequestMapping/i.test(item))) {
|
|
224
|
+
const metodos = extrairMetodosJava(atributo);
|
|
225
|
+
const caminho = normalizarCaminhoJava(juntarCaminho(classeAtual.rotaBase, extrairCaminhoJava(atributo)));
|
|
226
|
+
for (const httpMetodo of metodos) {
|
|
227
|
+
const registro: RotaJavaExtraida = {
|
|
228
|
+
origem: "java",
|
|
229
|
+
metodo: httpMetodo,
|
|
230
|
+
caminho,
|
|
231
|
+
simbolo: `${classeAtual.nome}.${metodo[2]!}`,
|
|
232
|
+
parametros: extrairParametrosRotaJava(caminho, metodo[3] ?? ""),
|
|
233
|
+
retorno: metodo[1]!.trim(),
|
|
234
|
+
};
|
|
235
|
+
rotas.set(`${registro.metodo}:${registro.caminho}:${registro.simbolo}`, registro);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
profundidade += contarChar(linha, "{") - contarChar(linha, "}");
|
|
241
|
+
while (pilhaClasses.length > 0 && profundidade < pilhaClasses[pilhaClasses.length - 1]!.profundidade) {
|
|
242
|
+
pilhaClasses.pop();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return [...rotas.values()];
|
|
247
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
export interface ParametroLuaExtraido {
|
|
2
|
+
nome: string;
|
|
3
|
+
obrigatorio: boolean;
|
|
4
|
+
tipoTexto?: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface SimboloLuaExtraido {
|
|
8
|
+
simbolo: string;
|
|
9
|
+
parametros: ParametroLuaExtraido[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const PALAVRAS_RESERVADAS_LUA = new Set([
|
|
13
|
+
"and",
|
|
14
|
+
"break",
|
|
15
|
+
"do",
|
|
16
|
+
"else",
|
|
17
|
+
"elseif",
|
|
18
|
+
"end",
|
|
19
|
+
"false",
|
|
20
|
+
"for",
|
|
21
|
+
"function",
|
|
22
|
+
"goto",
|
|
23
|
+
"if",
|
|
24
|
+
"in",
|
|
25
|
+
"local",
|
|
26
|
+
"nil",
|
|
27
|
+
"not",
|
|
28
|
+
"or",
|
|
29
|
+
"repeat",
|
|
30
|
+
"return",
|
|
31
|
+
"then",
|
|
32
|
+
"true",
|
|
33
|
+
"until",
|
|
34
|
+
"while",
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
function removerComentariosLua(codigo: string): string {
|
|
38
|
+
return codigo
|
|
39
|
+
.replace(/--\[\[[\s\S]*?\]\]/g, "")
|
|
40
|
+
.replace(/--[^\r\n]*/g, "");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function normalizarSimboloLua(simbolo: string): string {
|
|
44
|
+
return simbolo
|
|
45
|
+
.replace(/:/g, ".")
|
|
46
|
+
.replace(/\.+/g, ".")
|
|
47
|
+
.replace(/^\.+|\.+$/g, "");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function simboloLuaValido(simbolo: string): boolean {
|
|
51
|
+
const partes = simbolo.split(".").filter(Boolean);
|
|
52
|
+
return partes.length > 0
|
|
53
|
+
&& partes.every((parte) => /^[A-Za-z_]\w*$/.test(parte) && !PALAVRAS_RESERVADAS_LUA.has(parte));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function dividirParametrosLua(parametros: string): ParametroLuaExtraido[] {
|
|
57
|
+
return parametros
|
|
58
|
+
.split(",")
|
|
59
|
+
.map((item) => item.trim())
|
|
60
|
+
.filter(Boolean)
|
|
61
|
+
.filter((item) => item !== "..." && item !== "self")
|
|
62
|
+
.map((item) => item.replace(/\s*=.*$/, "").trim())
|
|
63
|
+
.filter((item) => /^[A-Za-z_]\w*$/.test(item))
|
|
64
|
+
.map((nome) => ({
|
|
65
|
+
nome,
|
|
66
|
+
obrigatorio: true,
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function registrarSimboloLua(
|
|
71
|
+
simbolos: Map<string, SimboloLuaExtraido>,
|
|
72
|
+
simboloBruto: string,
|
|
73
|
+
parametros: string,
|
|
74
|
+
): void {
|
|
75
|
+
const simbolo = normalizarSimboloLua(simboloBruto);
|
|
76
|
+
if (!simboloLuaValido(simbolo)) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
simbolos.set(simbolo, {
|
|
80
|
+
simbolo,
|
|
81
|
+
parametros: dividirParametrosLua(parametros),
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function extrairSimbolosLua(codigo: string): SimboloLuaExtraido[] {
|
|
86
|
+
const texto = removerComentariosLua(codigo);
|
|
87
|
+
const simbolos = new Map<string, SimboloLuaExtraido>();
|
|
88
|
+
|
|
89
|
+
for (const match of texto.matchAll(/(?:^|\n)\s*(?:local\s+)?function\s+([A-Za-z_]\w*(?:(?:\.|:)[A-Za-z_]\w*)*)\s*\(([^)]*)\)/g)) {
|
|
90
|
+
registrarSimboloLua(simbolos, match[1]!, match[2] ?? "");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
for (const match of texto.matchAll(/(?:^|\n)\s*(?:local\s+)?([A-Za-z_]\w*)\s*=\s*\{([\s\S]*?)^\s*\}/gm)) {
|
|
94
|
+
const tabela = match[1]!;
|
|
95
|
+
const corpo = match[2] ?? "";
|
|
96
|
+
for (const membro of corpo.matchAll(/(?:^|[\s,{])([A-Za-z_]\w*)\s*=\s*function\s*\(([^)]*)\)/g)) {
|
|
97
|
+
registrarSimboloLua(simbolos, `${tabela}.${membro[1]!}`, membro[2] ?? "");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
for (const match of texto.matchAll(/(?:^|\n)\s*([A-Za-z_]\w*(?:(?:\.|:)[A-Za-z_]\w*)*)\s*=\s*function\s*\(([^)]*)\)/g)) {
|
|
102
|
+
registrarSimboloLua(simbolos, match[1]!, match[2] ?? "");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
for (const match of texto.matchAll(/(?:^|\n)\s*([A-Za-z_]\w*)\s*\[\s*["']([A-Za-z_]\w*)["']\s*\]\s*=\s*function\s*\(([^)]*)\)/g)) {
|
|
106
|
+
registrarSimboloLua(simbolos, `${match[1]!}.${match[2]!}`, match[3] ?? "");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
for (const match of texto.matchAll(/(?:^|[\s,{])([A-Za-z_]\w*)\s*=\s*function\s*\(([^)]*)\)/g)) {
|
|
110
|
+
registrarSimboloLua(simbolos, match[1]!, match[2] ?? "");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return [...simbolos.values()].sort((a, b) => a.simbolo.localeCompare(b.simbolo, "pt-BR"));
|
|
114
|
+
}
|