Replace #! notation with #:

This commit is contained in:
Emery Hemingway 2024-02-08 14:22:18 +00:00
parent c0a8a1a76c
commit 9134fecb36
7 changed files with 8 additions and 8 deletions

View File

@ -41,7 +41,7 @@ SimplePattern =
; special builtins: bool, float, double, int, string, bytes, symbol
/ <atom @atomKind AtomKind>
; matches an embedded value in the input: #!p
; matches an embedded value in the input: #:p
/ <embedded @interface SimplePattern>
; =symbol, <<lit> any>, or plain non-symbol atom

View File

@ -68,7 +68,7 @@ grammar "Preserves":
SymbolOrNumber <- >(+(Alpha | Digit | sympunct | symuchar))
Symbol <- QuotedSymbol | (SymbolOrNumber * &delimiter)
Embedded <- "#!" * Value
Embedded <- "#:" * Value
Annotation <- '@' * Value * Value

View File

@ -474,7 +474,7 @@ proc toStrLit(loc: Location; sp: SimplePattern): PNode =
result = toStrLit(loc, def)
of SimplePatternKind.embedded:
doAssert not loc.schema.hasEmbeddedType
result = PNode(kind: nkStrLit, strVal: "#!" & toStrLit(loc, sp.embedded.interface).strVal)
result = PNode(kind: nkStrLit, strVal: "#:" & toStrLit(loc, sp.embedded.interface).strVal)
else: raiseAssert $sp
proc toFieldIdent(s: string): PNode =

View File

@ -220,7 +220,7 @@ proc parsePreservesAtom*(text: string): Atom =
let pegParser = peg("Atom", a: Atom):
# Override rules from pegs.nim
Atom <- ?"#!" * Preserves.Atom
Atom <- ?"#:" * Preserves.Atom
Preserves.Boolean <- Preserves.Boolean:
case $0

View File

@ -44,7 +44,7 @@ proc writeSymbol(stream: Stream; sym: string) =
proc writeText*(stream: Stream; pr: Value; mode = textPreserves) =
## Encode Preserves to a `Stream` as text.
if pr.embedded: write(stream, "#!")
if pr.embedded: write(stream, "#:")
case pr.kind:
of pkBoolean:
case pr.bool
@ -139,7 +139,7 @@ proc writeText*(stream: Stream; pr: Value; mode = textPreserves) =
writeText(stream, value, mode)
write(stream, '}')
of pkEmbedded:
if not pr.embedded: write(stream, "#!")
if not pr.embedded: write(stream, "#:")
if pr.embeddedRef.isNil:
write(stream, "<null>")
else:

View File

@ -180,7 +180,7 @@ const parser = peg("Schema", p: ParseState):
Symbol <- "symbol":
pushStack initRecord(toSymbol"atom", toSymbol"Symbol")
EmbeddedPattern <- "#!" * SimplePattern:
EmbeddedPattern <- "#:" * SimplePattern:
var n = initRecord(toSymbol"embedded", popStack())
pushStack n

View File

@ -23,7 +23,7 @@ suite "conversions":
c = Foobar(a: 1, b: @[2], c: ("ku", ), e: some(true))
b = toPreserves(c)
a = preservesTo(b, Foobar)
check($b == """{a: 1 b: [2] c: #!["ku"] e: #t}""")
check($b == """{a: 1 b: [2] c: #:["ku"] e: #t}""")
check(a.isSome)
if a.isSome: check(get(a) == c)
check(b.kind == pkDictionary)