mirror of https://github.com/status-im/NimYAML.git
Made NimYAML compile for JS
This commit is contained in:
parent
83efb88978
commit
f017a57d86
|
@ -1065,6 +1065,7 @@ proc init(c: ParserContext, p: YamlParser) {.raises: [YamlParserError].} =
|
||||||
c.explicitFlowKey = false
|
c.explicitFlowKey = false
|
||||||
c.advance()
|
c.advance()
|
||||||
|
|
||||||
|
when not defined(JS):
|
||||||
proc parse*(p: YamlParser, s: Stream): YamlStream
|
proc parse*(p: YamlParser, s: Stream): YamlStream
|
||||||
{.raises: [YamlParserError].} =
|
{.raises: [YamlParserError].} =
|
||||||
## Parse the given stream as YAML character stream.
|
## Parse the given stream as YAML character stream.
|
||||||
|
|
|
@ -42,7 +42,8 @@ type
|
||||||
newlines*: int
|
newlines*: int
|
||||||
|
|
||||||
# internals
|
# internals
|
||||||
source: pointer
|
when defined(JS): sSource: StringSource
|
||||||
|
else: source: pointer
|
||||||
inFlow: bool
|
inFlow: bool
|
||||||
literalEndIndent: int
|
literalEndIndent: int
|
||||||
nextState, lineStartState, inlineState, insideLineImpl, insideDocImpl,
|
nextState, lineStartState, inlineState, insideLineImpl, insideDocImpl,
|
||||||
|
@ -1140,6 +1141,7 @@ proc init*[T](lex: YamlLexer) =
|
||||||
lex.tokenLineGetter = tokenLine[T]
|
lex.tokenLineGetter = tokenLine[T]
|
||||||
lex.searchColonImpl = searchColon[T]
|
lex.searchColonImpl = searchColon[T]
|
||||||
|
|
||||||
|
when not defined(JS):
|
||||||
proc newYamlLexer*(source: Stream): YamlLexer {.raises: [YamlLexerError].} =
|
proc newYamlLexer*(source: Stream): YamlLexer {.raises: [YamlLexerError].} =
|
||||||
let blSource = new(BaseLexer)
|
let blSource = new(BaseLexer)
|
||||||
try: blSource[].open(source)
|
try: blSource[].open(source)
|
||||||
|
@ -1159,6 +1161,12 @@ proc newYamlLexer*(source: Stream): YamlLexer {.raises: [YamlLexerError].} =
|
||||||
|
|
||||||
proc newYamlLexer*(source: string, startAt: int = 0): YamlLexer
|
proc newYamlLexer*(source: string, startAt: int = 0): YamlLexer
|
||||||
{.raises: [].} =
|
{.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)
|
let sSource = new(StringSource)
|
||||||
sSource[] = StringSource(pos: startAt, lineStart: startAt, line: 1,
|
sSource[] = StringSource(pos: startAt, lineStart: startAt, line: 1,
|
||||||
src: source)
|
src: source)
|
||||||
|
|
|
@ -176,6 +176,7 @@ proc constructJson*(s: var YamlStream): seq[JsonNode]
|
||||||
else:
|
else:
|
||||||
internalError("Unexpected node kind: " & $levels[levels.high].node.kind)
|
internalError("Unexpected node kind: " & $levels[levels.high].node.kind)
|
||||||
|
|
||||||
|
when not defined(JS):
|
||||||
proc loadToJson*(s: Stream): seq[JsonNode]
|
proc loadToJson*(s: Stream): seq[JsonNode]
|
||||||
{.raises: [YamlParserError, YamlConstructionError, IOError].} =
|
{.raises: [YamlParserError, YamlConstructionError, IOError].} =
|
||||||
## Uses `YamlParser <#YamlParser>`_ and
|
## Uses `YamlParser <#YamlParser>`_ and
|
||||||
|
|
Loading…
Reference in New Issue