Patch the PEG library to work with the JS backend (#7866)

* Added compiler check on transformFile
This commit is contained in:
Tyler 2018-05-22 19:27:28 -07:00 • committed by Dmitry Atamanov
commit 799674168d

View file

@ -1010,15 +1010,19 @@ proc replace*(s: string, sub: Peg, cb: proc(
inc(m) inc(m)
add(result, substr(s, i)) add(result, substr(s, i))
proc transformFile*(infile, outfile: string, when not defined(js):
proc transformFile*(infile, outfile: string,
subs: varargs[tuple[pattern: Peg, repl: string]]) {. subs: varargs[tuple[pattern: Peg, repl: string]]) {.
rtl, extern: "npegs$1".} = rtl, extern: "npegs$1".} =
## reads in the file `infile`, performs a parallel replacement (calls ## reads in the file `infile`, performs a parallel replacement (calls
## `parallelReplace`) and writes back to `outfile`. Raises ``EIO`` if an ## `parallelReplace`) and writes back to `outfile`. Raises ``EIO`` if an
## error occurs. This is supposed to be used for quick scripting. ## error occurs. This is supposed to be used for quick scripting.
##
## **Note**: this proc does not exist while using the JS backend.
var x = readFile(infile).string var x = readFile(infile).string
writeFile(outfile, x.parallelReplace(subs)) writeFile(outfile, x.parallelReplace(subs))
iterator split*(s: string, sep: Peg): string = iterator split*(s: string, sep: Peg): string =
## Splits the string `s` into substrings. ## Splits the string `s` into substrings.
## ##