1
1
use std:: { iter:: Peekable , str:: Chars } ;
2
2
3
3
use error:: LexerResult ;
4
- use tokens:: { LexerLiteral , LexerToken , LexerTokenKind , LexerTokenList } ;
4
+ use tokens:: { LexerTokenValue , LexerToken , LexerTokenKind , LexerTokenList } ;
5
5
6
6
use crate :: {
7
7
component:: { ComponentErrors , ComponentIter } , constants:: { MAX_I32_LEN , MAX_I64_LEN } , cursor:: Cursor , error:: { EngineErrorKind , ErrorList } , parser:: expr:: ShellCommand
@@ -93,7 +93,7 @@ impl<'a> Lexer<'a> {
93
93
fn scan_char (
94
94
& mut self ,
95
95
char : & char ,
96
- ) -> LexerResult < Option < ( LexerTokenKind , Option < Box < LexerLiteral > > ) > > {
96
+ ) -> LexerResult < Option < ( LexerTokenKind , Option < Box < LexerTokenValue > > ) > > {
97
97
macro_rules! check_double {
98
98
( $single_type: expr, $double: tt, $double_type: expr) => {
99
99
if self . next_if_eq( & $double) . is_some( ) {
@@ -142,7 +142,7 @@ impl<'a> Lexer<'a> {
142
142
return Ok ( None ) ;
143
143
} ;
144
144
145
- return Ok ( Some ( ( Integer , Some ( Box :: from ( LexerLiteral :: Integer ( -self . eat_number ( char) ?) ) ) ) ) ) ;
145
+ return Ok ( Some ( ( Integer , Some ( Box :: from ( LexerTokenValue :: Integer ( -self . eat_number ( char) ?) ) ) ) ) ) ;
146
146
}
147
147
_ => Minus ,
148
148
} ,
@@ -187,7 +187,7 @@ impl<'a> Lexer<'a> {
187
187
'0' ..='9' => {
188
188
return Ok ( Some ( (
189
189
Integer ,
190
- Some ( Box :: from ( LexerLiteral :: Integer ( self . eat_number ( * char) ?) ) ) ,
190
+ Some ( Box :: from ( LexerTokenValue :: Integer ( self . eat_number ( * char) ?) ) ) ,
191
191
) ) )
192
192
}
193
193
'"' => return Ok ( Some ( self . consume_string ( ) ?) ) ,
@@ -219,10 +219,10 @@ impl<'a> Lexer<'a> {
219
219
"and" => And ,
220
220
"or" => Or ,
221
221
222
- "true" => return Ok ( Some ( ( Boolean , Some ( Box :: from ( LexerLiteral :: Boolean ( true ) ) ) ) ) ) ,
223
- "false" => return Ok ( Some ( ( Boolean , Some ( Box :: from ( LexerLiteral :: Boolean ( false ) ) ) ) ) ) ,
222
+ "true" => return Ok ( Some ( ( Boolean , Some ( Box :: from ( LexerTokenValue :: Boolean ( true ) ) ) ) ) ) ,
223
+ "false" => return Ok ( Some ( ( Boolean , Some ( Box :: from ( LexerTokenValue :: Boolean ( false ) ) ) ) ) ) ,
224
224
225
- _ if Self :: is_valid_identifier ( char) => return Ok ( Some ( ( Identifier , Some ( Box :: from ( LexerLiteral :: Identifier ( Box :: from ( word) ) ) ) ) ) ) ,
225
+ _ if Self :: is_valid_identifier ( char) => return Ok ( Some ( ( Identifier , Some ( Box :: from ( LexerTokenValue :: Identifier ( Box :: from ( word) ) ) ) ) ) ) ,
226
226
_ => return Err ( LexerErrorKind :: UnknownToken ) ,
227
227
}
228
228
}
@@ -234,7 +234,7 @@ impl<'a> Lexer<'a> {
234
234
fn add_token (
235
235
& mut self ,
236
236
token_type : LexerTokenKind ,
237
- value : Option < Box < LexerLiteral > > ,
237
+ value : Option < Box < LexerTokenValue > > ,
238
238
start : Cursor ,
239
239
) {
240
240
self . tokens . push ( LexerToken {
@@ -279,7 +279,7 @@ impl<'a> Lexer<'a> {
279
279
}
280
280
281
281
/// Attempts to return a [`TokenType::String`]
282
- fn consume_string ( & mut self ) -> LexerResult < ( LexerTokenKind , Option < Box < LexerLiteral > > ) > {
282
+ fn consume_string ( & mut self ) -> LexerResult < ( LexerTokenKind , Option < Box < LexerTokenValue > > ) > {
283
283
let string = self . eat_until ( & [ '"' , '\n' ] , true ) . unwrap_or_default ( ) ;
284
284
285
285
if let Err ( err) = self . expect_char ( & '"' ) {
@@ -292,14 +292,14 @@ impl<'a> Lexer<'a> {
292
292
293
293
Ok ( (
294
294
LexerTokenKind :: String ,
295
- Some ( Box :: from ( LexerLiteral :: String ( Box :: from ( string) ) ) ) ,
295
+ Some ( Box :: from ( LexerTokenValue :: String ( Box :: from ( string) ) ) ) ,
296
296
) )
297
297
}
298
298
299
299
/// Attempts to return a [`TokenType::ShellCommand`]
300
300
fn consume_shell_command (
301
301
& mut self ,
302
- ) -> LexerResult < ( LexerTokenKind , Option < Box < LexerLiteral > > ) > {
302
+ ) -> LexerResult < ( LexerTokenKind , Option < Box < LexerTokenValue > > ) > {
303
303
let cmd_name = self
304
304
. eat_until ( & [ ' ' , '\t' , '\n' , '(' ] , false )
305
305
. ok_or ( LexerErrorKind :: UnexpectedEnd ) ?;
@@ -323,7 +323,7 @@ impl<'a> Lexer<'a> {
323
323
324
324
Ok ( (
325
325
LexerTokenKind :: ShellCommand ,
326
- Some ( Box :: from ( LexerLiteral :: ShellCommand ( Box :: from ( ShellCommand ( cmd_name, cmd_args) ) ) ) ) ,
326
+ Some ( Box :: from ( LexerTokenValue :: ShellCommand ( Box :: from ( ShellCommand ( cmd_name, cmd_args) ) ) ) ) ,
327
327
) )
328
328
}
329
329
0 commit comments