@semacode/cli 1.5.16 → 1.5.17
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/AGENTS.md +272 -0
- package/LICENSE +22 -0
- package/SEMA_BRIEF.curto.txt +9 -0
- package/SEMA_BRIEF.md +70 -0
- package/SEMA_BRIEF.micro.txt +7 -0
- package/SEMA_INDEX.json +921 -0
- package/dist/angular-consumer-standalone.d.ts +6 -0
- package/dist/angular-consumer-standalone.js.map +1 -0
- package/dist/cpp-symbols.d.ts +10 -0
- package/dist/cpp-symbols.js.map +1 -0
- package/dist/docs.d.ts +56 -0
- package/dist/docs.js.map +1 -0
- package/dist/dotnet-http.d.ts +23 -0
- package/dist/dotnet-http.js.map +1 -0
- package/dist/drift.d.ts +225 -0
- package/dist/drift.js.map +1 -0
- package/dist/go-http.d.ts +23 -0
- package/dist/go-http.js.map +1 -0
- package/dist/importador.d.ts +31 -0
- package/dist/importador.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js.map +1 -0
- package/dist/java-http.d.ts +23 -0
- package/dist/java-http.js.map +1 -0
- package/dist/lua-symbols.d.ts +10 -0
- package/dist/lua-symbols.js.map +1 -0
- package/dist/php-symbols.d.ts +24 -0
- package/dist/php-symbols.js.map +1 -0
- package/dist/projeto.d.ts +53 -0
- package/dist/projeto.js.map +1 -0
- package/dist/python-http.d.ts +23 -0
- package/dist/python-http.js.map +1 -0
- package/dist/rust-http.d.ts +23 -0
- package/dist/rust-http.js.map +1 -0
- package/dist/tipos.d.ts +3 -0
- package/dist/tipos.js.map +1 -0
- package/dist/typescript-http.d.ts +35 -0
- package/dist/typescript-http.js.map +1 -0
- package/docs/AGENT_STARTER.md +102 -0
- package/docs/cli.md +119 -0
- package/docs/como-ensinar-a-sema-para-ia.md +149 -0
- package/docs/deploy.md +70 -0
- package/docs/documentacao.md +63 -0
- package/docs/env.md +56 -0
- package/docs/extensao-vscode.md +45 -0
- package/docs/fluxo-pratico-ia-sema.md +177 -0
- package/docs/instalacao-e-primeiro-uso.md +112 -0
- package/docs/integracao-com-ia.md +101 -0
- package/docs/mcp.md +53 -0
- package/docs/pagamento-ponta-a-ponta.md +155 -0
- package/docs/persistencia-vendor-first.md +145 -0
- package/docs/prompt-base-ia-sema.md +104 -0
- package/docs/rollback.md +47 -0
- package/docs/sintaxe.md +410 -0
- package/exemplos/agendamento.sema +106 -0
- package/exemplos/assinatura.sema +136 -0
- package/exemplos/auditoria.sema +88 -0
- package/exemplos/autenticacao.sema +125 -0
- package/exemplos/automacao.sema +107 -0
- package/exemplos/cadastro_usuario.sema +54 -0
- package/exemplos/calculadora.sema +78 -0
- package/exemplos/crud_simples.sema +89 -0
- package/exemplos/estoque.sema +126 -0
- package/exemplos/exportacao.sema +94 -0
- package/exemplos/fila.sema +131 -0
- package/exemplos/integracao_externa.sema +94 -0
- package/exemplos/multi_tenant.sema +140 -0
- package/exemplos/notificacao.sema +98 -0
- package/exemplos/operacao_estrategia.sema +402 -0
- package/exemplos/pagamento.sema +222 -0
- package/exemplos/pagamento_dominio.sema +35 -0
- package/exemplos/pedido.sema +119 -0
- package/exemplos/permissao.sema +121 -0
- package/exemplos/persistencia_vendor_first.sema +86 -0
- package/exemplos/relatorio.sema +93 -0
- package/exemplos/testes_embutidos.sema +45 -0
- package/exemplos/tratamento_erro.sema +157 -0
- package/exemplos/upload_arquivo.sema +93 -0
- package/exemplos/webhook.sema +96 -0
- package/llms-full.txt +34 -0
- package/llms.txt +17 -0
- package/node_modules/@sema/gerador-css/dist/index.d.ts +3 -0
- package/node_modules/@sema/gerador-css/dist/index.js +592 -0
- package/node_modules/@sema/gerador-css/dist/index.js.map +1 -0
- package/node_modules/@sema/gerador-css/package.json +7 -0
- package/node_modules/@sema/gerador-dart/dist/index.d.ts +3 -0
- package/node_modules/@sema/gerador-dart/dist/index.js +44 -0
- package/node_modules/@sema/gerador-dart/dist/index.js.map +1 -0
- package/node_modules/@sema/gerador-dart/package.json +7 -0
- package/node_modules/@sema/gerador-html/dist/index.d.ts +3 -0
- package/node_modules/@sema/gerador-html/dist/index.js +163 -0
- package/node_modules/@sema/gerador-html/dist/index.js.map +1 -0
- package/node_modules/@sema/gerador-html/package.json +7 -0
- package/node_modules/@sema/gerador-javascript/dist/index.d.ts +3 -0
- package/node_modules/@sema/gerador-javascript/dist/index.js +421 -0
- package/node_modules/@sema/gerador-javascript/dist/index.js.map +1 -0
- package/node_modules/@sema/gerador-javascript/package.json +7 -0
- package/node_modules/@sema/gerador-lua/dist/index.d.ts +3 -0
- package/node_modules/@sema/gerador-lua/dist/index.js +328 -0
- package/node_modules/@sema/gerador-lua/dist/index.js.map +1 -0
- package/node_modules/@sema/gerador-lua/package.json +7 -0
- package/node_modules/@sema/gerador-python/dist/index.d.ts +6 -0
- package/node_modules/@sema/gerador-python/dist/index.js +729 -0
- package/node_modules/@sema/gerador-python/dist/index.js.map +1 -0
- package/node_modules/@sema/gerador-python/package.json +7 -0
- package/node_modules/@sema/gerador-typescript/dist/index.d.ts +6 -0
- package/node_modules/@sema/gerador-typescript/dist/index.js +793 -0
- package/node_modules/@sema/gerador-typescript/dist/index.js.map +1 -0
- package/node_modules/@sema/gerador-typescript/package.json +7 -0
- package/node_modules/@sema/nucleo/dist/ast/tipos.d.ts +125 -0
- package/node_modules/@sema/nucleo/dist/ast/tipos.js +2 -0
- package/node_modules/@sema/nucleo/dist/ast/tipos.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/diagnosticos/index.d.ts +21 -0
- package/node_modules/@sema/nucleo/dist/diagnosticos/index.js +12 -0
- package/node_modules/@sema/nucleo/dist/diagnosticos/index.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/formatador/index.d.ts +9 -0
- package/node_modules/@sema/nucleo/dist/formatador/index.js +488 -0
- package/node_modules/@sema/nucleo/dist/formatador/index.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/index.d.ts +35 -0
- package/node_modules/@sema/nucleo/dist/index.js +96 -0
- package/node_modules/@sema/nucleo/dist/index.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/ir/conversor.d.ts +5 -0
- package/node_modules/@sema/nucleo/dist/ir/conversor.js +1072 -0
- package/node_modules/@sema/nucleo/dist/ir/conversor.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/ir/modelos.d.ts +377 -0
- package/node_modules/@sema/nucleo/dist/ir/modelos.js +2 -0
- package/node_modules/@sema/nucleo/dist/ir/modelos.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/lexer/lexer.d.ts +7 -0
- package/node_modules/@sema/nucleo/dist/lexer/lexer.js +122 -0
- package/node_modules/@sema/nucleo/dist/lexer/lexer.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/lexer/tokens.d.ts +8 -0
- package/node_modules/@sema/nucleo/dist/lexer/tokens.js +82 -0
- package/node_modules/@sema/nucleo/dist/lexer/tokens.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/parser/parser.d.ts +9 -0
- package/node_modules/@sema/nucleo/dist/parser/parser.js +807 -0
- package/node_modules/@sema/nucleo/dist/parser/parser.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/persistencia/contratos.d.ts +39 -0
- package/node_modules/@sema/nucleo/dist/persistencia/contratos.js +294 -0
- package/node_modules/@sema/nucleo/dist/persistencia/contratos.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/semantico/analisador.d.ts +58 -0
- package/node_modules/@sema/nucleo/dist/semantico/analisador.js +1912 -0
- package/node_modules/@sema/nucleo/dist/semantico/analisador.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/semantico/estruturas.d.ts +104 -0
- package/node_modules/@sema/nucleo/dist/semantico/estruturas.js +445 -0
- package/node_modules/@sema/nucleo/dist/semantico/estruturas.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/semantico/seguranca.d.ts +91 -0
- package/node_modules/@sema/nucleo/dist/semantico/seguranca.js +258 -0
- package/node_modules/@sema/nucleo/dist/semantico/seguranca.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/util/arquivos.d.ts +2 -0
- package/node_modules/@sema/nucleo/dist/util/arquivos.js +25 -0
- package/node_modules/@sema/nucleo/dist/util/arquivos.js.map +1 -0
- package/node_modules/@sema/nucleo/package.json +7 -0
- package/node_modules/@sema/padroes/dist/index.d.ts +25 -0
- package/node_modules/@sema/padroes/dist/index.js +316 -0
- package/node_modules/@sema/padroes/dist/index.js.map +1 -0
- package/node_modules/@sema/padroes/package.json +7 -0
- package/package.json +35 -26
- package/semacode-cli-1.3.1.tgz +0 -0
- package/src/angular-consumer-standalone.ts +0 -312
- package/src/cpp-symbols.ts +0 -82
- package/src/docs.ts +0 -535
- package/src/dotnet-http.ts +0 -355
- package/src/drift.ts +0 -4933
- package/src/go-http.ts +0 -118
- package/src/importador.ts +0 -3891
- package/src/index.ts +0 -5641
- package/src/java-http.ts +0 -247
- package/src/lua-symbols.ts +0 -114
- package/src/php-symbols.ts +0 -462
- package/src/projeto.ts +0 -862
- package/src/python-http.ts +0 -258
- package/src/rust-http.ts +0 -125
- package/src/tipos.ts +0 -24
- package/src/typescript-http.ts +0 -1076
- package/tsconfig.json +0 -20
|
@@ -0,0 +1,807 @@
|
|
|
1
|
+
import { criarDiagnostico, } from "../diagnosticos/index.js";
|
|
2
|
+
const PALAVRAS_BLOCO_NOMEADO_LIVRE = new Set([
|
|
3
|
+
"table",
|
|
4
|
+
"view",
|
|
5
|
+
"query",
|
|
6
|
+
"transaction",
|
|
7
|
+
"index",
|
|
8
|
+
"constraint",
|
|
9
|
+
"relationship",
|
|
10
|
+
"collection",
|
|
11
|
+
"document",
|
|
12
|
+
"keyspace",
|
|
13
|
+
"stream",
|
|
14
|
+
"lock",
|
|
15
|
+
"retention",
|
|
16
|
+
"replication",
|
|
17
|
+
]);
|
|
18
|
+
const PALAVRAS_AUTHOR_PROFILE = new Set([
|
|
19
|
+
"book",
|
|
20
|
+
"work",
|
|
21
|
+
"part",
|
|
22
|
+
"chapter",
|
|
23
|
+
"section",
|
|
24
|
+
"scene",
|
|
25
|
+
"character",
|
|
26
|
+
"arc",
|
|
27
|
+
"audience",
|
|
28
|
+
"thesis",
|
|
29
|
+
"argument",
|
|
30
|
+
"claim",
|
|
31
|
+
"source",
|
|
32
|
+
"concept",
|
|
33
|
+
"example",
|
|
34
|
+
"voice",
|
|
35
|
+
"style_rule",
|
|
36
|
+
"lexicon",
|
|
37
|
+
"motif",
|
|
38
|
+
"canon",
|
|
39
|
+
]);
|
|
40
|
+
function decodificarTextoLiteral(valor) {
|
|
41
|
+
let resultado = "";
|
|
42
|
+
for (let indice = 0; indice < valor.length; indice += 1) {
|
|
43
|
+
const atual = valor[indice];
|
|
44
|
+
if (atual !== "\\") {
|
|
45
|
+
resultado += atual;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const proximo = valor[indice + 1];
|
|
49
|
+
if (!proximo) {
|
|
50
|
+
resultado += atual;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
switch (proximo) {
|
|
54
|
+
case "\"":
|
|
55
|
+
resultado += "\"";
|
|
56
|
+
indice += 1;
|
|
57
|
+
break;
|
|
58
|
+
case "\\":
|
|
59
|
+
resultado += "\\";
|
|
60
|
+
indice += 1;
|
|
61
|
+
break;
|
|
62
|
+
case "n":
|
|
63
|
+
resultado += "\n";
|
|
64
|
+
indice += 1;
|
|
65
|
+
break;
|
|
66
|
+
case "r":
|
|
67
|
+
resultado += "\r";
|
|
68
|
+
indice += 1;
|
|
69
|
+
break;
|
|
70
|
+
case "t":
|
|
71
|
+
resultado += "\t";
|
|
72
|
+
indice += 1;
|
|
73
|
+
break;
|
|
74
|
+
default:
|
|
75
|
+
resultado += `${atual}${proximo}`;
|
|
76
|
+
indice += 1;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return resultado;
|
|
81
|
+
}
|
|
82
|
+
class Parser {
|
|
83
|
+
tokens;
|
|
84
|
+
indice = 0;
|
|
85
|
+
diagnosticos = [];
|
|
86
|
+
constructor(tokens) {
|
|
87
|
+
this.tokens = tokens;
|
|
88
|
+
}
|
|
89
|
+
analisar() {
|
|
90
|
+
this.ignorarRuido();
|
|
91
|
+
const modulo = this.parseModulo();
|
|
92
|
+
return { modulo, diagnosticos: this.diagnosticos };
|
|
93
|
+
}
|
|
94
|
+
atual() {
|
|
95
|
+
return this.tokens[this.indice];
|
|
96
|
+
}
|
|
97
|
+
anterior() {
|
|
98
|
+
return this.tokens[Math.max(0, this.indice - 1)];
|
|
99
|
+
}
|
|
100
|
+
avancar() {
|
|
101
|
+
const token = this.atual();
|
|
102
|
+
if (this.indice < this.tokens.length - 1) {
|
|
103
|
+
this.indice += 1;
|
|
104
|
+
}
|
|
105
|
+
return token;
|
|
106
|
+
}
|
|
107
|
+
ignorarRuido() {
|
|
108
|
+
while (["nova_linha", "comentario"].includes(this.atual().tipo)) {
|
|
109
|
+
this.avancar();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
tokenNaFrente(distancia = 1) {
|
|
113
|
+
return this.tokens[this.indice + distancia];
|
|
114
|
+
}
|
|
115
|
+
iniciaBlocoSimples(keyword) {
|
|
116
|
+
if (this.atual().valor !== keyword) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
return this.tokenNaFrente()?.valor === "{";
|
|
120
|
+
}
|
|
121
|
+
iniciaBlocoComNomeObrigatorio(keyword) {
|
|
122
|
+
if (this.atual().valor !== keyword) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
return this.tokenNaFrente()?.tipo === "identificador" && this.tokenNaFrente(2)?.valor === "{";
|
|
126
|
+
}
|
|
127
|
+
iniciaBlocoState() {
|
|
128
|
+
if (this.atual().valor !== "state") {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
return this.tokenNaFrente()?.valor === "{"
|
|
132
|
+
|| (this.tokenNaFrente()?.tipo === "identificador" && this.tokenNaFrente(2)?.valor === "{");
|
|
133
|
+
}
|
|
134
|
+
iniciaSubblocoConhecido() {
|
|
135
|
+
if (this.atual().tipo !== "palavra_chave") {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
if (["state"].includes(this.atual().valor)) {
|
|
139
|
+
return this.iniciaBlocoState();
|
|
140
|
+
}
|
|
141
|
+
return [
|
|
142
|
+
"docs",
|
|
143
|
+
"comments",
|
|
144
|
+
"fields",
|
|
145
|
+
"invariants",
|
|
146
|
+
"transitions",
|
|
147
|
+
"input",
|
|
148
|
+
"output",
|
|
149
|
+
"rules",
|
|
150
|
+
"effects",
|
|
151
|
+
"impl",
|
|
152
|
+
"vinculos",
|
|
153
|
+
"execucao",
|
|
154
|
+
"auth",
|
|
155
|
+
"authz",
|
|
156
|
+
"dados",
|
|
157
|
+
"audit",
|
|
158
|
+
"segredos",
|
|
159
|
+
"forbidden",
|
|
160
|
+
"guarantees",
|
|
161
|
+
"tests",
|
|
162
|
+
"error",
|
|
163
|
+
"given",
|
|
164
|
+
"when",
|
|
165
|
+
"expect",
|
|
166
|
+
].includes(this.atual().valor) && this.iniciaBlocoSimples(this.atual().valor);
|
|
167
|
+
}
|
|
168
|
+
consumirValor(valor, mensagem) {
|
|
169
|
+
const token = this.atual();
|
|
170
|
+
if (token.valor === valor) {
|
|
171
|
+
this.avancar();
|
|
172
|
+
return token;
|
|
173
|
+
}
|
|
174
|
+
this.registrarErro("PAR001", mensagem, token.intervalo, `Esperado "${valor}", recebido "${token.valor}".`);
|
|
175
|
+
return token;
|
|
176
|
+
}
|
|
177
|
+
consumirTipo(tipo, mensagem) {
|
|
178
|
+
const token = this.atual();
|
|
179
|
+
if (token.tipo === tipo) {
|
|
180
|
+
this.avancar();
|
|
181
|
+
return token;
|
|
182
|
+
}
|
|
183
|
+
this.registrarErro("PAR002", mensagem, token.intervalo, `Esperado token do tipo "${tipo}".`);
|
|
184
|
+
return token;
|
|
185
|
+
}
|
|
186
|
+
registrarErro(codigo, mensagem, intervalo, contexto) {
|
|
187
|
+
this.diagnosticos.push(criarDiagnostico(codigo, mensagem, "erro", intervalo, "Revise a sintaxe do bloco e a ordem das declaracoes.", contexto));
|
|
188
|
+
}
|
|
189
|
+
parseModulo() {
|
|
190
|
+
if (this.atual().valor !== "module") {
|
|
191
|
+
this.registrarErro("PAR003", "Arquivo .sema deve iniciar com um bloco module.", this.atual().intervalo);
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
194
|
+
const inicio = this.avancar().intervalo.inicio;
|
|
195
|
+
const nome = this.consumirTipo("identificador", "Era esperado o nome do modulo.").valor;
|
|
196
|
+
this.consumirValor("{", "Era esperado abrir o corpo do modulo com {.");
|
|
197
|
+
const uses = [];
|
|
198
|
+
let vinculos;
|
|
199
|
+
const databases = [];
|
|
200
|
+
const types = [];
|
|
201
|
+
const entities = [];
|
|
202
|
+
const enums = [];
|
|
203
|
+
const tasks = [];
|
|
204
|
+
const flows = [];
|
|
205
|
+
const routes = [];
|
|
206
|
+
const authorBlocks = [];
|
|
207
|
+
const agents = [];
|
|
208
|
+
const workers = [];
|
|
209
|
+
const eventos = [];
|
|
210
|
+
const filas = [];
|
|
211
|
+
const crons = [];
|
|
212
|
+
const webhooks = [];
|
|
213
|
+
const caches = [];
|
|
214
|
+
const storages = [];
|
|
215
|
+
const policies = [];
|
|
216
|
+
const states = [];
|
|
217
|
+
const extras = [];
|
|
218
|
+
let docs;
|
|
219
|
+
let comments;
|
|
220
|
+
let tests;
|
|
221
|
+
while (this.atual().tipo !== "fim_arquivo" && this.atual().valor !== "}") {
|
|
222
|
+
this.ignorarRuido();
|
|
223
|
+
const token = this.atual();
|
|
224
|
+
if (token.valor === "}") {
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
if (PALAVRAS_AUTHOR_PROFILE.has(token.valor) && this.iniciaBlocoComNomeObrigatorio(token.valor)) {
|
|
228
|
+
authorBlocks.push(this.parseBlocoGenerico(token.valor));
|
|
229
|
+
this.ignorarRuido();
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
if (token.valor === "agent" && this.iniciaBlocoComNomeObrigatorio("agent")) {
|
|
233
|
+
agents.push(this.parseBlocoGenerico("agent"));
|
|
234
|
+
this.ignorarRuido();
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
switch (token.valor) {
|
|
238
|
+
case "use":
|
|
239
|
+
if (this.tokenNaFrente()?.tipo === "identificador") {
|
|
240
|
+
uses.push(this.parseUse());
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
extras.push(this.parseBlocoGenerico("desconhecido"));
|
|
244
|
+
break;
|
|
245
|
+
case "docs":
|
|
246
|
+
if (this.iniciaBlocoSimples("docs")) {
|
|
247
|
+
docs = this.parseBlocoGenerico("docs");
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
extras.push(this.parseBlocoGenerico("desconhecido"));
|
|
251
|
+
break;
|
|
252
|
+
case "comments":
|
|
253
|
+
if (this.iniciaBlocoSimples("comments")) {
|
|
254
|
+
comments = this.parseBlocoGenerico("comments");
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
extras.push(this.parseBlocoGenerico("desconhecido"));
|
|
258
|
+
break;
|
|
259
|
+
case "vinculos":
|
|
260
|
+
if (this.iniciaBlocoSimples("vinculos")) {
|
|
261
|
+
vinculos = this.parseBlocoGenerico("vinculos");
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
extras.push(this.parseBlocoGenerico("desconhecido"));
|
|
265
|
+
break;
|
|
266
|
+
case "database":
|
|
267
|
+
if (this.iniciaBlocoComNomeObrigatorio("database")) {
|
|
268
|
+
databases.push(this.parseBlocoGenerico("database"));
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
extras.push(this.parseBlocoGenerico("desconhecido"));
|
|
272
|
+
break;
|
|
273
|
+
case "type":
|
|
274
|
+
if (this.iniciaBlocoComNomeObrigatorio("type")) {
|
|
275
|
+
types.push(this.parseType());
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
extras.push(this.parseBlocoGenerico("desconhecido"));
|
|
279
|
+
break;
|
|
280
|
+
case "entity":
|
|
281
|
+
if (this.iniciaBlocoComNomeObrigatorio("entity")) {
|
|
282
|
+
entities.push(this.parseEntity());
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
extras.push(this.parseBlocoGenerico("desconhecido"));
|
|
286
|
+
break;
|
|
287
|
+
case "enum":
|
|
288
|
+
if (this.iniciaBlocoComNomeObrigatorio("enum")) {
|
|
289
|
+
enums.push(this.parseEnum());
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
extras.push(this.parseBlocoGenerico("desconhecido"));
|
|
293
|
+
break;
|
|
294
|
+
case "task":
|
|
295
|
+
if (this.iniciaBlocoComNomeObrigatorio("task")) {
|
|
296
|
+
tasks.push(this.parseTask());
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
extras.push(this.parseBlocoGenerico("desconhecido"));
|
|
300
|
+
break;
|
|
301
|
+
case "flow":
|
|
302
|
+
if (this.iniciaBlocoComNomeObrigatorio("flow")) {
|
|
303
|
+
flows.push(this.parseFlow());
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
extras.push(this.parseBlocoGenerico("desconhecido"));
|
|
307
|
+
break;
|
|
308
|
+
case "route":
|
|
309
|
+
if (this.iniciaBlocoComNomeObrigatorio("route")) {
|
|
310
|
+
routes.push(this.parseRoute());
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
extras.push(this.parseBlocoGenerico("desconhecido"));
|
|
314
|
+
break;
|
|
315
|
+
case "worker":
|
|
316
|
+
if (this.iniciaBlocoComNomeObrigatorio("worker")) {
|
|
317
|
+
workers.push(this.parseBlocoGenerico("worker"));
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
extras.push(this.parseBlocoGenerico("desconhecido"));
|
|
321
|
+
break;
|
|
322
|
+
case "evento":
|
|
323
|
+
if (this.iniciaBlocoComNomeObrigatorio("evento")) {
|
|
324
|
+
eventos.push(this.parseBlocoGenerico("evento"));
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
extras.push(this.parseBlocoGenerico("desconhecido"));
|
|
328
|
+
break;
|
|
329
|
+
case "fila":
|
|
330
|
+
if (this.iniciaBlocoComNomeObrigatorio("fila")) {
|
|
331
|
+
filas.push(this.parseBlocoGenerico("fila"));
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
extras.push(this.parseBlocoGenerico("desconhecido"));
|
|
335
|
+
break;
|
|
336
|
+
case "cron":
|
|
337
|
+
if (this.iniciaBlocoComNomeObrigatorio("cron")) {
|
|
338
|
+
crons.push(this.parseBlocoGenerico("cron"));
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
extras.push(this.parseBlocoGenerico("desconhecido"));
|
|
342
|
+
break;
|
|
343
|
+
case "webhook":
|
|
344
|
+
if (this.iniciaBlocoComNomeObrigatorio("webhook")) {
|
|
345
|
+
webhooks.push(this.parseBlocoGenerico("webhook"));
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
extras.push(this.parseBlocoGenerico("desconhecido"));
|
|
349
|
+
break;
|
|
350
|
+
case "cache":
|
|
351
|
+
if (this.iniciaBlocoComNomeObrigatorio("cache")) {
|
|
352
|
+
caches.push(this.parseBlocoGenerico("cache"));
|
|
353
|
+
break;
|
|
354
|
+
}
|
|
355
|
+
extras.push(this.parseBlocoGenerico("desconhecido"));
|
|
356
|
+
break;
|
|
357
|
+
case "storage":
|
|
358
|
+
if (this.iniciaBlocoComNomeObrigatorio("storage")) {
|
|
359
|
+
storages.push(this.parseBlocoGenerico("storage"));
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
extras.push(this.parseBlocoGenerico("desconhecido"));
|
|
363
|
+
break;
|
|
364
|
+
case "policy":
|
|
365
|
+
if (this.iniciaBlocoComNomeObrigatorio("policy")) {
|
|
366
|
+
policies.push(this.parseBlocoGenerico("policy"));
|
|
367
|
+
break;
|
|
368
|
+
}
|
|
369
|
+
extras.push(this.parseBlocoGenerico("desconhecido"));
|
|
370
|
+
break;
|
|
371
|
+
case "state":
|
|
372
|
+
if (this.iniciaBlocoState()) {
|
|
373
|
+
states.push(this.parseState());
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
extras.push(this.parseBlocoGenerico("desconhecido"));
|
|
377
|
+
break;
|
|
378
|
+
case "tests":
|
|
379
|
+
if (this.iniciaBlocoSimples("tests")) {
|
|
380
|
+
tests = this.parseBlocoGenerico("tests");
|
|
381
|
+
break;
|
|
382
|
+
}
|
|
383
|
+
extras.push(this.parseBlocoGenerico("desconhecido"));
|
|
384
|
+
break;
|
|
385
|
+
default:
|
|
386
|
+
extras.push(this.parseBlocoGenerico("desconhecido"));
|
|
387
|
+
break;
|
|
388
|
+
}
|
|
389
|
+
this.ignorarRuido();
|
|
390
|
+
}
|
|
391
|
+
const fim = this.consumirValor("}", "Era esperado fechar o bloco module com }.").intervalo.fim;
|
|
392
|
+
return {
|
|
393
|
+
tipo: "module",
|
|
394
|
+
nome,
|
|
395
|
+
uses,
|
|
396
|
+
vinculos,
|
|
397
|
+
docs,
|
|
398
|
+
comments,
|
|
399
|
+
databases,
|
|
400
|
+
types,
|
|
401
|
+
entities,
|
|
402
|
+
enums,
|
|
403
|
+
tasks,
|
|
404
|
+
flows,
|
|
405
|
+
routes,
|
|
406
|
+
authorBlocks,
|
|
407
|
+
agents,
|
|
408
|
+
workers,
|
|
409
|
+
eventos,
|
|
410
|
+
filas,
|
|
411
|
+
crons,
|
|
412
|
+
webhooks,
|
|
413
|
+
caches,
|
|
414
|
+
storages,
|
|
415
|
+
policies,
|
|
416
|
+
states,
|
|
417
|
+
tests,
|
|
418
|
+
extras,
|
|
419
|
+
intervalo: { inicio, fim },
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
parseUse() {
|
|
423
|
+
const inicio = this.avancar().intervalo.inicio;
|
|
424
|
+
const primeiro = this.consumirTipo("identificador", "Era esperado o caminho do use.");
|
|
425
|
+
let origem = "sema";
|
|
426
|
+
let caminho = primeiro.valor;
|
|
427
|
+
const origemNormalizada = normalizarOrigemUse(primeiro.valor);
|
|
428
|
+
if (origemNormalizada && this.atual().tipo === "identificador") {
|
|
429
|
+
origem = origemNormalizada;
|
|
430
|
+
caminho = this.avancar().valor;
|
|
431
|
+
}
|
|
432
|
+
const fim = this.anterior().intervalo.fim;
|
|
433
|
+
return { tipo: "use", origem, caminho, intervalo: { inicio, fim } };
|
|
434
|
+
}
|
|
435
|
+
parseType() {
|
|
436
|
+
const inicio = this.avancar().intervalo.inicio;
|
|
437
|
+
const nome = this.consumirTipo("identificador", "Era esperado o nome do type.").valor;
|
|
438
|
+
const corpo = this.parseBlocoComNomeOpcional("type");
|
|
439
|
+
return { tipo: "type", nome, corpo, intervalo: { inicio, fim: corpo.intervalo?.fim ?? this.anterior().intervalo.fim } };
|
|
440
|
+
}
|
|
441
|
+
parseEntity() {
|
|
442
|
+
const inicio = this.avancar().intervalo.inicio;
|
|
443
|
+
const nome = this.consumirTipo("identificador", "Era esperado o nome da entity.").valor;
|
|
444
|
+
const corpo = this.parseBlocoComNomeOpcional("entity");
|
|
445
|
+
return { tipo: "entity", nome, corpo, intervalo: { inicio, fim: corpo.intervalo?.fim ?? this.anterior().intervalo.fim } };
|
|
446
|
+
}
|
|
447
|
+
parseEnum() {
|
|
448
|
+
const inicio = this.avancar().intervalo.inicio;
|
|
449
|
+
const nome = this.consumirTipo("identificador", "Era esperado o nome do enum.").valor;
|
|
450
|
+
this.consumirValor("{", "Era esperado abrir o corpo do enum.");
|
|
451
|
+
const valores = [];
|
|
452
|
+
let docs;
|
|
453
|
+
while (this.atual().tipo !== "fim_arquivo" && this.atual().valor !== "}") {
|
|
454
|
+
this.ignorarRuido();
|
|
455
|
+
if (this.atual().valor === "}") {
|
|
456
|
+
break;
|
|
457
|
+
}
|
|
458
|
+
if (this.atual().valor === "docs") {
|
|
459
|
+
docs = this.parseBlocoGenerico("docs");
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
if (["identificador", "palavra_chave"].includes(this.atual().tipo)) {
|
|
463
|
+
valores.push(this.avancar().valor);
|
|
464
|
+
if (this.atual().valor === ",") {
|
|
465
|
+
this.avancar();
|
|
466
|
+
}
|
|
467
|
+
continue;
|
|
468
|
+
}
|
|
469
|
+
this.avancar();
|
|
470
|
+
}
|
|
471
|
+
const fim = this.consumirValor("}", "Era esperado fechar o enum.").intervalo.fim;
|
|
472
|
+
return { tipo: "enum", nome, valores, docs, intervalo: { inicio, fim } };
|
|
473
|
+
}
|
|
474
|
+
parseTask() {
|
|
475
|
+
const inicio = this.avancar().intervalo.inicio;
|
|
476
|
+
const nome = this.consumirTipo("identificador", "Era esperado o nome da task.").valor;
|
|
477
|
+
const corpo = this.parseBlocoComNomeOpcional("task");
|
|
478
|
+
const localizar = (palavraChave) => corpo.blocos.find((bloco) => bloco.tipo === "bloco_generico" && bloco.palavraChave === palavraChave);
|
|
479
|
+
return {
|
|
480
|
+
tipo: "task",
|
|
481
|
+
nome,
|
|
482
|
+
corpo,
|
|
483
|
+
input: localizar("input"),
|
|
484
|
+
output: localizar("output"),
|
|
485
|
+
rules: localizar("rules"),
|
|
486
|
+
effects: localizar("effects"),
|
|
487
|
+
impl: localizar("impl"),
|
|
488
|
+
vinculos: localizar("vinculos"),
|
|
489
|
+
execucao: localizar("execucao"),
|
|
490
|
+
auth: localizar("auth"),
|
|
491
|
+
authz: localizar("authz"),
|
|
492
|
+
dados: localizar("dados"),
|
|
493
|
+
audit: localizar("audit"),
|
|
494
|
+
segredos: localizar("segredos"),
|
|
495
|
+
forbidden: localizar("forbidden"),
|
|
496
|
+
guarantees: localizar("guarantees"),
|
|
497
|
+
state: localizar("state"),
|
|
498
|
+
tests: localizar("tests"),
|
|
499
|
+
error: localizar("error"),
|
|
500
|
+
docs: localizar("docs"),
|
|
501
|
+
comments: localizar("comments"),
|
|
502
|
+
intervalo: { inicio, fim: corpo.intervalo?.fim ?? this.anterior().intervalo.fim },
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
parseFlow() {
|
|
506
|
+
const inicio = this.avancar().intervalo.inicio;
|
|
507
|
+
const nome = this.consumirTipo("identificador", "Era esperado o nome do flow.").valor;
|
|
508
|
+
const corpo = this.parseBlocoComNomeOpcional("flow");
|
|
509
|
+
const vinculos = corpo.blocos.find((bloco) => bloco.tipo === "bloco_generico" && bloco.palavraChave === "vinculos");
|
|
510
|
+
return { tipo: "flow", nome, corpo, vinculos, intervalo: { inicio, fim: corpo.intervalo?.fim ?? this.anterior().intervalo.fim } };
|
|
511
|
+
}
|
|
512
|
+
parseRoute() {
|
|
513
|
+
const inicio = this.avancar().intervalo.inicio;
|
|
514
|
+
const nome = this.consumirTipo("identificador", "Era esperado o nome da route.").valor;
|
|
515
|
+
const corpo = this.parseBlocoComNomeOpcional("route");
|
|
516
|
+
const vinculos = corpo.blocos.find((bloco) => bloco.tipo === "bloco_generico" && bloco.palavraChave === "vinculos");
|
|
517
|
+
return { tipo: "route", nome, corpo, vinculos, intervalo: { inicio, fim: corpo.intervalo?.fim ?? this.anterior().intervalo.fim } };
|
|
518
|
+
}
|
|
519
|
+
parseState() {
|
|
520
|
+
const inicioToken = this.avancar();
|
|
521
|
+
let nome;
|
|
522
|
+
if (this.atual().tipo === "identificador") {
|
|
523
|
+
nome = this.avancar().valor;
|
|
524
|
+
}
|
|
525
|
+
this.consumirValor("{", "Era esperado abrir o bloco state.");
|
|
526
|
+
const corpo = this.parseCorpoBloco("state", nome, inicioToken.intervalo.inicio);
|
|
527
|
+
return {
|
|
528
|
+
tipo: "state",
|
|
529
|
+
nome,
|
|
530
|
+
corpo,
|
|
531
|
+
intervalo: { inicio: inicioToken.intervalo.inicio, fim: corpo.intervalo?.fim ?? this.anterior().intervalo.fim },
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
parseBlocoComNomeOpcional(nomeBloco) {
|
|
535
|
+
this.consumirValor("{", `Era esperado abrir o bloco ${nomeBloco}.`);
|
|
536
|
+
return this.parseCorpoBloco(nomeBloco);
|
|
537
|
+
}
|
|
538
|
+
parseBlocoGenerico(palavraChave) {
|
|
539
|
+
const inicioToken = this.avancar();
|
|
540
|
+
let nome;
|
|
541
|
+
if (this.atual().tipo === "identificador") {
|
|
542
|
+
nome = this.avancar().valor;
|
|
543
|
+
}
|
|
544
|
+
this.consumirValor("{", `Era esperado abrir o bloco ${inicioToken.valor}.`);
|
|
545
|
+
return this.parseCorpoBloco((palavraChave === "desconhecido" ? "desconhecido" : inicioToken.valor), nome, inicioToken.intervalo.inicio);
|
|
546
|
+
}
|
|
547
|
+
parseBlocoNomeadoLivre() {
|
|
548
|
+
const inicioToken = this.avancar();
|
|
549
|
+
const nome = inicioToken.valor;
|
|
550
|
+
this.consumirValor("{", `Era esperado abrir o bloco ${nome}.`);
|
|
551
|
+
return this.parseCorpoBloco("desconhecido", nome, inicioToken.intervalo.inicio);
|
|
552
|
+
}
|
|
553
|
+
parseBlocoNomeadoComPalavraChaveLivre() {
|
|
554
|
+
const palavraChaveToken = this.avancar();
|
|
555
|
+
const nomeToken = this.avancar();
|
|
556
|
+
this.consumirValor("{", `Era esperado abrir o bloco ${palavraChaveToken.valor} ${nomeToken.valor}.`);
|
|
557
|
+
return this.parseCorpoBloco(palavraChaveToken.valor, nomeToken.valor, palavraChaveToken.intervalo.inicio);
|
|
558
|
+
}
|
|
559
|
+
parseCorpoBloco(palavraChave, nome, inicioManual) {
|
|
560
|
+
const inicio = inicioManual ?? this.anterior().intervalo.inicio;
|
|
561
|
+
const campos = [];
|
|
562
|
+
const linhas = [];
|
|
563
|
+
const blocos = [];
|
|
564
|
+
while (this.atual().tipo !== "fim_arquivo" && this.atual().valor !== "}") {
|
|
565
|
+
this.ignorarRuido();
|
|
566
|
+
if (this.atual().valor === "}") {
|
|
567
|
+
break;
|
|
568
|
+
}
|
|
569
|
+
if (palavraChave === "tests" && this.atual().valor === "caso") {
|
|
570
|
+
blocos.push(this.parseCasoTeste());
|
|
571
|
+
continue;
|
|
572
|
+
}
|
|
573
|
+
if (this.iniciaSubblocoConhecido()) {
|
|
574
|
+
blocos.push(this.parseBlocoGenerico(this.atual().valor));
|
|
575
|
+
continue;
|
|
576
|
+
}
|
|
577
|
+
if (["identificador", "palavra_chave"].includes(this.atual().tipo)
|
|
578
|
+
&& PALAVRAS_BLOCO_NOMEADO_LIVRE.has(this.atual().valor)
|
|
579
|
+
&& ["identificador", "palavra_chave"].includes(this.tokens[this.indice + 1]?.tipo ?? "")
|
|
580
|
+
&& this.tokens[this.indice + 2]?.valor === "{") {
|
|
581
|
+
blocos.push(this.parseBlocoNomeadoComPalavraChaveLivre());
|
|
582
|
+
continue;
|
|
583
|
+
}
|
|
584
|
+
if (["identificador", "palavra_chave"].includes(this.atual().tipo) && this.tokens[this.indice + 1]?.valor === "{") {
|
|
585
|
+
blocos.push(this.parseBlocoNomeadoLivre());
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
588
|
+
if (["identificador", "palavra_chave"].includes(this.atual().tipo) && this.tokens[this.indice + 1]?.valor === ":") {
|
|
589
|
+
campos.push(this.parseCampo());
|
|
590
|
+
continue;
|
|
591
|
+
}
|
|
592
|
+
const linha = this.parseLinhaDeclarativa();
|
|
593
|
+
if (linha.conteudo.trim().length > 0) {
|
|
594
|
+
linhas.push(linha);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
const fim = this.consumirValor("}", "Era esperado fechar o bloco com }.").intervalo.fim;
|
|
598
|
+
return {
|
|
599
|
+
tipo: "bloco_generico",
|
|
600
|
+
palavraChave,
|
|
601
|
+
nome,
|
|
602
|
+
campos,
|
|
603
|
+
linhas,
|
|
604
|
+
blocos,
|
|
605
|
+
intervalo: { inicio, fim },
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
parseCampo() {
|
|
609
|
+
const inicio = this.atual().intervalo.inicio;
|
|
610
|
+
const nome = this.avancar().valor;
|
|
611
|
+
this.consumirValor(":", "Era esperado ':' depois do nome do campo.");
|
|
612
|
+
const partes = [];
|
|
613
|
+
let profundidade = 0;
|
|
614
|
+
while (this.atual().tipo !== "fim_arquivo" && this.atual().tipo !== "nova_linha" && this.atual().valor !== "}") {
|
|
615
|
+
const proximoToken = this.tokens[this.indice + 1];
|
|
616
|
+
const iniciaNovoCampo = profundidade === 0
|
|
617
|
+
&& partes.length > 0
|
|
618
|
+
&& ["identificador", "palavra_chave"].includes(this.atual().tipo)
|
|
619
|
+
&& proximoToken?.valor === ":";
|
|
620
|
+
if (iniciaNovoCampo) {
|
|
621
|
+
break;
|
|
622
|
+
}
|
|
623
|
+
const token = this.avancar();
|
|
624
|
+
partes.push(token);
|
|
625
|
+
if (["<", "[", "("].includes(token.valor)) {
|
|
626
|
+
profundidade += 1;
|
|
627
|
+
}
|
|
628
|
+
else if ([">", "]", ")"].includes(token.valor)) {
|
|
629
|
+
profundidade = Math.max(0, profundidade - 1);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
const segmentos = partes.filter((token) => token.valor.length > 0);
|
|
633
|
+
const possuiTextoLiteral = segmentos.some((token) => token.tipo === "texto");
|
|
634
|
+
if (possuiTextoLiteral) {
|
|
635
|
+
const valorLiteral = segmentos.map((token) => token.tipo === "texto" ? decodificarTextoLiteral(token.valor) : token.valor).join(" ");
|
|
636
|
+
if (this.atual().tipo === "nova_linha") {
|
|
637
|
+
this.avancar();
|
|
638
|
+
}
|
|
639
|
+
return {
|
|
640
|
+
tipo: "campo",
|
|
641
|
+
nome,
|
|
642
|
+
valor: valorLiteral,
|
|
643
|
+
modificadores: [],
|
|
644
|
+
intervalo: { inicio, fim: this.anterior().intervalo.fim },
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
const tipoTokens = [];
|
|
648
|
+
const modificadores = [];
|
|
649
|
+
let profundidadeTipo = 0;
|
|
650
|
+
let iniciouModificadores = false;
|
|
651
|
+
for (const token of segmentos) {
|
|
652
|
+
const segmento = token.valor;
|
|
653
|
+
if (!iniciouModificadores) {
|
|
654
|
+
if (["<", "[", "("].includes(segmento)) {
|
|
655
|
+
profundidadeTipo += 1;
|
|
656
|
+
tipoTokens.push(segmento);
|
|
657
|
+
continue;
|
|
658
|
+
}
|
|
659
|
+
if ([">", "]", ")"].includes(segmento)) {
|
|
660
|
+
profundidadeTipo = Math.max(0, profundidadeTipo - 1);
|
|
661
|
+
tipoTokens.push(segmento);
|
|
662
|
+
continue;
|
|
663
|
+
}
|
|
664
|
+
const pareceModificador = profundidadeTipo === 0
|
|
665
|
+
&& tipoTokens.length > 0
|
|
666
|
+
&& /^[a-z_][a-z0-9_]*$/u.test(segmento);
|
|
667
|
+
if (pareceModificador) {
|
|
668
|
+
iniciouModificadores = true;
|
|
669
|
+
modificadores.push(segmento);
|
|
670
|
+
continue;
|
|
671
|
+
}
|
|
672
|
+
tipoTokens.push(segmento);
|
|
673
|
+
continue;
|
|
674
|
+
}
|
|
675
|
+
modificadores.push(segmento);
|
|
676
|
+
}
|
|
677
|
+
let valor = tipoTokens
|
|
678
|
+
.join(" ")
|
|
679
|
+
.replace(/\s*([<>\[\](),|?])\s*/g, "$1")
|
|
680
|
+
.trim();
|
|
681
|
+
if (valor.includes("/")) {
|
|
682
|
+
valor = valor.replace(/\s*\/\s*/g, "/");
|
|
683
|
+
}
|
|
684
|
+
if (this.atual().tipo === "nova_linha") {
|
|
685
|
+
this.avancar();
|
|
686
|
+
}
|
|
687
|
+
return {
|
|
688
|
+
tipo: "campo",
|
|
689
|
+
nome,
|
|
690
|
+
valor,
|
|
691
|
+
modificadores,
|
|
692
|
+
intervalo: { inicio, fim: this.anterior().intervalo.fim },
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
parseLinhaDeclarativa() {
|
|
696
|
+
const inicio = this.atual().intervalo.inicio;
|
|
697
|
+
const partes = [];
|
|
698
|
+
while (this.atual().tipo !== "fim_arquivo" && this.atual().tipo !== "nova_linha" && this.atual().valor !== "}") {
|
|
699
|
+
partes.push(this.avancar().valor);
|
|
700
|
+
}
|
|
701
|
+
if (this.atual().tipo === "nova_linha") {
|
|
702
|
+
this.avancar();
|
|
703
|
+
}
|
|
704
|
+
return {
|
|
705
|
+
tipo: "linha_declarativa",
|
|
706
|
+
conteudo: partes.join(" ").trim(),
|
|
707
|
+
intervalo: { inicio, fim: this.anterior().intervalo.fim },
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
parseCasoTeste() {
|
|
711
|
+
const inicio = this.avancar().intervalo.inicio;
|
|
712
|
+
const nomeToken = this.atual();
|
|
713
|
+
const nome = nomeToken.tipo === "texto"
|
|
714
|
+
? this.avancar().valor
|
|
715
|
+
: this.consumirTipo("identificador", "Era esperado o nome textual do caso de teste.").valor;
|
|
716
|
+
this.consumirValor("{", "Era esperado abrir o bloco do caso de teste.");
|
|
717
|
+
let given;
|
|
718
|
+
let when;
|
|
719
|
+
let expect;
|
|
720
|
+
let error;
|
|
721
|
+
let docs;
|
|
722
|
+
let comments;
|
|
723
|
+
while (this.atual().tipo !== "fim_arquivo" && this.atual().valor !== "}") {
|
|
724
|
+
this.ignorarRuido();
|
|
725
|
+
if (this.atual().valor === "}") {
|
|
726
|
+
break;
|
|
727
|
+
}
|
|
728
|
+
switch (this.atual().valor) {
|
|
729
|
+
case "given":
|
|
730
|
+
given = this.parseBlocoGenerico("given");
|
|
731
|
+
break;
|
|
732
|
+
case "when":
|
|
733
|
+
when = this.parseBlocoGenerico("when");
|
|
734
|
+
break;
|
|
735
|
+
case "expect":
|
|
736
|
+
expect = this.parseBlocoGenerico("expect");
|
|
737
|
+
break;
|
|
738
|
+
case "error":
|
|
739
|
+
error = this.parseBlocoGenerico("error");
|
|
740
|
+
break;
|
|
741
|
+
case "docs":
|
|
742
|
+
docs = this.parseBlocoGenerico("docs");
|
|
743
|
+
break;
|
|
744
|
+
case "comments":
|
|
745
|
+
comments = this.parseBlocoGenerico("comments");
|
|
746
|
+
break;
|
|
747
|
+
default:
|
|
748
|
+
this.avancar();
|
|
749
|
+
break;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
const fim = this.consumirValor("}", "Era esperado fechar o caso de teste.").intervalo.fim;
|
|
753
|
+
return {
|
|
754
|
+
tipo: "caso_teste",
|
|
755
|
+
nome,
|
|
756
|
+
given,
|
|
757
|
+
when,
|
|
758
|
+
expect,
|
|
759
|
+
error,
|
|
760
|
+
docs,
|
|
761
|
+
comments,
|
|
762
|
+
intervalo: { inicio, fim },
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
function normalizarOrigemUse(valor) {
|
|
767
|
+
switch (valor.toLowerCase()) {
|
|
768
|
+
case "sema":
|
|
769
|
+
return "sema";
|
|
770
|
+
case "ts":
|
|
771
|
+
case "typescript":
|
|
772
|
+
return "ts";
|
|
773
|
+
case "py":
|
|
774
|
+
case "python":
|
|
775
|
+
return "py";
|
|
776
|
+
case "dart":
|
|
777
|
+
return "dart";
|
|
778
|
+
case "lua":
|
|
779
|
+
return "lua";
|
|
780
|
+
case "php":
|
|
781
|
+
return "php";
|
|
782
|
+
case "cs":
|
|
783
|
+
case "csharp":
|
|
784
|
+
case "dotnet":
|
|
785
|
+
return "cs";
|
|
786
|
+
case "java":
|
|
787
|
+
return "java";
|
|
788
|
+
case "go":
|
|
789
|
+
case "golang":
|
|
790
|
+
return "go";
|
|
791
|
+
case "rust":
|
|
792
|
+
case "rs":
|
|
793
|
+
return "rust";
|
|
794
|
+
case "cpp":
|
|
795
|
+
case "cxx":
|
|
796
|
+
case "cc":
|
|
797
|
+
case "c++":
|
|
798
|
+
return "cpp";
|
|
799
|
+
default:
|
|
800
|
+
return undefined;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
export function parsear(tokens) {
|
|
804
|
+
const parser = new Parser(tokens);
|
|
805
|
+
return parser.analisar();
|
|
806
|
+
}
|
|
807
|
+
//# sourceMappingURL=parser.js.map
|