Move preserves/parse module into preserves
Some macros in preserves call `parsePreserves` so include that proc implicitly.
This commit is contained in:
parent
5408cb859a
commit
1dcad539f4
|
@ -256,8 +256,7 @@ func step*(pr, idx: Preserve): Option[Preserve] =
|
|||
## Step into `pr` by index `idx`.
|
||||
## Works for sequences, records, and dictionaries.
|
||||
runnableExamples:
|
||||
import options
|
||||
import preserves, preserves/parse
|
||||
import std/options
|
||||
assert step(parsePreserves("""<foo 1 2>"""), 1.toPreserve) == some(2.toPreserve)
|
||||
assert step(parsePreserves("""{ foo: 1 bar: 2}"""), "foo".toSymbol) == some(1.toPreserve)
|
||||
assert step(parsePreserves("""[ ]"""), 1.toPreserve) == none(Preserve[void])
|
||||
|
@ -786,7 +785,6 @@ proc fromPreserve*[T, E](v: var T; pr: Preserve[E]): bool =
|
|||
## trace is printing during `fromPreserve`.
|
||||
# TODO: {.raises: [].}
|
||||
runnableExamples:
|
||||
import preserves, preserves/parse
|
||||
type Foo {.preservesRecord: "foo".} = object
|
||||
x, y: int
|
||||
var foo: Foo
|
||||
|
@ -967,7 +965,7 @@ proc preserveTo*(pr: Preserve; T: typedesc): Option[T] =
|
|||
## Reverse of `toPreserve`.
|
||||
# TODO: {.raises: [].}
|
||||
runnableExamples:
|
||||
import std/options, preserves, preserves/parse
|
||||
import std/options
|
||||
type Foo {.preservesRecord: "foo".} = object
|
||||
x, y: int
|
||||
|
||||
|
@ -1136,3 +1134,5 @@ proc concat[E](result: var string; pr: Preserve[E]) =
|
|||
|
||||
proc `$`*(pr: Preserve): string = concat(result, pr)
|
||||
## Generate the textual representation of ``pr``.
|
||||
|
||||
include ./preserves/private/parse
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
# SPDX-FileCopyrightText: 2021 ☭ Emery Hemingway
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
|
||||
## NPEG rules for Preserves.
|
||||
|
||||
import npeg, npeg/lib/utf8
|
||||
|
||||
when defined(nimHasUsed): {.used.}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
# SPDX-FileCopyrightText: 2021 ☭ Emery Hemingway
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
|
||||
import std/[base64, parseutils, sets, strutils, tables]
|
||||
# this module is included in ../../preserves.nim
|
||||
|
||||
import std/[parseutils, strutils]
|
||||
import npeg
|
||||
import ../preserves, ./pegs
|
||||
import ../pegs
|
||||
|
||||
type
|
||||
Value = Preserve[void]
|
||||
|
@ -15,6 +17,9 @@ proc shrink(stack: var Stack; n: int) = stack.setLen(stack.len - n)
|
|||
template pushStack(v: Value) = stack.add((v, capture[0].si))
|
||||
|
||||
proc parsePreserves*(text: string): Preserve[void] {.gcsafe.} =
|
||||
## Parse a text-encoded Preserves `string` to a `Preserve` value.
|
||||
runnableExamples:
|
||||
assert parsePreserves"[ 1 2 3 ]" == [ 1, 2, 3 ].toPreserve
|
||||
const pegParser = peg("Document", stack: Stack):
|
||||
# Override rules from pegs.nim
|
||||
|
||||
|
@ -105,8 +110,6 @@ proc parsePreserves*(text: string): Preserve[void] {.gcsafe.} =
|
|||
stack.pop.value
|
||||
|
||||
proc parsePreserves*(text: string; E: typedesc): Preserve[E] {.gcsafe.} =
|
||||
## Parse a text-encoded Preserves `string` to a `Preserve[E]` value for embedded type `E`.
|
||||
when E is void: parsePreserves(text)
|
||||
else: mapEmbeds(parsePreserves(text), E)
|
||||
|
||||
when isMainModule:
|
||||
assert(parsePreserves("#f") == Preserve())
|
Loading…
Reference in New Issue