@@ -4,10 +4,7 @@ use error::LexerResult;
44use tokens:: { LexerLiteral , LexerToken , LexerTokenKind , LexerTokenList } ;
55
66use 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
118} ;
129
1310pub use error:: { LexerError , LexerErrorKind } ;
@@ -17,54 +14,35 @@ pub mod tokens;
1714
1815pub struct Lexer < ' a > {
1916 chars : Peekable < Chars < ' a > > ,
20- errors : ErrorList ,
17+ errors : Vec < LexerError > ,
2118 cursor : Cursor ,
2219 tokens : LexerTokenList ,
2320 max_int_len : u8 ,
24-
25- #[ cfg( feature = "cli" ) ]
26- source : crate :: error:: SourceFile ,
21+ source_file : & ' a SourceFile ,
2722}
2823
2924impl < ' a > Lexer < ' a > {
3025 pub fn create (
31- input : & ' a str ,
32- #[ cfg( feature = "cli" ) ] path : Option < std:: path:: PathBuf > ,
26+ source_file : & ' a SourceFile ,
3327 ) -> Self {
3428 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 ,
5132 )
5233 }
5334
5435 pub fn create_bits (
55- input : & ' a str ,
56- #[ cfg( feature = "cli" ) ] path : Option < std:: path:: PathBuf > ,
36+ source_file : & ' a SourceFile ,
5737 max_int_len : u8 ,
5838 ) -> Self {
5939 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 ( ) ,
6242 cursor : Cursor :: create ( ) ,
6343 tokens : LexerTokenList :: new ( ) ,
6444 max_int_len,
65-
66- #[ cfg( feature = "cli" ) ]
67- source : Box :: from ( ( path, input. to_string ( ) ) ) ,
45+ source_file,
6846 } ;
6947
7048 debug ! ( "created lexer" ) ;
@@ -253,13 +231,12 @@ impl<'a> Lexer<'a> {
253231 start : Cursor ,
254232 err : LexerErrorKind
255233 ) {
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 ) ,
259236 start,
260237 end : self . cursor ,
261238 kind : err,
262- } ) )
239+ } )
263240 }
264241
265242 /// Consumes a single-line comment (aka skips to the end of the line and returns nothing)
@@ -487,14 +464,13 @@ impl<'a> Lexer<'a> {
487464 }
488465}
489466
490- impl ComponentErrors for Lexer < ' _ > {
491- fn fetch_errors ( & self ) -> & ErrorList {
467+ impl ComponentErrors < LexerError > for Lexer < ' _ > {
468+ fn fetch_errors ( & self ) -> & Vec < LexerError > {
492469 & self . errors
493470 }
494471
495- #[ cfg( feature = "cli" ) ]
496472 fn source ( & self ) -> & crate :: error:: SourceFile {
497- & self . source
473+ self . source_file
498474 }
499475}
500476
0 commit comments