summary refs log tree commit diff stats
path: root/compiler/syntaxes.nim
diff options
context:
space:
mode:
authorMichael Voronin <survivor.mail@gmail.com>2018-05-03 17:12:01 +0300
committerGitHub <noreply@github.com>2018-05-03 17:12:01 +0300
commit5ea967d97a30f0084883d4efa81b05bea3e5d148 (patch)
tree05ea0e3624f6720c2f5af28b5a70c87c85feafc7 /compiler/syntaxes.nim
parent3949c9f977378ea3ab2b3c750f4dc2bc8d853022 (diff)
parent5564289b577c620cbd775f477b7fc8b6507adbfa (diff)
downloadNim-5ea967d97a30f0084883d4efa81b05bea3e5d148.tar.gz
Merge pull request #3 from nim-lang/devel
pull #3
Diffstat (limited to 'compiler/syntaxes.nim')
-rw-r--r--compiler/syntaxes.nim10
1 files changed, 5 insertions, 5 deletions
diff --git a/compiler/syntaxes.nim b/compiler/syntaxes.nim
index 4014d4c58..5413565e6 100644
--- a/compiler/syntaxes.nim
+++ b/compiler/syntaxes.nim
@@ -51,15 +51,15 @@ proc parseTopLevelStmt*(p: var TParsers): PNode =
     result = ast.emptyNode
 
 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
   else:
     result = 0
 
 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
-    while s[j] in Whitespace: inc(j)
+    while j < s.len and s[j] in Whitespace: inc(j)
     result = s[j] == '/'
 
 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)
       i = 0
       inc linenumber
-    if line[i] == '#' and line[i+1] == '?':
+    if i+1 < line.len and line[i] == '#' and line[i+1] == '?':
       inc(i, 2)
-      while line[i] in Whitespace: inc(i)
+      while i < line.len and line[i] in Whitespace: inc(i)
       var q: TParser
       parser.openParser(q, filename, llStreamOpen(substr(line, i)), cache)
       result = parser.parseAll(q)