@@ -4,10 +4,7 @@ use error::LexerResult;
4
4
use tokens:: { LexerLiteral , LexerToken , LexerTokenKind , LexerTokenList } ;
5
5
6
6
use crate :: {
7
- component:: { ComponentErrors , ComponentIter } ,
8
- constants:: { MAX_I32_LEN , MAX_I64_LEN } ,
9
- error:: { EngineErrorKind , ErrorList } ,
10
- cursor:: Cursor ,
7
+ component:: { ComponentErrors , ComponentIter } , cursor:: Cursor , error:: SourceFile
11
8
} ;
12
9
13
10
pub use error:: { LexerError , LexerErrorKind } ;
@@ -17,54 +14,35 @@ pub mod tokens;
17
14
18
15
pub struct Lexer < ' a > {
19
16
chars : Peekable < Chars < ' a > > ,
20
- errors : ErrorList ,
17
+ errors : Vec < LexerError > ,
21
18
cursor : Cursor ,
22
19
tokens : LexerTokenList ,
23
20
max_int_len : u8 ,
24
-
25
- #[ cfg( feature = "cli" ) ]
26
- source : crate :: error:: SourceFile ,
21
+ source_file : & ' a SourceFile ,
27
22
}
28
23
29
24
impl < ' a > Lexer < ' a > {
30
25
pub fn create (
31
- input : & ' a str ,
32
- #[ cfg( feature = "cli" ) ] path : Option < std:: path:: PathBuf > ,
26
+ source_file : & ' a SourceFile ,
33
27
) -> Self {
34
28
Self :: create_bits (
35
- input,
36
- #[ cfg( feature = "cli" ) ]
37
- path,
38
- MAX_I64_LEN ,
39
- )
40
- }
41
-
42
- pub fn create_32b (
43
- input : & ' a str ,
44
- #[ cfg( feature = "cli" ) ] path : Option < std:: path:: PathBuf > ,
45
- ) -> Self {
46
- Self :: create_bits (
47
- input,
48
- #[ cfg( feature = "cli" ) ]
49
- path,
50
- MAX_I32_LEN ,
29
+ source_file,
30
+ #[ cfg( target_pointer_width = "32" ) ] crate :: constants:: MAX_I32_LEN ,
31
+ #[ cfg( target_pointer_width = "64" ) ] crate :: constants:: MAX_I64_LEN ,
51
32
)
52
33
}
53
34
54
35
pub fn create_bits (
55
- input : & ' a str ,
56
- #[ cfg( feature = "cli" ) ] path : Option < std:: path:: PathBuf > ,
36
+ source_file : & ' a SourceFile ,
57
37
max_int_len : u8 ,
58
38
) -> Self {
59
39
let lexer = Self {
60
- chars : input . trim ( ) . chars ( ) . peekable ( ) ,
61
- errors : ErrorList :: new ( ) ,
40
+ chars : source_file . get_code ( ) . trim ( ) . chars ( ) . peekable ( ) ,
41
+ errors : Vec :: new ( ) ,
62
42
cursor : Cursor :: create ( ) ,
63
43
tokens : LexerTokenList :: new ( ) ,
64
44
max_int_len,
65
-
66
- #[ cfg( feature = "cli" ) ]
67
- source : Box :: from ( ( path, input. to_string ( ) ) ) ,
45
+ source_file,
68
46
} ;
69
47
70
48
debug ! ( "created lexer" ) ;
@@ -253,13 +231,12 @@ impl<'a> Lexer<'a> {
253
231
start : Cursor ,
254
232
err : LexerErrorKind
255
233
) {
256
- self . errors . push ( EngineErrorKind :: LexerError ( LexerError {
257
- #[ cfg( feature = "cli" ) ]
258
- source_file : self . get_source_sliced ( start, self . cursor ) ,
234
+ self . errors . push ( LexerError {
235
+ source_file : self . source ( ) . sliced ( start, self . cursor ) ,
259
236
start,
260
237
end : self . cursor ,
261
238
kind : err,
262
- } ) )
239
+ } )
263
240
}
264
241
265
242
/// Consumes a single-line comment (aka skips to the end of the line and returns nothing)
@@ -487,14 +464,13 @@ impl<'a> Lexer<'a> {
487
464
}
488
465
}
489
466
490
- impl ComponentErrors for Lexer < ' _ > {
491
- fn fetch_errors ( & self ) -> & ErrorList {
467
+ impl ComponentErrors < LexerError > for Lexer < ' _ > {
468
+ fn fetch_errors ( & self ) -> & Vec < LexerError > {
492
469
& self . errors
493
470
}
494
471
495
- #[ cfg( feature = "cli" ) ]
496
472
fn source ( & self ) -> & crate :: error:: SourceFile {
497
- & self . source
473
+ self . source_file
498
474
}
499
475
}
500
476
0 commit comments