papagaio 0.1.4 → 0.1.6

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.
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { Papagaio } from "./src/papagaio.js";
2
+ import { Papagaio } from "./papagaio.js";
3
3
  import fs from "fs";
4
4
 
5
5
  const file = process.argv[2];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "papagaio",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "easy yet powerful preprocessor",
5
5
  "main": "papagaio.js",
6
6
  "type": "module",
@@ -23,6 +23,6 @@
23
23
  "homepage": "https://github.com/jardimdanificado/papagaio#readme"
24
24
  ,
25
25
  "bin": {
26
- "papagaio": "./node.js"
26
+ "papagaio": "./cli.js"
27
27
  }
28
28
  }
package/papagaio.js CHANGED
@@ -207,12 +207,22 @@ export class Papagaio {
207
207
  j++;
208
208
  }
209
209
 
210
- if (token) {
211
- const escapedToken = this.#escapeRegex(token);
212
- regex += `((?:.|\\r|\\n)*?)${escapedToken}`;
213
- i = j;
214
- continue;
210
+ // Aqui convertemos o token em uma parte de regex:
211
+ // - qualquer ocorrência de $$ (S2) vira \s*
212
+ // - o restante é escapado apropriadamente
213
+ let tokenRegex = '';
214
+ if (token.length === 0) {
215
+ tokenRegex = ''; // sem token → apenas captura sem terminador
216
+ } else {
217
+ // dividir pelo S2 e escapar cada pedaço literal
218
+ const parts = token.split(S2);
219
+ tokenRegex = parts.map(p => this.#escapeRegex(p)).join('\\s*');
215
220
  }
221
+
222
+ // captura não-gulosa para o ... seguida do token interpretado
223
+ regex += `((?:.|\\r|\\n)*?)${tokenRegex}`;
224
+ i = j;
225
+ continue;
216
226
  }
217
227
 
218
228
  if (varName) {
@@ -240,6 +250,7 @@ export class Papagaio {
240
250
  return new RegExp(regex, 'g');
241
251
  }
242
252
 
253
+
243
254
  #buildBalancedBlockRegex(open, close) {
244
255
  const escapedOpen = open === '(' ? '\\(' : (open === '[' ? '\\[' : open === '{' ? '\\{' : open === '<' ? '\\<' : open);
245
256
  const escapedClose = close === ')' ? '\\)' : (close === ']' ? '\\]' : close === '}' ? '\\}' : close === '>' ? '\\>' : close);