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:
parent
500d5f0f38
commit
f017eadc97
2 changed files with 7 additions and 1 deletions
|
|
@ -1285,9 +1285,12 @@ proc parallelReplace*(s: string, subs: varargs[
|
||||||
# copy the rest:
|
# copy the rest:
|
||||||
add(result, substr(s, i))
|
add(result, substr(s, i))
|
||||||
|
|
||||||
|
when not defined(nimHasEffectsOf):
|
||||||
|
{.pragma: effectsOf.}
|
||||||
|
|
||||||
proc replace*(s: string, sub: Peg, cb: proc(
|
proc replace*(s: string, sub: Peg, cb: proc(
|
||||||
match: int, cnt: int, caps: openArray[string]): string): string {.
|
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.
|
## 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 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:
|
## the count of captures and an open array with the captures of each match. Examples:
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,9 @@ Event parser output
|
||||||
'''
|
'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
when defined(nimHasEffectsOf):
|
||||||
|
{.experimental: "strictEffects".}
|
||||||
|
|
||||||
import std/[strutils, streams, pegs]
|
import std/[strutils, streams, pegs]
|
||||||
|
|
||||||
const
|
const
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue