Add support for strictEffects to std/pegs (#18949)

* Add support for `strictEffects` to `std/pegs`

* Fixed support of older Nim versions

Co-authored-by: quantimnot <quantimnot@users.noreply.github.com>
This commit is contained in:
quantimnot
2021-10-04 15:27:13 -04:00
committed by GitHub
parent 500d5f0f38
commit f017eadc97
2 changed files with 7 additions and 1 deletions

View File

@@ -1285,9 +1285,12 @@ proc parallelReplace*(s: string, subs: varargs[
# copy the rest:
add(result, substr(s, i))
when not defined(nimHasEffectsOf):
{.pragma: effectsOf.}
proc replace*(s: string, sub: Peg, cb: proc(
match: int, cnt: int, caps: openArray[string]): string): string {.
rtl, extern: "npegs$1cb".} =
rtl, extern: "npegs$1cb", effectsOf: cb.} =
## Replaces `sub` in `s` by the resulting strings from the callback.
## The callback proc receives the index of the current match (starting with 0),
## the count of captures and an open array with the captures of each match. Examples:

View File

@@ -51,6 +51,9 @@ Event parser output
'''
"""
when defined(nimHasEffectsOf):
{.experimental: "strictEffects".}
import std/[strutils, streams, pegs]
const