@semacode/cli 1.3.0 → 1.3.2

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