@semacode/cli 1.2.17 → 1.3.1

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 (128) hide show
  1. package/README.md +2 -2
  2. package/dist/index.js +58 -10
  3. package/dist/projeto.js +4 -1
  4. package/package.json +23 -29
  5. package/src/cpp-symbols.ts +82 -0
  6. package/src/dotnet-http.ts +355 -0
  7. package/src/drift.ts +2455 -0
  8. package/src/go-http.ts +118 -0
  9. package/src/importador.ts +3448 -0
  10. package/src/index.ts +4470 -0
  11. package/src/java-http.ts +247 -0
  12. package/src/projeto.ts +810 -0
  13. package/src/python-http.ts +258 -0
  14. package/src/rust-http.ts +125 -0
  15. package/src/tipos.ts +22 -0
  16. package/src/typescript-http.ts +1076 -0
  17. package/tsconfig.json +20 -0
  18. package/AGENTS.md +0 -50
  19. package/LICENSE +0 -22
  20. package/SEMA_BRIEF.curto.txt +0 -9
  21. package/SEMA_BRIEF.md +0 -49
  22. package/SEMA_BRIEF.micro.txt +0 -7
  23. package/SEMA_INDEX.json +0 -546
  24. package/dist/cpp-symbols.d.ts +0 -10
  25. package/dist/cpp-symbols.js.map +0 -1
  26. package/dist/dotnet-http.d.ts +0 -23
  27. package/dist/dotnet-http.js.map +0 -1
  28. package/dist/drift.d.ts +0 -118
  29. package/dist/drift.js.map +0 -1
  30. package/dist/go-http.d.ts +0 -23
  31. package/dist/go-http.js.map +0 -1
  32. package/dist/importador.d.ts +0 -29
  33. package/dist/importador.js.map +0 -1
  34. package/dist/index.d.ts +0 -2
  35. package/dist/index.js.map +0 -1
  36. package/dist/java-http.d.ts +0 -23
  37. package/dist/java-http.js.map +0 -1
  38. package/dist/lua-symbols.d.ts +0 -8
  39. package/dist/lua-symbols.js.map +0 -1
  40. package/dist/projeto.d.ts +0 -48
  41. package/dist/projeto.js.map +0 -1
  42. package/dist/python-http.d.ts +0 -23
  43. package/dist/python-http.js.map +0 -1
  44. package/dist/rust-http.d.ts +0 -23
  45. package/dist/rust-http.js.map +0 -1
  46. package/dist/tipos.d.ts +0 -3
  47. package/dist/tipos.js.map +0 -1
  48. package/dist/typescript-http.d.ts +0 -35
  49. package/dist/typescript-http.js.map +0 -1
  50. package/docs/AGENT_STARTER.md +0 -102
  51. package/docs/como-ensinar-a-sema-para-ia.md +0 -149
  52. package/docs/fluxo-pratico-ia-sema.md +0 -177
  53. package/docs/instalacao-e-primeiro-uso.md +0 -196
  54. package/docs/integracao-com-ia.md +0 -228
  55. package/docs/pagamento-ponta-a-ponta.md +0 -155
  56. package/docs/prompt-base-ia-sema.md +0 -104
  57. package/docs/sintaxe.md +0 -361
  58. package/exemplos/automacao.sema +0 -107
  59. package/exemplos/cadastro_usuario.sema +0 -54
  60. package/exemplos/calculadora.sema +0 -78
  61. package/exemplos/crud_simples.sema +0 -89
  62. package/exemplos/operacao_estrategia.sema +0 -402
  63. package/exemplos/pagamento.sema +0 -222
  64. package/exemplos/pagamento_dominio.sema +0 -35
  65. package/exemplos/testes_embutidos.sema +0 -45
  66. package/exemplos/tratamento_erro.sema +0 -157
  67. package/llms-full.txt +0 -34
  68. package/llms.txt +0 -17
  69. package/node_modules/@sema/gerador-dart/dist/index.d.ts +0 -3
  70. package/node_modules/@sema/gerador-dart/dist/index.js +0 -44
  71. package/node_modules/@sema/gerador-dart/dist/index.js.map +0 -1
  72. package/node_modules/@sema/gerador-dart/package.json +0 -7
  73. package/node_modules/@sema/gerador-lua/dist/index.d.ts +0 -3
  74. package/node_modules/@sema/gerador-lua/dist/index.js +0 -328
  75. package/node_modules/@sema/gerador-lua/dist/index.js.map +0 -1
  76. package/node_modules/@sema/gerador-lua/package.json +0 -7
  77. package/node_modules/@sema/gerador-python/dist/index.d.ts +0 -6
  78. package/node_modules/@sema/gerador-python/dist/index.js +0 -628
  79. package/node_modules/@sema/gerador-python/dist/index.js.map +0 -1
  80. package/node_modules/@sema/gerador-python/package.json +0 -7
  81. package/node_modules/@sema/gerador-typescript/dist/index.d.ts +0 -6
  82. package/node_modules/@sema/gerador-typescript/dist/index.js +0 -656
  83. package/node_modules/@sema/gerador-typescript/dist/index.js.map +0 -1
  84. package/node_modules/@sema/gerador-typescript/package.json +0 -7
  85. package/node_modules/@sema/nucleo/dist/ast/tipos.d.ts +0 -122
  86. package/node_modules/@sema/nucleo/dist/ast/tipos.js +0 -2
  87. package/node_modules/@sema/nucleo/dist/ast/tipos.js.map +0 -1
  88. package/node_modules/@sema/nucleo/dist/diagnosticos/index.d.ts +0 -21
  89. package/node_modules/@sema/nucleo/dist/diagnosticos/index.js +0 -12
  90. package/node_modules/@sema/nucleo/dist/diagnosticos/index.js.map +0 -1
  91. package/node_modules/@sema/nucleo/dist/formatador/index.d.ts +0 -9
  92. package/node_modules/@sema/nucleo/dist/formatador/index.js +0 -445
  93. package/node_modules/@sema/nucleo/dist/formatador/index.js.map +0 -1
  94. package/node_modules/@sema/nucleo/dist/index.d.ts +0 -34
  95. package/node_modules/@sema/nucleo/dist/index.js +0 -95
  96. package/node_modules/@sema/nucleo/dist/index.js.map +0 -1
  97. package/node_modules/@sema/nucleo/dist/ir/conversor.d.ts +0 -5
  98. package/node_modules/@sema/nucleo/dist/ir/conversor.js +0 -781
  99. package/node_modules/@sema/nucleo/dist/ir/conversor.js.map +0 -1
  100. package/node_modules/@sema/nucleo/dist/ir/modelos.d.ts +0 -285
  101. package/node_modules/@sema/nucleo/dist/ir/modelos.js +0 -2
  102. package/node_modules/@sema/nucleo/dist/ir/modelos.js.map +0 -1
  103. package/node_modules/@sema/nucleo/dist/lexer/lexer.d.ts +0 -7
  104. package/node_modules/@sema/nucleo/dist/lexer/lexer.js +0 -122
  105. package/node_modules/@sema/nucleo/dist/lexer/lexer.js.map +0 -1
  106. package/node_modules/@sema/nucleo/dist/lexer/tokens.d.ts +0 -8
  107. package/node_modules/@sema/nucleo/dist/lexer/tokens.js +0 -46
  108. package/node_modules/@sema/nucleo/dist/lexer/tokens.js.map +0 -1
  109. package/node_modules/@sema/nucleo/dist/parser/parser.d.ts +0 -9
  110. package/node_modules/@sema/nucleo/dist/parser/parser.js +0 -656
  111. package/node_modules/@sema/nucleo/dist/parser/parser.js.map +0 -1
  112. package/node_modules/@sema/nucleo/dist/semantico/analisador.d.ts +0 -57
  113. package/node_modules/@sema/nucleo/dist/semantico/analisador.js +0 -1497
  114. package/node_modules/@sema/nucleo/dist/semantico/analisador.js.map +0 -1
  115. package/node_modules/@sema/nucleo/dist/semantico/estruturas.d.ts +0 -104
  116. package/node_modules/@sema/nucleo/dist/semantico/estruturas.js +0 -445
  117. package/node_modules/@sema/nucleo/dist/semantico/estruturas.js.map +0 -1
  118. package/node_modules/@sema/nucleo/dist/semantico/seguranca.d.ts +0 -91
  119. package/node_modules/@sema/nucleo/dist/semantico/seguranca.js +0 -258
  120. package/node_modules/@sema/nucleo/dist/semantico/seguranca.js.map +0 -1
  121. package/node_modules/@sema/nucleo/dist/util/arquivos.d.ts +0 -2
  122. package/node_modules/@sema/nucleo/dist/util/arquivos.js +0 -25
  123. package/node_modules/@sema/nucleo/dist/util/arquivos.js.map +0 -1
  124. package/node_modules/@sema/nucleo/package.json +0 -7
  125. package/node_modules/@sema/padroes/dist/index.d.ts +0 -21
  126. package/node_modules/@sema/padroes/dist/index.js +0 -159
  127. package/node_modules/@sema/padroes/dist/index.js.map +0 -1
  128. package/node_modules/@sema/padroes/package.json +0 -7
@@ -1,656 +0,0 @@
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