Made NimYAML compile for JS

This commit is contained in:
Felix Krause 2017-03-29 17:14:50 +02:00
parent 83efb88978
commit f017a57d86
3 changed files with 68 additions and 58 deletions

View File

@ -1065,6 +1065,7 @@ proc init(c: ParserContext, p: YamlParser) {.raises: [YamlParserError].} =
c.explicitFlowKey = false
c.advance()
when not defined(JS):
proc parse*(p: YamlParser, s: Stream): YamlStream
{.raises: [YamlParserError].} =
## Parse the given stream as YAML character stream.

View File

@ -42,7 +42,8 @@ type
newlines*: int
# internals
source: pointer
when defined(JS): sSource: StringSource
else: source: pointer
inFlow: bool
literalEndIndent: int
nextState, lineStartState, inlineState, insideLineImpl, insideDocImpl,
@ -1140,6 +1141,7 @@ proc init*[T](lex: YamlLexer) =
lex.tokenLineGetter = tokenLine[T]
lex.searchColonImpl = searchColon[T]
when not defined(JS):
proc newYamlLexer*(source: Stream): YamlLexer {.raises: [YamlLexerError].} =
let blSource = new(BaseLexer)
try: blSource[].open(source)
@ -1159,6 +1161,12 @@ proc newYamlLexer*(source: Stream): YamlLexer {.raises: [YamlLexerError].} =
proc newYamlLexer*(source: string, startAt: int = 0): YamlLexer
{.raises: [].} =
when defined(JS):
let sSource = StringSource(pos: startAt, lineStart: startAt, line: 1,
src: source)
result = YamlLexer(buf: "", sSource: sSource,
inFlow: false, c: sSource.src[startAt], newlines: 0, folded: true)
else:
let sSource = new(StringSource)
sSource[] = StringSource(pos: startAt, lineStart: startAt, line: 1,
src: source)

View File

@ -176,6 +176,7 @@ proc constructJson*(s: var YamlStream): seq[JsonNode]
else:
internalError("Unexpected node kind: " & $levels[levels.high].node.kind)
when not defined(JS):
proc loadToJson*(s: Stream): seq[JsonNode]
{.raises: [YamlParserError, YamlConstructionError, IOError].} =
## Uses `YamlParser <#YamlParser>`_ and