the compiler does not rely on the zero terminator anymore
This commit is contained in:
parent
68a63b3407
commit
7e0540ed80
3 changed files with 13 additions and 14 deletions
|
|
@ -165,13 +165,12 @@ proc isKeyword*(kind: TTokType): bool =
|
||||||
template ones(n): untyped = ((1 shl n)-1) # for utf-8 conversion
|
template ones(n): untyped = ((1 shl n)-1) # for utf-8 conversion
|
||||||
|
|
||||||
proc isNimIdentifier*(s: string): bool =
|
proc isNimIdentifier*(s: string): bool =
|
||||||
if s[0] in SymStartChars:
|
let sLen = s.len
|
||||||
|
if sLen > 0 and s[0] in SymStartChars:
|
||||||
var i = 1
|
var i = 1
|
||||||
var sLen = s.len
|
|
||||||
while i < sLen:
|
while i < sLen:
|
||||||
if s[i] == '_':
|
if s[i] == '_': inc(i)
|
||||||
inc(i)
|
if i < sLen and s[i] notin SymChars: return
|
||||||
if s[i] notin SymChars: return
|
|
||||||
inc(i)
|
inc(i)
|
||||||
result = true
|
result = true
|
||||||
|
|
||||||
|
|
@ -311,12 +310,12 @@ template tokenEndPrevious(tok, pos) =
|
||||||
# We need to parse the largest uint literal without overflow checks
|
# We need to parse the largest uint literal without overflow checks
|
||||||
proc unsafeParseUInt(s: string, b: var BiggestInt, start = 0): int =
|
proc unsafeParseUInt(s: string, b: var BiggestInt, start = 0): int =
|
||||||
var i = start
|
var i = start
|
||||||
if s[i] in {'0'..'9'}:
|
if i < s.len and s[i] in {'0'..'9'}:
|
||||||
b = 0
|
b = 0
|
||||||
while s[i] in {'0'..'9'}:
|
while i < s.len and s[i] in {'0'..'9'}:
|
||||||
b = b * 10 + (ord(s[i]) - ord('0'))
|
b = b * 10 + (ord(s[i]) - ord('0'))
|
||||||
inc(i)
|
inc(i)
|
||||||
while s[i] == '_': inc(i) # underscores are allowed and ignored
|
while i < s.len and s[i] == '_': inc(i) # underscores are allowed and ignored
|
||||||
result = i - start
|
result = i - start
|
||||||
{.pop.} # overflowChecks
|
{.pop.} # overflowChecks
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -251,7 +251,7 @@ proc `%`*(frmt: FormatStr, args: openArray[Rope]): Rope =
|
||||||
while true:
|
while true:
|
||||||
j = j * 10 + ord(frmt[i]) - ord('0')
|
j = j * 10 + ord(frmt[i]) - ord('0')
|
||||||
inc(i)
|
inc(i)
|
||||||
if frmt[i] notin {'0'..'9'}: break
|
if i >= frmt.len or frmt[i] notin {'0'..'9'}: break
|
||||||
num = j
|
num = j
|
||||||
if j > high(args) + 1:
|
if j > high(args) + 1:
|
||||||
errorHandler(rInvalidFormatStr, $(j))
|
errorHandler(rInvalidFormatStr, $(j))
|
||||||
|
|
|
||||||
|
|
@ -51,15 +51,15 @@ proc parseTopLevelStmt*(p: var TParsers): PNode =
|
||||||
result = ast.emptyNode
|
result = ast.emptyNode
|
||||||
|
|
||||||
proc utf8Bom(s: string): int =
|
proc utf8Bom(s: string): int =
|
||||||
if s[0] == '\xEF' and s[1] == '\xBB' and s[2] == '\xBF':
|
if s.len >= 3 and s[0] == '\xEF' and s[1] == '\xBB' and s[2] == '\xBF':
|
||||||
result = 3
|
result = 3
|
||||||
else:
|
else:
|
||||||
result = 0
|
result = 0
|
||||||
|
|
||||||
proc containsShebang(s: string, i: int): bool =
|
proc containsShebang(s: string, i: int): bool =
|
||||||
if s[i] == '#' and s[i+1] == '!':
|
if i+1 < s.len and s[i] == '#' and s[i+1] == '!':
|
||||||
var j = i + 2
|
var j = i + 2
|
||||||
while s[j] in Whitespace: inc(j)
|
while j < s.len and s[j] in Whitespace: inc(j)
|
||||||
result = s[j] == '/'
|
result = s[j] == '/'
|
||||||
|
|
||||||
proc parsePipe(filename: string, inputStream: PLLStream; cache: IdentCache): PNode =
|
proc parsePipe(filename: string, inputStream: PLLStream; cache: IdentCache): PNode =
|
||||||
|
|
@ -74,9 +74,9 @@ proc parsePipe(filename: string, inputStream: PLLStream; cache: IdentCache): PNo
|
||||||
discard llStreamReadLine(s, line)
|
discard llStreamReadLine(s, line)
|
||||||
i = 0
|
i = 0
|
||||||
inc linenumber
|
inc linenumber
|
||||||
if line[i] == '#' and line[i+1] == '?':
|
if i+1 < line.len and line[i] == '#' and line[i+1] == '?':
|
||||||
inc(i, 2)
|
inc(i, 2)
|
||||||
while line[i] in Whitespace: inc(i)
|
while i < line.len and line[i] in Whitespace: inc(i)
|
||||||
var q: TParser
|
var q: TParser
|
||||||
parser.openParser(q, filename, llStreamOpen(substr(line, i)), cache)
|
parser.openParser(q, filename, llStreamOpen(substr(line, i)), cache)
|
||||||
result = parser.parseAll(q)
|
result = parser.parseAll(q)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue