@@ -77,24 +77,14 @@ Ideally a lexer is stateless but some state is needed here for:
77
77
"""
78
78
mutable struct Lexer{IO_t <: IO }
79
79
io:: IO_t
80
- io_startpos:: Int
81
80
82
- token_start_row:: Int
83
- token_start_col:: Int
84
81
token_startpos:: Int
85
82
86
- current_row:: Int
87
- current_col:: Int
88
- current_pos:: Int
89
-
90
83
last_token:: Kind
91
84
string_states:: Vector{StringState}
92
- charstore:: IOBuffer
93
85
chars:: Tuple{Char,Char,Char,Char}
94
86
charspos:: Tuple{Int,Int,Int,Int}
95
- doread:: Bool
96
87
dotop:: Bool
97
- errored:: Bool
98
88
end
99
89
100
90
function Lexer (io:: IO )
@@ -121,9 +111,9 @@ function Lexer(io::IO)
121
111
end
122
112
end
123
113
end
124
- Lexer (io, position (io), 1 , 1 , position (io), 1 , 1 , position (io),
125
- K " error" , Vector {StringState} (), IOBuffer (),
126
- (c1,c2,c3,c4), (p1,p2,p3,p4), false , false , false )
114
+ Lexer (io, position (io),
115
+ K " error" , Vector {StringState} (),
116
+ (c1,c2,c3,c4), (p1,p2,p3,p4), false )
127
117
end
128
118
Lexer (str:: AbstractString ) = Lexer (IOBuffer (str))
129
119
@@ -143,14 +133,8 @@ Base.eltype(::Type{<:Lexer}) = Token
143
133
144
134
145
135
function Base. iterate (l:: Lexer )
146
- seekstart (l)
147
136
l. token_startpos = position (l)
148
- l. token_start_row = 1
149
- l. token_start_col = 1
150
137
151
- l. current_row = 1
152
- l. current_col = 1
153
- l. current_pos = l. io_startpos
154
138
t = next_token (l)
155
139
return t, t. kind == K " EndMarker"
156
140
end
@@ -179,15 +163,6 @@ Set a new starting position.
179
163
"""
180
164
startpos! (l:: Lexer , i:: Integer ) = l. token_startpos = i
181
165
182
- Base. seekstart (l:: Lexer ) = seek (l. io, l. io_startpos)
183
-
184
- """
185
- seek2startpos!(l::Lexer)
186
-
187
- Sets the lexer's current position to the beginning of the latest `Token`.
188
- """
189
- seek2startpos! (l:: Lexer ) = seek (l, startpos (l))
190
-
191
166
"""
192
167
peekchar(l::Lexer)
193
168
@@ -220,7 +195,7 @@ Base.position(l::Lexer) = l.charspos[1]
220
195
eof(l::Lexer)
221
196
222
197
Determine whether the end of the lexer's underlying buffer has been reached.
223
- """ # Base.position(l::Lexer) = Base.position(l.io)
198
+ """
224
199
Base. eof (l:: Lexer ) = eof (l. io)
225
200
226
201
Base. seek (l:: Lexer , pos) = seek (l. io, pos)
@@ -233,8 +208,6 @@ position.
233
208
"""
234
209
function start_token! (l:: Lexer )
235
210
l. token_startpos = l. charspos[1 ]
236
- l. token_start_row = l. current_row
237
- l. token_start_col = l. current_col
238
211
end
239
212
240
213
"""
312
285
Returns an `K"error"` token with error `err` and starts a new `Token`.
313
286
"""
314
287
function emit_error (l:: Lexer , err:: Kind = K " error" )
315
- l. errored = true
316
288
@assert is_error (err)
317
289
return emit (l, err)
318
290
end
0 commit comments