From 5a90255993d56f5101da850a5dce03d74f85a3c7 Mon Sep 17 00:00:00 2001 From: Felix Krause Date: Thu, 1 Sep 2016 21:08:27 +0200 Subject: [PATCH] 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! --- private/presenter.nim | 51 +++++++++++++++++++-------------------- private/serialization.nim | 5 ++++ private/streams.nim | 1 - yaml.nim | 2 +- 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/private/presenter.nim b/private/presenter.nim index 289167d..03b5b40 100644 --- a/private/presenter.nim +++ b/private/presenter.nim @@ -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() diff --git a/private/serialization.nim b/private/serialization.nim index 0e9be69..abb5055 100644 --- a/private/serialization.nim +++ b/private/serialization.nim @@ -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 diff --git a/private/streams.nim b/private/streams.nim index dace89a..63f3d0d 100644 --- a/private/streams.nim +++ b/private/streams.nim @@ -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 diff --git a/yaml.nim b/yaml.nim index 73d0d82..8aa457c 100644 --- a/yaml.nim +++ b/yaml.nim @@ -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