From c767907b25d34a740b1d1b5d7aa7896842d650a3 Mon Sep 17 00:00:00 2001 From: 0rphon <59403052+0rphon@users.noreply.github.com> Date: Fri, 18 Feb 2022 16:29:24 -0700 Subject: [PATCH] removed more dead lexer code --- parser/src/tokenizer/lexer.rs | 34 ++++++++----------- .../parser/expression/literal/char.leo.out | 11 ++++++ .../expression/literal/char_fail.leo.out | 1 + tests/parser/expression/literal/char.leo | 1 + tests/parser/expression/literal/char_fail.leo | 1 + 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/parser/src/tokenizer/lexer.rs b/parser/src/tokenizer/lexer.rs index 2c22e57b04..8e76253419 100644 --- a/parser/src/tokenizer/lexer.rs +++ b/parser/src/tokenizer/lexer.rs @@ -76,17 +76,17 @@ impl Token { if escaped.len() != 1 { return None; - } - - return match escaped.chars().next().unwrap() { - '0' => Some(Char::Scalar(0 as char)), - 't' => Some(Char::Scalar(9 as char)), - 'n' => Some(Char::Scalar(10 as char)), - 'r' => Some(Char::Scalar(13 as char)), - '\"' => Some(Char::Scalar(34 as char)), - '\'' => Some(Char::Scalar(39 as char)), - '\\' => Some(Char::Scalar(92 as char)), - _ => None, + } else { + return match escaped.chars().next().unwrap() { + '0' => Some(Char::Scalar(0 as char)), + 't' => Some(Char::Scalar(9 as char)), + 'n' => Some(Char::Scalar(10 as char)), + 'r' => Some(Char::Scalar(13 as char)), + '\"' => Some(Char::Scalar(34 as char)), + '\'' => Some(Char::Scalar(39 as char)), + '\\' => Some(Char::Scalar(92 as char)), + _ => None, + }; }; } @@ -96,15 +96,13 @@ impl Token { if hex_string.len() != 2 { return None; - } - - if let Ok(ascii_number) = u8::from_str_radix(hex_string, 16) { + } else if let Ok(ascii_number) = u8::from_str_radix(hex_string, 16) { // According to RFC, we allow only values less than 128. if ascii_number > 127 { return None; + } else { + return Some(Char::Scalar(ascii_number as char)); } - - return Some(Char::Scalar(ascii_number as char)); } } @@ -118,9 +116,7 @@ impl Token { let len = unicode_number.len(); if !(1..=6).contains(&len) { return None; - } - - if let Ok(hex) = u32::from_str_radix(unicode_number, 16) { + } else if let Ok(hex) = u32::from_str_radix(unicode_number, 16) { if let Some(character) = std::char::from_u32(hex) { // scalar return Some(Char::Scalar(character)); diff --git a/tests/expectations/parser/parser/expression/literal/char.leo.out b/tests/expectations/parser/parser/expression/literal/char.leo.out index 0ceeb2c2f2..fc3cfb55ad 100644 --- a/tests/expectations/parser/parser/expression/literal/char.leo.out +++ b/tests/expectations/parser/parser/expression/literal/char.leo.out @@ -145,6 +145,17 @@ outputs: col_stop: 5 path: "" content: "'Ӡ'" + - Value: + Char: + character: + NonScalar: 55296 + span: + line_start: 1 + line_stop: 1 + col_start: 1 + col_stop: 11 + path: "" + content: "'\\u{d800}'" - Value: Char: character: diff --git a/tests/expectations/parser/parser/expression/literal/char_fail.leo.out b/tests/expectations/parser/parser/expression/literal/char_fail.leo.out index 30507bca2f..6b1e104d08 100644 --- a/tests/expectations/parser/parser/expression/literal/char_fail.leo.out +++ b/tests/expectations/parser/parser/expression/literal/char_fail.leo.out @@ -37,4 +37,5 @@ outputs: - "Error [EPAR0370000]: '\n --> test:1:1\n |\n 1 | '\\u00000000'\n | ^" - "Error [EPAR0370000]: '\n --> test:1:1\n |\n 1 | '\\u01000000'\n | ^" - "Error [EPAR0370000]: '\n --> test:1:1\n |\n 1 | '\\u9999999'\n | ^" + - "Error [EPAR0370000]: '\n --> test:1:1\n |\n 1 | '\\u{110000}'\n | ^" - "Error [EPAR0370000]: '\n --> test:1:1\n |\n 1 | '😭😂😘'\n | ^" diff --git a/tests/parser/expression/literal/char.leo b/tests/parser/expression/literal/char.leo index e665284a00..206a48cff5 100644 --- a/tests/parser/expression/literal/char.leo +++ b/tests/parser/expression/literal/char.leo @@ -16,6 +16,7 @@ expectation: Pass 'å' '\u{4e0}' 'Ӡ' +'\u{d800}' '\u{2764}' '❤' '\u{1F622}' diff --git a/tests/parser/expression/literal/char_fail.leo b/tests/parser/expression/literal/char_fail.leo index baac67875a..769d3aafdd 100644 --- a/tests/parser/expression/literal/char_fail.leo +++ b/tests/parser/expression/literal/char_fail.leo @@ -45,5 +45,6 @@ expectation: Fail '\u00000000' '\u01000000' '\u9999999' +'\u{110000}' '😭😂😘'