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

View File

@ -121,6 +121,11 @@ proc constructObject*(s: var YamlStream, c: ConstructionContext,
constructObject(s, c, u32Result) constructObject(s, c, u32Result)
result= uint(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, proc representObject*[T: uint8|uint16|uint32|uint64](value: T, ts: TagStyle,
c: SerializationContext, tag: TagId) {.raises: [].} = c: SerializationContext, tag: TagId) {.raises: [].} =
## represents an unsigned integer value as YAML scalar ## represents an unsigned integer value as YAML scalar

View File

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

View File

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