@@ -25,32 +25,23 @@ TOKEN_ERROR_DESCRIPTION = Dict{Kind, String}(
25
25
struct Token
26
26
kind:: Kind
27
27
# Offsets into a string or buffer
28
- startbyte:: Int # The byte where the token start in the buffer
29
28
endbyte:: Int # The byte where the token ended in the buffer
30
29
dotop:: Bool
31
30
suffix:: Bool
32
31
end
33
- function Token (kind:: Kind , startbyte :: Int , endbyte:: Int )
34
- Token (kind, startbyte, endbyte, false , false )
32
+ function Token (kind:: Kind , endbyte:: Int )
33
+ Token (kind, endbyte, false , false )
35
34
end
36
- Token () = Token (K " error" , 0 , 0 , false , false )
35
+ Token () = Token (K " error" , 0 , false , false )
37
36
38
37
const EMPTY_TOKEN = Token ()
39
38
40
39
kind (t:: Token ) = t. kind
41
40
42
- startbyte (t:: Token ) = t. startbyte
43
41
endbyte (t:: Token ) = t. endbyte
44
42
45
43
46
- function untokenize (t:: Token , str:: String )
47
- String (codeunits (str)[1 .+ (t. startbyte: t. endbyte)])
48
- end
49
44
50
- function Base. show (io:: IO , t:: Token )
51
- print (io, rpad (string (startbyte (t), " -" , endbyte (t)), 11 , " " ))
52
- print (io, rpad (kind (t), 15 , " " ))
53
- end
54
45
55
46
# -------------------------------------------------------------------------------
56
47
# Lexer
@@ -77,9 +68,7 @@ Ideally a lexer is stateless but some state is needed here for:
77
68
"""
78
69
mutable struct Lexer{IO_t <: IO }
79
70
io:: IO_t
80
-
81
71
token_startpos:: Int
82
-
83
72
last_token:: Kind
84
73
string_states:: Vector{StringState}
85
74
chars:: Tuple{Char,Char,Char,Char}
@@ -156,13 +145,6 @@ Return the latest `Token`'s starting position.
156
145
"""
157
146
startpos (l:: Lexer ) = l. token_startpos
158
147
159
- """
160
- startpos!(l::Lexer, i::Integer)
161
-
162
- Set a new starting position.
163
- """
164
- startpos! (l:: Lexer , i:: Integer ) = l. token_startpos = i
165
-
166
148
"""
167
149
peekchar(l::Lexer)
168
150
@@ -171,14 +153,14 @@ Returns the next character without changing the lexer's state.
171
153
peekchar (l:: Lexer ) = l. chars[2 ]
172
154
173
155
"""
174
- dpeekchar(l::Lexer)
156
+ dpeekchar(l::Lexer)
175
157
176
158
Returns the next two characters without changing the lexer's state.
177
159
"""
178
160
dpeekchar (l:: Lexer ) = l. chars[2 ], l. chars[3 ]
179
161
180
162
"""
181
- peekchar3(l::Lexer)
163
+ peekchar3(l::Lexer)
182
164
183
165
Returns the next three characters without changing the lexer's state.
184
166
"""
@@ -198,8 +180,6 @@ Determine whether the end of the lexer's underlying buffer has been reached.
198
180
"""
199
181
Base. eof (l:: Lexer ) = eof (l. io)
200
182
201
- Base. seek (l:: Lexer , pos) = seek (l. io, pos)
202
-
203
183
"""
204
184
start_token!(l::Lexer)
205
185
215
195
216
196
Returns the next character and increments the current position.
217
197
"""
218
- function readchar end
219
-
220
-
221
198
function readchar (l:: Lexer )
222
199
c = readchar (l. io)
223
200
l. chars = (l. chars[2 ], l. chars[3 ], l. chars[4 ], c)
@@ -271,8 +248,7 @@ function emit(l::Lexer, kind::Kind)
271
248
suffix = true
272
249
end
273
250
end
274
-
275
- tok = Token (kind, startpos (l), position (l) - 1 , l. dotop, suffix)
251
+ tok = Token (kind, position (l) - 1 , l. dotop, suffix)
276
252
277
253
l. dotop = false
278
254
l. last_token = kind
0 commit comments