summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lib/pure/pegs.nim22
1 files changed, 11 insertions, 11 deletions
diff --git a/lib/pure/pegs.nim b/lib/pure/pegs.nim
index e13bc8329..23ed855a4 100644
--- a/lib/pure/pegs.nim
+++ b/lib/pure/pegs.nim
@@ -1125,7 +1125,7 @@ proc handleCR(L: var PegLexer, pos: int): int =
   assert(L.buf[pos] == '\c')
   inc(L.lineNumber)
   result = pos+1
-  if L.buf[result] == '\L': inc(result)
+  if result < L.buf.len and L.buf[result] == '\L': inc(result)
   L.lineStart = result
 
 proc handleLF(L: var PegLexer, pos: int): int =
@@ -1221,7 +1221,7 @@ proc getEscapedChar(c: var PegLexer, tok: var Token) =
 proc skip(c: var PegLexer) =
   var pos = c.bufpos
   var buf = c.buf
-  while true:
+  while pos < c.buf.len:
     case buf[pos]
     of ' ', '\t':
       inc(pos)
@@ -1242,7 +1242,7 @@ proc getString(c: var PegLexer, tok: var Token) =
   var pos = c.bufpos + 1
   var buf = c.buf
   var quote = buf[pos-1]
-  while true:
+  while pos < c.buf.len:
     case buf[pos]
     of '\\':
       c.bufpos = pos
@@ -1265,7 +1265,7 @@ proc getDollar(c: var PegLexer, tok: var Token) =
   if buf[pos] in {'0'..'9'}:
     tok.kind = tkBackref
     tok.index = 0
-    while buf[pos] in {'0'..'9'}:
+    while pos < c.buf.len and buf[pos] in {'0'..'9'}:
       tok.index = tok.index * 10 + ord(buf[pos]) - ord('0')
       inc(pos)
   else:
@@ -1281,7 +1281,7 @@ proc getCharSet(c: var PegLexer, tok: var Token) =
   if buf[pos] == '^':
     inc(pos)
     caret = true
-  while true:
+  while pos < c.buf.len:
     var ch: char
     case buf[pos]
     of ']':
@@ -1300,7 +1300,7 @@ proc getCharSet(c: var PegLexer, tok: var Token) =
       inc(pos)
     incl(tok.charset, ch)
     if buf[pos] == '-':
-      if buf[pos+1] == ']':
+      if pos+1 < c.buf.len and buf[pos+1] == ']':
         incl(tok.charset, '-')
         inc(pos)
       else:
@@ -1326,10 +1326,10 @@ proc getCharSet(c: var PegLexer, tok: var Token) =
 proc getSymbol(c: var PegLexer, tok: var Token) =
   var pos = c.bufpos
   var buf = c.buf
-  while true:
+  while pos < c.buf.len:
     add(tok.literal, buf[pos])
     inc(pos)
-    if buf[pos] notin strutils.IdentChars: break
+    if pos < buf.len and buf[pos] notin strutils.IdentChars: break
   c.bufpos = pos
   tok.kind = tkIdentifier
 
@@ -1451,8 +1451,8 @@ proc getTok(c: var PegLexer, tok: var Token) =
 proc arrowIsNextTok(c: PegLexer): bool =
   # the only look ahead we need
   var pos = c.bufpos
-  while c.buf[pos] in {'\t', ' '}: inc(pos)
-  result = c.buf[pos] == '<' and c.buf[pos+1] == '-'
+  while pos < c.buf.len and c.buf[pos] in {'\t', ' '}: inc(pos)
+  result = c.buf[pos] == '<' and (pos+1 < c.buf.len) and c.buf[pos+1] == '-'
 
 # ----------------------------- parser ----------------------------------------
 
@@ -1475,7 +1475,7 @@ proc pegError(p: PegParser, msg: string, line = -1, col = -1) =
 
 proc getTok(p: var PegParser) =
   getTok(p, p.tok)
-  if p.tok.kind == tkInvalid: pegError(p, "invalid token")
+  if p.tok.kind == tkInvalid: pegError(p, "'" & p.tok.literal & "' is invalid token")
 
 proc eat(p: var PegParser, kind: TokKind) =
   if p.tok.kind == kind: getTok(p)
'/danisanti/profani-tty/blame/src/ui.h?id=32a5e07a9bc2f51a490fabe194b37a637175f45c'>^
2a69f8d2 ^
11125561 ^
df094a7d ^







17a284b2 ^
8c24a7c4 ^
17a284b2 ^
df094a7d ^
0ddf97e0 ^

4662f21c ^
57920163 ^
17a284b2 ^

2101f29e ^
7aa1d931 ^
b79e61fd ^
7aa1d931 ^
2101f29e ^

7aa1d931 ^
a7190ed7 ^

9e63c4a0 ^
a7190ed7 ^

02f5df5b ^
632528a9 ^
caa95562 ^
f533c6c1 ^
355f2a68 ^
dd9f6f82 ^
d9c47c9b ^


02f5df5b ^

baced857 ^
02f5df5b ^
b3f42cd3 ^
8b1653f7 ^
e45e6c46 ^
76149e1f ^
a574f7ff ^
bfc9e9a7 ^
c3b0e804 ^
6bad38c2 ^
f533c6c1 ^
4f82ece2 ^
0ddf97e0 ^
6bad38c2 ^
f533c6c1 ^
6bad38c2 ^
f533c6c1 ^
9805b2b2 ^
2375b7ae ^

294ea2d1 ^
a775d182 ^

d30d31b5 ^
02f5df5b ^
b329d09c ^
a676c50b ^
83834b96 ^
ad884599 ^

00234228 ^

be2fb1c8 ^

b3e1d473 ^

181669a8 ^
49676e3f ^

e506986e ^
de2f0607 ^

49676e3f ^

bd3f1d15 ^
645d1b74 ^

cd446539 ^
2f6361a5 ^
02f5df5b ^
d19afc35 ^
02f5df5b ^
15de3d4a ^

8ecbe0c5 ^
15de3d4a ^
5f60e463 ^
f533c6c1 ^
6aa1fe55 ^
5ef8aa8c ^

a5082a54 ^
f533c6c1 ^
9e230609 ^
2ca8f5b6 ^
02f5df5b ^
9e63c4a0 ^
e112ef5a ^
e5d4e09f ^
9e63c4a0 ^
118d97cd ^
9e63c4a0 ^
f533c6c1 ^


6ab1a84c ^
9e63c4a0 ^
a7190ed7 ^

4f82ece2 ^
a7190ed7 ^
6f69ce26 ^
4a2ff760 ^
a7190ed7 ^
03b90cf5 ^
a7190ed7 ^
34392622 ^
d30d31b5 ^
a7190ed7 ^
134e5d17 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172