[backport] run nimpretty on parsers
This commit is contained in:
parent
6c994b2498
commit
b17ed2ca9c
11 changed files with 207 additions and 193 deletions
|
|
@ -15,7 +15,7 @@ import
|
|||
strutils, streams
|
||||
|
||||
const
|
||||
EndOfFile* = '\0' ## end of file marker
|
||||
EndOfFile* = '\0' ## end of file marker
|
||||
NewLines* = {'\c', '\L'}
|
||||
|
||||
# Buffer handling:
|
||||
|
|
@ -27,13 +27,13 @@ const
|
|||
type
|
||||
BaseLexer* = object of RootObj ## the base lexer. Inherit your lexer from
|
||||
## this object.
|
||||
bufpos*: int ## the current position within the buffer
|
||||
buf*: string ## the buffer itself
|
||||
input: Stream ## the input stream
|
||||
lineNumber*: int ## the current line number
|
||||
bufpos*: int ## the current position within the buffer
|
||||
buf*: string ## the buffer itself
|
||||
input: Stream ## the input stream
|
||||
lineNumber*: int ## the current line number
|
||||
sentinel: int
|
||||
lineStart: int # index of last line start in buffer
|
||||
offsetBase*: int # use ``offsetBase + bufpos`` to get the offset
|
||||
lineStart: int # index of last line start in buffer
|
||||
offsetBase*: int # use ``offsetBase + bufpos`` to get the offset
|
||||
refillChars: set[char]
|
||||
|
||||
proc close*(L: var BaseLexer) =
|
||||
|
|
@ -65,11 +65,11 @@ proc fillBuffer(L: var BaseLexer) =
|
|||
charsRead = L.input.readDataStr(L.buf, toCopy ..< toCopy + L.sentinel + 1)
|
||||
s = toCopy + charsRead
|
||||
if charsRead < L.sentinel + 1:
|
||||
L.buf[s] = EndOfFile # set end marker
|
||||
L.buf[s] = EndOfFile # set end marker
|
||||
L.sentinel = s
|
||||
else:
|
||||
# compute sentinel:
|
||||
dec(s) # BUGFIX (valgrind)
|
||||
dec(s) # BUGFIX (valgrind)
|
||||
while true:
|
||||
assert(s < L.buf.len)
|
||||
while s >= 0 and L.buf[s] notin L.refillChars: dec(s)
|
||||
|
|
@ -92,7 +92,7 @@ proc fillBuffer(L: var BaseLexer) =
|
|||
proc fillBaseLexer(L: var BaseLexer, pos: int): int =
|
||||
assert(pos <= L.sentinel)
|
||||
if pos < L.sentinel:
|
||||
result = pos + 1 # nothing to do
|
||||
result = pos + 1 # nothing to do
|
||||
else:
|
||||
fillBuffer(L)
|
||||
L.offsetBase += pos
|
||||
|
|
@ -142,7 +142,7 @@ proc open*(L: var BaseLexer, input: Stream, bufLen: int = 8192;
|
|||
L.buf = newString(bufLen)
|
||||
L.sentinel = bufLen - 1
|
||||
L.lineStart = 0
|
||||
L.lineNumber = 1 # lines start at 1
|
||||
L.lineNumber = 1 # lines start at 1
|
||||
fillBuffer(L)
|
||||
skipUtf8Bom(L)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue