diff options
Diffstat (limited to 'compiler/nimlexbase.nim')
-rw-r--r-- | compiler/nimlexbase.nim | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/compiler/nimlexbase.nim b/compiler/nimlexbase.nim index 6d45a825a..038573c35 100644 --- a/compiler/nimlexbase.nim +++ b/compiler/nimlexbase.nim @@ -42,7 +42,7 @@ type buf*: cstring bufLen*: int # length of buffer in characters stream*: PLLStream # we read from this stream - LineNumber*: int # the current line number + lineNumber*: int # the current line number # private data: sentinel*: int lineStart*: int # index of last line start in buffer @@ -54,11 +54,11 @@ proc openBaseLexer*(L: var TBaseLexer, inputstream: PLLStream, proc closeBaseLexer*(L: var TBaseLexer) proc getCurrentLine*(L: TBaseLexer, marker: bool = true): string proc getColNumber*(L: TBaseLexer, pos: int): int -proc HandleCR*(L: var TBaseLexer, pos: int): int +proc handleCR*(L: var TBaseLexer, pos: int): int # Call this if you scanned over CR in the buffer; it returns the # position to continue the scanning from. `pos` must be the position # of the CR. -proc HandleLF*(L: var TBaseLexer, pos: int): int +proc handleLF*(L: var TBaseLexer, pos: int): int # Call this if you scanned over LF in the buffer; it returns the the # position to continue the scanning from. `pos` must be the position # of the LF. @@ -69,9 +69,9 @@ const proc closeBaseLexer(L: var TBaseLexer) = dealloc(L.buf) - LLStreamClose(L.stream) + llStreamClose(L.stream) -proc FillBuffer(L: var TBaseLexer) = +proc fillBuffer(L: var TBaseLexer) = var charsRead, toCopy, s: int # all are in characters, # not bytes (in case this @@ -80,12 +80,12 @@ proc FillBuffer(L: var TBaseLexer) = # we know here that pos == L.sentinel, but not if this proc # is called the first time by initBaseLexer() assert(L.sentinel < L.bufLen) - toCopy = L.BufLen - L.sentinel - 1 + toCopy = L.bufLen - L.sentinel - 1 assert(toCopy >= 0) if toCopy > 0: - MoveMem(L.buf, addr(L.buf[L.sentinel + 1]), toCopy * chrSize) + moveMem(L.buf, addr(L.buf[L.sentinel + 1]), toCopy * chrSize) # "moveMem" handles overlapping regions - charsRead = LLStreamRead(L.stream, addr(L.buf[toCopy]), + charsRead = llStreamRead(L.stream, addr(L.buf[toCopy]), (L.sentinel + 1) * chrSize) div chrSize s = toCopy + charsRead if charsRead < L.sentinel + 1: @@ -96,7 +96,7 @@ proc FillBuffer(L: var TBaseLexer) = dec(s) # BUGFIX (valgrind) while true: assert(s < L.bufLen) - while (s >= 0) and not (L.buf[s] in NewLines): Dec(s) + while (s >= 0) and not (L.buf[s] in NewLines): dec(s) if s >= 0: # we found an appropriate character for a sentinel: L.sentinel = s @@ -104,11 +104,11 @@ proc FillBuffer(L: var TBaseLexer) = else: # rather than to give up here because the line is too long, # double the buffer's size and try again: - oldBufLen = L.BufLen - L.bufLen = L.BufLen * 2 + oldBufLen = L.bufLen + L.bufLen = L.bufLen * 2 L.buf = cast[cstring](realloc(L.buf, L.bufLen * chrSize)) - assert(L.bufLen - oldBuflen == oldBufLen) - charsRead = LLStreamRead(L.stream, addr(L.buf[oldBufLen]), + assert(L.bufLen - oldBufLen == oldBufLen) + charsRead = llStreamRead(L.stream, addr(L.buf[oldBufLen]), oldBufLen * chrSize) div chrSize if charsRead < oldBufLen: L.buf[oldBufLen + charsRead] = EndOfFile @@ -126,20 +126,20 @@ proc fillBaseLexer(L: var TBaseLexer, pos: int): int = result = 0 L.lineStart = result -proc HandleCR(L: var TBaseLexer, pos: int): int = +proc handleCR(L: var TBaseLexer, pos: int): int = assert(L.buf[pos] == CR) - inc(L.linenumber) + inc(L.lineNumber) result = fillBaseLexer(L, pos) if L.buf[result] == LF: result = fillBaseLexer(L, result) -proc HandleLF(L: var TBaseLexer, pos: int): int = +proc handleLF(L: var TBaseLexer, pos: int): int = assert(L.buf[pos] == LF) - inc(L.linenumber) + inc(L.lineNumber) result = fillBaseLexer(L, pos) #L.lastNL := result-1; // BUGFIX: was: result; -proc skip_UTF_8_BOM(L: var TBaseLexer) = - if (L.buf[0] == '\xEF') and (L.buf[1] == '\xBB') and (L.buf[2] == '\xBF'): +proc skipUTF8BOM(L: var TBaseLexer) = + if L.buf[0] == '\xEF' and L.buf[1] == '\xBB' and L.buf[2] == '\xBF': inc(L.bufpos, 3) inc(L.lineStart, 3) @@ -150,10 +150,10 @@ proc openBaseLexer(L: var TBaseLexer, inputstream: PLLStream, bufLen = 8192) = L.buf = cast[cstring](alloc(bufLen * chrSize)) L.sentinel = bufLen - 1 L.lineStart = 0 - L.linenumber = 1 # lines start at 1 + L.lineNumber = 1 # lines start at 1 L.stream = inputstream fillBuffer(L) - skip_UTF_8_BOM(L) + skipUTF8BOM(L) proc getColNumber(L: TBaseLexer, pos: int): int = result = abs(pos - L.lineStart) @@ -166,5 +166,4 @@ proc getCurrentLine(L: TBaseLexer, marker: bool = true): string = inc(i) result.add("\n") if marker: - result.add(RepeatChar(getColNumber(L, L.bufpos)) & '^' & "\n") - + result.add(repeatChar(getColNumber(L, L.bufpos)) & '^' & "\n") |