mirror of
https://github.com/AleoHQ/leo.git
synced 2024-11-28 19:23:24 +03:00
clean up lexing char
This commit is contained in:
parent
8cea284427
commit
6f8df3c84d
@ -78,8 +78,10 @@ impl Token {
|
||||
let mut characters: Vec<u8> = vec![];
|
||||
|
||||
while i < input.len() {
|
||||
println!("?? input[i] {}", input[i]);
|
||||
if !escaped {
|
||||
if input[i] == b'\'' {
|
||||
println!("last");
|
||||
last = true;
|
||||
i += 1;
|
||||
break;
|
||||
@ -139,14 +141,7 @@ impl Token {
|
||||
}
|
||||
|
||||
return match characters.len() {
|
||||
1 => {
|
||||
if hex {
|
||||
return (0, None);
|
||||
}
|
||||
|
||||
(i, Some(Token::CharLit(characters[0] as char)))
|
||||
}
|
||||
2 | 3 | 4 | 5 if unicode => {
|
||||
1 | 2 | 3 | 4 | 5 if unicode => {
|
||||
if let Ok(string) = std::str::from_utf8(&characters[..]) {
|
||||
if let Ok(hex) = u32::from_str_radix(&string, 16) {
|
||||
if hex <= 0x10FFF {
|
||||
@ -159,20 +154,26 @@ impl Token {
|
||||
|
||||
(0, None)
|
||||
}
|
||||
2 => {
|
||||
1 => {
|
||||
if hex {
|
||||
if let Ok(string) = std::str::from_utf8(&characters[..]) {
|
||||
if let Ok(number) = u8::from_str_radix(&string, 16) {
|
||||
if number <= 127 {
|
||||
return (i, Some(Token::CharLit(number as char)));
|
||||
}
|
||||
return (0, None);
|
||||
}
|
||||
|
||||
(i, Some(Token::CharLit(characters[0] as char)))
|
||||
}
|
||||
2 if hex => {
|
||||
if let Ok(string) = std::str::from_utf8(&characters[..]) {
|
||||
if let Ok(number) = u8::from_str_radix(&string, 16) {
|
||||
if number <= 127 {
|
||||
return (i, Some(Token::CharLit(number as char)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(0, None)
|
||||
}
|
||||
3 => {
|
||||
3 | 4 => {
|
||||
// direct unicode symbol
|
||||
if let Ok(string) = std::str::from_utf8(&characters[..]) {
|
||||
if let Some(character) = string.chars().next() {
|
||||
return (i, Some(Token::CharLit(character)));
|
||||
@ -181,17 +182,6 @@ impl Token {
|
||||
|
||||
(0, None)
|
||||
}
|
||||
4 | 5 | 6 => {
|
||||
if let Ok(unicode_string) = std::str::from_utf8(&characters[..]) {
|
||||
if let Ok(hex) = u32::from_str_radix(&unicode_string, 16) {
|
||||
if let Some(unicode_char) = std::char::from_u32(hex) {
|
||||
return (i, Some(Token::CharLit(unicode_char)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(0, None)
|
||||
}
|
||||
_ => (0, None),
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user