mirror of https://github.com/status-im/NimYAML.git
More improvements to lexer
This commit is contained in:
parent
fc94c9da65
commit
f4a715c67f
|
@ -1127,10 +1127,14 @@ proc init*[T](lex: YamlLexer) =
|
||||||
lex.tokenLineGetter = tokenLine[T]
|
lex.tokenLineGetter = tokenLine[T]
|
||||||
lex.searchColonImpl = searchColon[T]
|
lex.searchColonImpl = searchColon[T]
|
||||||
|
|
||||||
proc newYamlLexer*(source: Stream): YamlLexer {.raises: [].} =
|
proc newYamlLexer*(source: Stream): YamlLexer {.raises: [YamlLexerError].} =
|
||||||
try:
|
|
||||||
let blSource = new(BaseLexer)
|
let blSource = new(BaseLexer)
|
||||||
blSource[].open(source)
|
try: blSource[].open(source)
|
||||||
|
except:
|
||||||
|
var e = newException(YamlLexerError,
|
||||||
|
"Could not open stream for reading:\n" & getCurrentExceptionMsg())
|
||||||
|
e.parent = getCurrentException()
|
||||||
|
raise e
|
||||||
GC_ref(blSource)
|
GC_ref(blSource)
|
||||||
new(result, proc(x: ref YamlLexerObj) {.nimcall.} =
|
new(result, proc(x: ref YamlLexerObj) {.nimcall.} =
|
||||||
GC_unref(cast[ref BaseLexer](x.source))
|
GC_unref(cast[ref BaseLexer](x.source))
|
||||||
|
@ -1138,13 +1142,10 @@ proc newYamlLexer*(source: Stream): YamlLexer {.raises: [].} =
|
||||||
result[] = YamlLexerObj(source: cast[pointer](blSource), inFlow: false,
|
result[] = YamlLexerObj(source: cast[pointer](blSource), inFlow: false,
|
||||||
buf: "", c: blSource[].buf[blSource[].bufpos], newlines: 0,
|
buf: "", c: blSource[].buf[blSource[].bufpos], newlines: 0,
|
||||||
folded: true)
|
folded: true)
|
||||||
except:
|
|
||||||
discard # TODO
|
|
||||||
init[BaseLexer](result)
|
init[BaseLexer](result)
|
||||||
|
|
||||||
proc newYamlLexer*(source: string, startAt: int = 0): YamlLexer
|
proc newYamlLexer*(source: string, startAt: int = 0): YamlLexer
|
||||||
{.raises: [].} =
|
{.raises: [].} =
|
||||||
try:
|
|
||||||
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)
|
||||||
|
@ -1152,10 +1153,8 @@ proc newYamlLexer*(source: string, startAt: int = 0): YamlLexer
|
||||||
new(result, proc(x: ref YamlLexerObj) {.nimcall.} =
|
new(result, proc(x: ref YamlLexerObj) {.nimcall.} =
|
||||||
GC_unref(cast[ref StringSource](x.source))
|
GC_unref(cast[ref StringSource](x.source))
|
||||||
)
|
)
|
||||||
result[] = YamlLexerObj(buf: "", source: cast[pointer](sSource), inFlow: false,
|
result[] = YamlLexerObj(buf: "", source: cast[pointer](sSource),
|
||||||
c: sSource.src[startAt], newlines: 0, folded: true)
|
inFlow: false, c: sSource.src[startAt], newlines: 0, folded: true)
|
||||||
except:
|
|
||||||
discard # TODO
|
|
||||||
init[StringSource](result)
|
init[StringSource](result)
|
||||||
|
|
||||||
proc next*(lex: YamlLexer) =
|
proc next*(lex: YamlLexer) =
|
||||||
|
|
Loading…
Reference in New Issue