@semacode/cli 1.5.16 → 1.5.18

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