Fixed remaining JS compilation issues

* Changed transform() to not use first class iterators
 * provide a archaic `$` for uints that will break if
   poked
 * TODO: test JS output!
This commit is contained in:
Felix Krause 2016-09-01 21:08:27 +02:00
parent ad18db5113
commit 5a90255993
4 changed files with 31 additions and 28 deletions

View File

@ -601,32 +601,31 @@ proc transform*(input: Stream, output: Stream,
events = parser.parse(input)
try:
if options.style == psCanonical:
var specificTagEvents = iterator(): YamlStreamEvent =
for e in events:
var event = e
case event.kind
of yamlStartDoc, yamlEndDoc, yamlEndMap, yamlAlias, yamlEndSeq:
discard
of yamlStartMap:
if event.mapTag in [yTagQuestionMark, yTagExclamationMark]:
event.mapTag = yTagMapping
of yamlStartSeq:
if event.seqTag in [yTagQuestionMark, yTagExclamationMark]:
event.seqTag = yTagSequence
of yamlScalar:
if event.scalarTag == yTagQuestionMark:
case guessType(event.scalarContent)
of yTypeInteger: event.scalarTag = yTagInteger
of yTypeFloat, yTypeFloatInf, yTypeFloatNaN:
event.scalarTag = yTagFloat
of yTypeBoolTrue, yTypeBoolFalse: event.scalarTag = yTagBoolean
of yTypeNull: event.scalarTag = yTagNull
of yTypeUnknown: event.scalarTag = yTagString
elif event.scalarTag == yTagExclamationMark:
event.scalarTag = yTagString
yield event
var s = initYamlStream(specificTagEvents)
present(s, output, tagLib, options)
var bys: YamlStream = newBufferYamlStream()
for e in events:
var event = e
case event.kind
of yamlStartDoc, yamlEndDoc, yamlEndMap, yamlAlias, yamlEndSeq:
discard
of yamlStartMap:
if event.mapTag in [yTagQuestionMark, yTagExclamationMark]:
event.mapTag = yTagMapping
of yamlStartSeq:
if event.seqTag in [yTagQuestionMark, yTagExclamationMark]:
event.seqTag = yTagSequence
of yamlScalar:
if event.scalarTag == yTagQuestionMark:
case guessType(event.scalarContent)
of yTypeInteger: event.scalarTag = yTagInteger
of yTypeFloat, yTypeFloatInf, yTypeFloatNaN:
event.scalarTag = yTagFloat
of yTypeBoolTrue, yTypeBoolFalse: event.scalarTag = yTagBoolean
of yTypeNull: event.scalarTag = yTagNull
of yTypeUnknown: event.scalarTag = yTagString
elif event.scalarTag == yTagExclamationMark:
event.scalarTag = yTagString
BufferYamlStream(bys).buf.add(e)
present(bys, output, tagLib, options)
else: present(events, output, tagLib, options)
except YamlStreamError:
var e = getCurrentException()

View File

@ -121,6 +121,11 @@ proc constructObject*(s: var YamlStream, c: ConstructionContext,
constructObject(s, c, u32Result)
result= uint(u32Result)
when defined(JS):
# TODO: this is a dirty hack and may lead to overflows!
proc `$`(x: uint8|uint16|uint32|uint64|uint): string =
result = $BiggestInt(x)
proc representObject*[T: uint8|uint16|uint32|uint64](value: T, ts: TagStyle,
c: SerializationContext, tag: TagId) {.raises: [].} =
## represents an unsigned integer value as YAML scalar

View File

@ -85,7 +85,6 @@ proc finished*(s: YamlStream): bool =
raise e
except Exception:
let cur = getCurrentException()
echo cur.getStackTrace()
var e = newException(YamlStreamError, cur.msg)
e.parent = cur
raise e

View File

@ -750,9 +750,9 @@ setTagUri(float64, "!nim:system:float64", yTagNimFloat64)
include private.tagLibrary
include private.events
include private.json
include private.streams
include private.presenter
include private.parse
include private.hints
include private.streams
include private.serialization
include private.dom