schema: sort dictionary fields by key
Size of the value is a compelling alternative but cannot be inferred at code generation time.
This commit is contained in:
parent
fa5441bd01
commit
c087294b23
|
@ -597,7 +597,13 @@ proc addFields(recList: PNode; loc: Location; known: var TypeTable; pat: Pattern
|
||||||
reclist
|
reclist
|
||||||
|
|
||||||
proc addFields(recList: PNode; loc: Location; known: var TypeTable; entries: DictionaryEntries; parentName: string): PNode {.discardable.} =
|
proc addFields(recList: PNode; loc: Location; known: var TypeTable; entries: DictionaryEntries; parentName: string): PNode {.discardable.} =
|
||||||
|
var sortedEntries =
|
||||||
|
initOrderedTable[Preserve[void], NamedSimplePattern](entries.len)
|
||||||
for key, val in entries.pairs:
|
for key, val in entries.pairs:
|
||||||
|
sortedEntries[key] = val
|
||||||
|
sort(sortedEntries) do (x, y: (Preserve[void], NamedSimplePattern)) -> int:
|
||||||
|
cmp(x[0], y[0])
|
||||||
|
for key, val in sortedEntries.pairs:
|
||||||
doAssert(key.isSymbol)
|
doAssert(key.isSymbol)
|
||||||
let label = string key.symbol
|
let label = string key.symbol
|
||||||
addField(recList, loc, known, val.pattern, label)
|
addField(recList, loc, known, val.pattern, label)
|
||||||
|
|
|
@ -4,7 +4,10 @@
|
||||||
# this module is included in ../../preserves.nim
|
# this module is included in ../../preserves.nim
|
||||||
|
|
||||||
import std/[parseutils, unicode]
|
import std/[parseutils, unicode]
|
||||||
from std/sequtils import insert
|
|
||||||
|
when isMainModule:
|
||||||
|
from std/sequtils import insert
|
||||||
|
|
||||||
from std/strutils import Whitespace, parseFloat, parseHexStr, parseInt, tokenize
|
from std/strutils import Whitespace, parseFloat, parseHexStr, parseInt, tokenize
|
||||||
import npeg
|
import npeg
|
||||||
import ../pegs
|
import ../pegs
|
||||||
|
|
Loading…
Reference in New Issue