From c8de6826c21a13aac40a80c9aab2e6d27b4147bf Mon Sep 17 00:00:00 2001 From: collin <16715212+collinc97@users.noreply.github.com> Date: Thu, 12 May 2022 13:16:25 -0700 Subject: [PATCH] preserve char scalar nonscalar --- compiler/ast/src/chars/char_value.rs | 10 +++++----- compiler/parser/src/tokenizer/lexer.rs | 22 +++++++++++----------- compiler/parser/src/tokenizer/token.rs | 12 ++++++------ 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/compiler/ast/src/chars/char_value.rs b/compiler/ast/src/chars/char_value.rs index a3e218b798..18ed903bfb 100644 --- a/compiler/ast/src/chars/char_value.rs +++ b/compiler/ast/src/chars/char_value.rs @@ -31,24 +31,24 @@ where D: ::serde::de::Deserializer<'de>, { let int = u32::deserialize(deserializer)?; - std::char::from_u32(int).ok_or_else(|| ::serde::de::Error::custom("Failed to convert u32 to primitive char.")) + std::char::from_u32(int).ok_or_else(|| ::serde::de::Error::custom("Failed to convert u32 to scalar char.")) } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum Char { - Primitive( + Scalar( #[serde(deserialize_with = "char_from_u32")] #[serde(serialize_with = "char_to_u32")] char, ), - NonPrimitive(u32), + NonScalar(u32), } impl fmt::Display for Char { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::Primitive(c) => write!(f, "{}", c), - Self::NonPrimitive(c) => write!(f, "{:X}", c), + Self::Scalar(c) => write!(f, "{}", c), + Self::NonScalar(c) => write!(f, "{:X}", c), } } } diff --git a/compiler/parser/src/tokenizer/lexer.rs b/compiler/parser/src/tokenizer/lexer.rs index 849d45fb7d..4764d341b0 100644 --- a/compiler/parser/src/tokenizer/lexer.rs +++ b/compiler/parser/src/tokenizer/lexer.rs @@ -79,9 +79,9 @@ impl Token { if let Ok(hex) = u32::from_str_radix(&unicode, 16) { if let Some(character) = std::char::from_u32(hex) { - Ok((len, Char::Primitive(character))) + Ok((len, Char::Scalar(character))) } else if hex <= 0x10FFFF { - Ok((len, Char::NonPrimitive(hex))) + Ok((len, Char::NonScalar(hex))) } else { Err(ParserError::lexer_invalid_character_exceeded_max_value(unicode).into()) } @@ -122,7 +122,7 @@ impl Token { return Err(ParserError::lexer_expected_valid_hex_char(hex).into()); } - Ok((len, Char::Primitive(ascii_number as char))) + Ok((len, Char::Scalar(ascii_number as char))) } else { Err(ParserError::lexer_expected_valid_hex_char(hex).into()) } @@ -132,13 +132,13 @@ impl Token { match input.next() { None => Err(ParserError::lexer_empty_input_tendril().into()), // Length of 2 to account the '\'. - Some('0') => Ok((2, Char::Primitive(0 as char))), - Some('t') => Ok((2, Char::Primitive(9 as char))), - Some('n') => Ok((2, Char::Primitive(10 as char))), - Some('r') => Ok((2, Char::Primitive(13 as char))), - Some('\"') => Ok((2, Char::Primitive(34 as char))), - Some('\'') => Ok((2, Char::Primitive(39 as char))), - Some('\\') => Ok((2, Char::Primitive(92 as char))), + Some('0') => Ok((2, Char::Scalar(0 as char))), + Some('t') => Ok((2, Char::Scalar(9 as char))), + Some('n') => Ok((2, Char::Scalar(10 as char))), + Some('r') => Ok((2, Char::Scalar(13 as char))), + Some('\"') => Ok((2, Char::Scalar(34 as char))), + Some('\'') => Ok((2, Char::Scalar(39 as char))), + Some('\\') => Ok((2, Char::Scalar(92 as char))), Some('u') => Self::eat_unicode_char(input), Some('x') => Self::eat_hex_char(input), Some(c) => Err(ParserError::lexer_expected_valid_escaped_char(c).into()), @@ -150,7 +150,7 @@ impl Token { match input.next() { None => Err(ParserError::lexer_empty_input_tendril().into()), Some('\\') => Self::eat_escaped_char(input), - Some(c) => Ok((c.len_utf8(), Char::Primitive(c))), + Some(c) => Ok((c.len_utf8(), Char::Scalar(c))), } } diff --git a/compiler/parser/src/tokenizer/token.rs b/compiler/parser/src/tokenizer/token.rs index ff3bd639fd..5a0d58aff6 100644 --- a/compiler/parser/src/tokenizer/token.rs +++ b/compiler/parser/src/tokenizer/token.rs @@ -21,16 +21,16 @@ use std::fmt; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub enum Char { - Primitive(char), - NonPrimitive(u32), + Scalar(char), + NonScalar(u32), } #[allow(clippy::from_over_into)] impl Into for Char { fn into(self) -> leo_ast::Char { match self { - Self::Primitive(c) => leo_ast::Char::Primitive(c), - Self::NonPrimitive(c) => leo_ast::Char::NonPrimitive(c), + Self::Scalar(c) => leo_ast::Char::Scalar(c), + Self::NonScalar(c) => leo_ast::Char::NonScalar(c), } } } @@ -38,8 +38,8 @@ impl Into for Char { impl fmt::Display for Char { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::Primitive(c) => write!(f, "{}", c), - Self::NonPrimitive(c) => write!(f, "{:X}", c), + Self::Scalar(c) => write!(f, "{}", c), + Self::NonScalar(c) => write!(f, "{:X}", c), } } }