diff options
author | Tyler <tslimkemann42@gmail.com> | 2018-05-22 19:27:28 -0700 |
---|---|---|
committer | Dmitry Atamanov <data-man@users.noreply.github.com> | 2018-05-23 05:27:28 +0300 |
commit | 799674168d969afa73a507d59de7e34b360f1047 (patch) | |
tree | 657635e008260388dc0256b6a858f3d01efa0f36 /lib/pure | |
parent | c6a9a9c30b2b758f3f5da582b2f1a8c4b0d7d503 (diff) | |
download | Nim-799674168d969afa73a507d59de7e34b360f1047.tar.gz |
Patch the PEG library to work with the JS backend (#7866)
* Added compiler check on transformFile
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/pegs.nim | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/lib/pure/pegs.nim b/lib/pure/pegs.nim index 830429842..e13bc8329 100644 --- a/lib/pure/pegs.nim +++ b/lib/pure/pegs.nim @@ -1010,14 +1010,18 @@ proc replace*(s: string, sub: Peg, cb: proc( inc(m) add(result, substr(s, i)) -proc transformFile*(infile, outfile: string, - subs: varargs[tuple[pattern: Peg, repl: string]]) {. - rtl, extern: "npegs$1".} = - ## reads in the file `infile`, performs a parallel replacement (calls - ## `parallelReplace`) and writes back to `outfile`. Raises ``EIO`` if an - ## error occurs. This is supposed to be used for quick scripting. - var x = readFile(infile).string - writeFile(outfile, x.parallelReplace(subs)) +when not defined(js): + proc transformFile*(infile, outfile: string, + subs: varargs[tuple[pattern: Peg, repl: string]]) {. + rtl, extern: "npegs$1".} = + ## reads in the file `infile`, performs a parallel replacement (calls + ## `parallelReplace`) and writes back to `outfile`. Raises ``EIO`` if an + ## 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 + writeFile(outfile, x.parallelReplace(subs)) + iterator split*(s: string, sep: Peg): string = ## Splits the string `s` into substrings. |