More improvements to lexer

This commit is contained in:
Felix Krause 2016-09-30 20:12:17 +02:00
parent fc94c9da65
commit f4a715c67f
1 changed files with 24 additions and 25 deletions

View File

@ -1127,35 +1127,34 @@ 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) try: blSource[].open(source)
blSource[].open(source)
GC_ref(blSource)
new(result, proc(x: ref YamlLexerObj) {.nimcall.} =
GC_unref(cast[ref BaseLexer](x.source))
)
result[] = YamlLexerObj(source: cast[pointer](blSource), inFlow: false,
buf: "", c: blSource[].buf[blSource[].bufpos], newlines: 0,
folded: true)
except: except:
discard # TODO var e = newException(YamlLexerError,
"Could not open stream for reading:\n" & getCurrentExceptionMsg())
e.parent = getCurrentException()
raise e
GC_ref(blSource)
new(result, proc(x: ref YamlLexerObj) {.nimcall.} =
GC_unref(cast[ref BaseLexer](x.source))
)
result[] = YamlLexerObj(source: cast[pointer](blSource), inFlow: false,
buf: "", c: blSource[].buf[blSource[].bufpos], newlines: 0,
folded: true)
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) GC_ref(sSource)
GC_ref(sSource) 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),
result[] = YamlLexerObj(buf: "", source: cast[pointer](sSource), inFlow: false, inFlow: false, c: sSource.src[startAt], newlines: 0, folded: true)
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) =