From 8f17d6294a1dc9ebbff3f6af6160abf469767ca8 Mon Sep 17 00:00:00 2001 From: collin <16715212+collinc97@users.noreply.github.com> Date: Wed, 11 May 2022 14:09:12 -0700 Subject: [PATCH 1/2] rename scalar -> primitive --- compiler/ast/src/chars/char_value.rs | 10 +++--- compiler/parser/src/tokenizer/lexer.rs | 23 ++++++------- compiler/parser/src/tokenizer/token.rs | 12 +++---- docs/grammar/README.md | Bin 50324 -> 50354 bytes docs/grammar/abnf-grammar.txt | 4 +-- .../compiler/compiler/char/neq.leo.out | 32 +++++++++--------- .../compiler/compiler/char/out.leo.out | 32 +++++++++--------- .../compiler/compiler/console/error.leo.out | 2 +- .../compiler/compiler/console/log.leo.out | 2 +- .../compiler/console/log_conditional.leo.out | 2 +- .../compiler/console/log_input.leo.out | 2 +- .../compiler/console/log_parameter.leo.out | 2 +- .../console/log_parameter_many.leo.out | 2 +- .../program_input/main_group.leo.out | 2 +- .../main_group.leo.out | 2 +- .../parser/parser/statement/console.leo.out | 28 +++++++-------- 16 files changed, 78 insertions(+), 79 deletions(-) diff --git a/compiler/ast/src/chars/char_value.rs b/compiler/ast/src/chars/char_value.rs index 18ed903bfb..a3e218b798 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 scalar char.")) + std::char::from_u32(int).ok_or_else(|| ::serde::de::Error::custom("Failed to convert u32 to primitive char.")) } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum Char { - Scalar( + Primitive( #[serde(deserialize_with = "char_from_u32")] #[serde(serialize_with = "char_to_u32")] char, ), - NonScalar(u32), + NonPrimitive(u32), } impl fmt::Display for Char { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::Scalar(c) => write!(f, "{}", c), - Self::NonScalar(c) => write!(f, "{:X}", c), + Self::Primitive(c) => write!(f, "{}", c), + Self::NonPrimitive(c) => write!(f, "{:X}", c), } } } diff --git a/compiler/parser/src/tokenizer/lexer.rs b/compiler/parser/src/tokenizer/lexer.rs index a8d820f815..849d45fb7d 100644 --- a/compiler/parser/src/tokenizer/lexer.rs +++ b/compiler/parser/src/tokenizer/lexer.rs @@ -79,10 +79,9 @@ impl Token { if let Ok(hex) = u32::from_str_radix(&unicode, 16) { if let Some(character) = std::char::from_u32(hex) { - // scalar - Ok((len, Char::Scalar(character))) + Ok((len, Char::Primitive(character))) } else if hex <= 0x10FFFF { - Ok((len, Char::NonScalar(hex))) + Ok((len, Char::NonPrimitive(hex))) } else { Err(ParserError::lexer_invalid_character_exceeded_max_value(unicode).into()) } @@ -123,7 +122,7 @@ impl Token { return Err(ParserError::lexer_expected_valid_hex_char(hex).into()); } - Ok((len, Char::Scalar(ascii_number as char))) + Ok((len, Char::Primitive(ascii_number as char))) } else { Err(ParserError::lexer_expected_valid_hex_char(hex).into()) } @@ -133,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::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('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('u') => Self::eat_unicode_char(input), Some('x') => Self::eat_hex_char(input), Some(c) => Err(ParserError::lexer_expected_valid_escaped_char(c).into()), @@ -151,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::Scalar(c))), + Some(c) => Ok((c.len_utf8(), Char::Primitive(c))), } } diff --git a/compiler/parser/src/tokenizer/token.rs b/compiler/parser/src/tokenizer/token.rs index 5a0d58aff6..ff3bd639fd 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 { - Scalar(char), - NonScalar(u32), + Primitive(char), + NonPrimitive(u32), } #[allow(clippy::from_over_into)] impl Into for Char { fn into(self) -> leo_ast::Char { match self { - Self::Scalar(c) => leo_ast::Char::Scalar(c), - Self::NonScalar(c) => leo_ast::Char::NonScalar(c), + Self::Primitive(c) => leo_ast::Char::Primitive(c), + Self::NonPrimitive(c) => leo_ast::Char::NonPrimitive(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::Scalar(c) => write!(f, "{}", c), - Self::NonScalar(c) => write!(f, "{:X}", c), + Self::Primitive(c) => write!(f, "{}", c), + Self::NonPrimitive(c) => write!(f, "{:X}", c), } } } diff --git a/docs/grammar/README.md b/docs/grammar/README.md index 45be683ef56ad0a8b41fc1a818e2651a7bd37162..b25a20102ef10fb58f8ce66d81282b09b1ad4ac6 100644 GIT binary patch delta 121 zcmbQz$-JqPc|%x+U;#rBLncEm5SIXP8AIyijcK}*1By5};Ub%7W>hm_QJ9#jk43aF QOB;)5W3v9{ec9I{05?4%)c^nh delta 101 zcmdng$vmZ#c|%wRXE8%ELn1>CL*nF%>H6Go9z)UQr5V*s$O4lSQ&AL5R?N~yk#9`a SpX^Y;GkIRF$mT!U+adtt@gB7R diff --git a/docs/grammar/abnf-grammar.txt b/docs/grammar/abnf-grammar.txt index 6dd159e16b..e340336d2a 100644 --- a/docs/grammar/abnf-grammar.txt +++ b/docs/grammar/abnf-grammar.txt @@ -222,9 +222,9 @@ address-type = %s"address" character-type = %s"char" -scalar-type = boolean-type / arithmetic-type / address-type / character-type +primitive-type = boolean-type / arithmetic-type / address-type / character-type -type = scalar-type +type = primitive-type group-coordinate = ( [ "-" ] numeral ) / "+" / "-" / "_" diff --git a/tests/expectations/compiler/compiler/char/neq.leo.out b/tests/expectations/compiler/compiler/char/neq.leo.out index 37030dd649..01af1b1a7d 100644 --- a/tests/expectations/compiler/compiler/char/neq.leo.out +++ b/tests/expectations/compiler/compiler/char/neq.leo.out @@ -3,20 +3,20 @@ namespace: Compile expectation: Pass outputs: - output: - - initial_input_ast: cd2c41435af95147ff1dcd94031e443b93b15ac7b4f65331ef734759006f3c03 - - initial_input_ast: 5e4fd7cfc681e863ed393f7746308d7b962e2b5f9dcd21aa09a26526ce2ea8e3 - - initial_input_ast: 8fcda0e92250e9897bdb8cfb9b1e3046f94f6f6206ecb958d9758e64e5615889 - - initial_input_ast: 41fef97affd26b29428302f519a5e7a7d61158923e6576618c42607f0c16ff4f - - initial_input_ast: 30c56d9a2e096215900942f18b63cf5a96fb9c0b7cf4fea11dafeeabb02a5233 - - initial_input_ast: 076d0f1b70534c15108ea0dc9e74860030d6701ce1ce38b4a3a41e5ba9fe0121 - - initial_input_ast: d3bff6374e68b63bf35fe089bbff0abb31958571b99b9e0251d82895fdc27edd - - initial_input_ast: 9455652735eb74bd67423f9ed2c7d76b1b27e47f62b5331843f8f4975a03cc9a - - initial_input_ast: 3f69c5fdd03605808dfb6ae116cdf860525b494d5d7cac39b667931c282e8c3e - - initial_input_ast: bdc202a836d17bcb974e33b5b938148c0c9b57fd8b779e813c26d8feac915547 - - initial_input_ast: 6e12715d32233251ea63ae7457c7c1d20e82995cf3df02a1adb943ee358a2643 - - initial_input_ast: 6383f20ea72b337521956a9d86608fc1861f8a5e709bb29e88f2022e893d4e59 - - initial_input_ast: e4ba1106bf3425f620578111bd3c63c0178dbc087ab4c90e873c5b9cc790f6bc - - initial_input_ast: 4c7f9b03dd308ff3981127c4c12adcb883fd8b3ce1dbd744cd935750961fc1c4 - - initial_input_ast: 2a5e92af845c8a56375cbc6123e92aa87cf4523e059c02dfcde326970d88f5c2 - initial_ast: 9733a36e7d3465c6217ecf2139c2e4154790e39f006f1e3318a981265d24ad23 + - initial_input_ast: c5014ebe0b04ecf0cfca9befc3cad1725daf451b4a926741ef909fe396007891 + - initial_input_ast: e754ce377bf760178cf72cf8b0e1597c94eb833bf18e3524c99cd86c6ac4b003 + - initial_input_ast: ff9ecea579f37e0abbac30d7065f5293b0bf8affc53cfd627e0e1e43227e9b27 + - initial_input_ast: 72a3e3befe5feac1a922a42ce7fa7f1bc495eeeab43b3be86df09db770c93e73 + - initial_input_ast: 45237feb75335b96d98682c743ededad68167fcc6ad151eca3caa55b1625b647 + - initial_input_ast: c14a6deb2a1f0f60320260b189fea801ee942e3e44e0d6334067d6d7972eb4be + - initial_input_ast: 38431bcff38b26387d2f41af68d2a6e22d184be6d44dbcdc6e5eda62ae822d40 + - initial_input_ast: 767918cd56f1bc8a9c6b64cc0e92dab97698e500588a0cf480e0b5838e7067f0 + - initial_input_ast: c7ba648f22d3b30d4f62a1093a2dcab8def815aa9f7083ee4fe9236dd63b1c0e + - initial_input_ast: d6acd30374e64196b072f5a1c68ba379cce1eb5e866afac4acd98643f68d1c03 + - initial_input_ast: 2aa446f52a535b7918039280d90d098deea58ae0d84445dd31a8c66f05f52449 + - initial_input_ast: 69a6b4dcd3e363cce68ccdae93f77ead9319af6886aecf775a09a0ed535bb02b + - initial_input_ast: c2f4b8b92cb0ee71de7fd532b483c2fb2c9ebcc8a59249a763fc30d05eb5d38e + - initial_input_ast: 9196de328711651e75edb7ffba6b85b37ca468d509b0e96e6b5271d6d0785949 + - initial_input_ast: 012468d79c66ea8de1b7357678f0dd4f12a4188b384ed38696934add946dc72f + initial_ast: 5ee529ed9657976f562ba09ffbd0c642283ac523a4ed4df18520a26b3769e408 symbol_table: cf3569155d9961e6cab441ea9a60f5c92d2b18e6cd2ecaa64b1529d1774d3585 diff --git a/tests/expectations/compiler/compiler/char/out.leo.out b/tests/expectations/compiler/compiler/char/out.leo.out index 89eedc779d..514b3aac5d 100644 --- a/tests/expectations/compiler/compiler/char/out.leo.out +++ b/tests/expectations/compiler/compiler/char/out.leo.out @@ -3,20 +3,20 @@ namespace: Compile expectation: Pass outputs: - output: - - initial_input_ast: cd2c41435af95147ff1dcd94031e443b93b15ac7b4f65331ef734759006f3c03 - - initial_input_ast: 5e4fd7cfc681e863ed393f7746308d7b962e2b5f9dcd21aa09a26526ce2ea8e3 - - initial_input_ast: 8fcda0e92250e9897bdb8cfb9b1e3046f94f6f6206ecb958d9758e64e5615889 - - initial_input_ast: 41fef97affd26b29428302f519a5e7a7d61158923e6576618c42607f0c16ff4f - - initial_input_ast: 30c56d9a2e096215900942f18b63cf5a96fb9c0b7cf4fea11dafeeabb02a5233 - - initial_input_ast: 076d0f1b70534c15108ea0dc9e74860030d6701ce1ce38b4a3a41e5ba9fe0121 - - initial_input_ast: d3bff6374e68b63bf35fe089bbff0abb31958571b99b9e0251d82895fdc27edd - - initial_input_ast: 9455652735eb74bd67423f9ed2c7d76b1b27e47f62b5331843f8f4975a03cc9a - - initial_input_ast: 3f69c5fdd03605808dfb6ae116cdf860525b494d5d7cac39b667931c282e8c3e - - initial_input_ast: bdc202a836d17bcb974e33b5b938148c0c9b57fd8b779e813c26d8feac915547 - - initial_input_ast: 6e12715d32233251ea63ae7457c7c1d20e82995cf3df02a1adb943ee358a2643 - - initial_input_ast: 6383f20ea72b337521956a9d86608fc1861f8a5e709bb29e88f2022e893d4e59 - - initial_input_ast: e4ba1106bf3425f620578111bd3c63c0178dbc087ab4c90e873c5b9cc790f6bc - - initial_input_ast: 4c7f9b03dd308ff3981127c4c12adcb883fd8b3ce1dbd744cd935750961fc1c4 - - initial_input_ast: 2a5e92af845c8a56375cbc6123e92aa87cf4523e059c02dfcde326970d88f5c2 - initial_ast: 890e5d07cf4b2967be0e2f9c82268619015dc3cea62cc1520f406107cdd056e5 + - initial_input_ast: c5014ebe0b04ecf0cfca9befc3cad1725daf451b4a926741ef909fe396007891 + - initial_input_ast: e754ce377bf760178cf72cf8b0e1597c94eb833bf18e3524c99cd86c6ac4b003 + - initial_input_ast: ff9ecea579f37e0abbac30d7065f5293b0bf8affc53cfd627e0e1e43227e9b27 + - initial_input_ast: 72a3e3befe5feac1a922a42ce7fa7f1bc495eeeab43b3be86df09db770c93e73 + - initial_input_ast: 45237feb75335b96d98682c743ededad68167fcc6ad151eca3caa55b1625b647 + - initial_input_ast: c14a6deb2a1f0f60320260b189fea801ee942e3e44e0d6334067d6d7972eb4be + - initial_input_ast: 38431bcff38b26387d2f41af68d2a6e22d184be6d44dbcdc6e5eda62ae822d40 + - initial_input_ast: 767918cd56f1bc8a9c6b64cc0e92dab97698e500588a0cf480e0b5838e7067f0 + - initial_input_ast: c7ba648f22d3b30d4f62a1093a2dcab8def815aa9f7083ee4fe9236dd63b1c0e + - initial_input_ast: d6acd30374e64196b072f5a1c68ba379cce1eb5e866afac4acd98643f68d1c03 + - initial_input_ast: 2aa446f52a535b7918039280d90d098deea58ae0d84445dd31a8c66f05f52449 + - initial_input_ast: 69a6b4dcd3e363cce68ccdae93f77ead9319af6886aecf775a09a0ed535bb02b + - initial_input_ast: c2f4b8b92cb0ee71de7fd532b483c2fb2c9ebcc8a59249a763fc30d05eb5d38e + - initial_input_ast: 9196de328711651e75edb7ffba6b85b37ca468d509b0e96e6b5271d6d0785949 + - initial_input_ast: 012468d79c66ea8de1b7357678f0dd4f12a4188b384ed38696934add946dc72f + initial_ast: 3965395dcb477379853989110bf621aefc6a052ee39e06b9e1d15dbe0f0de184 symbol_table: 1cad55eef598e4d05af7c5f88119636a2e6d23d81213bbaad908d66a32906780 diff --git a/tests/expectations/compiler/compiler/console/error.leo.out b/tests/expectations/compiler/compiler/console/error.leo.out index 5246ca94f5..4271b5f36e 100644 --- a/tests/expectations/compiler/compiler/console/error.leo.out +++ b/tests/expectations/compiler/compiler/console/error.leo.out @@ -4,5 +4,5 @@ expectation: Pass outputs: - output: - initial_input_ast: 38e6b369397fcf11fa921808be61baf33a705d4509bc15a46ec69e1a0aaa5031 - initial_ast: 379919a368ef91f880f8209c68891ac5b5071c3d7f64ae15b39eaab52972d6a9 + initial_ast: d1d00796ff928991e5c898877a2f6e540dc744807d696b3b14af935e380eafb4 symbol_table: d46f6eb98259f34d32a60788aa178efa34166bcc6ba1058e2ff5f8327a129b9c diff --git a/tests/expectations/compiler/compiler/console/log.leo.out b/tests/expectations/compiler/compiler/console/log.leo.out index bfc714d28d..951ba01393 100644 --- a/tests/expectations/compiler/compiler/console/log.leo.out +++ b/tests/expectations/compiler/compiler/console/log.leo.out @@ -4,5 +4,5 @@ expectation: Pass outputs: - output: - initial_input_ast: 38e6b369397fcf11fa921808be61baf33a705d4509bc15a46ec69e1a0aaa5031 - initial_ast: c573c8914fc34302d6ea0ad1727f61b02c540f2f9dce82fd492407002516a367 + initial_ast: a2e9492d07dd4600eb79386662e4fd1f56b5c95fe4b05ef149a346e1b935f908 symbol_table: 559484bc163178bf54b169f5dd573167771566aa993055b6a28f0c1a759339bc diff --git a/tests/expectations/compiler/compiler/console/log_conditional.leo.out b/tests/expectations/compiler/compiler/console/log_conditional.leo.out index 3bf860dc62..738f68bb81 100644 --- a/tests/expectations/compiler/compiler/console/log_conditional.leo.out +++ b/tests/expectations/compiler/compiler/console/log_conditional.leo.out @@ -5,5 +5,5 @@ outputs: - output: - initial_input_ast: b9ca1f9e4746ba9f99375205e309b977a522109054d058039197767b39fa6833 - initial_input_ast: 398a847f3f6c8826a10942c856b67d9acf37a51bf4ec9109be549b24b2dfff94 - initial_ast: 29f607e8e1badfbb612a8acb20123882205c86c7290a24dca70df39f8261cc0b + initial_ast: a80b061288d4070d42ab6f4b37404004faab51e8a58cd301632c88bf940e9630 symbol_table: 560afbb790df70bfc770d5c2f966428a37baf94a5c0f5312ad445456d33a2cd9 diff --git a/tests/expectations/compiler/compiler/console/log_input.leo.out b/tests/expectations/compiler/compiler/console/log_input.leo.out index 7f7a2c9cc2..e70584d630 100644 --- a/tests/expectations/compiler/compiler/console/log_input.leo.out +++ b/tests/expectations/compiler/compiler/console/log_input.leo.out @@ -4,5 +4,5 @@ expectation: Pass outputs: - output: - initial_input_ast: 38e6b369397fcf11fa921808be61baf33a705d4509bc15a46ec69e1a0aaa5031 - initial_ast: a5cf98065c1f1a668d898974ab67cd148e43409c0455d95f77e030cb5c905e0c + initial_ast: fd62f417968d0212bd96f8069d2afafeb1f6f44e3270d1b729687cb82d882a12 symbol_table: 720c2aafae77c261ed1640d4080f9a73657638baa30e54a5e10e2323b6f6eca0 diff --git a/tests/expectations/compiler/compiler/console/log_parameter.leo.out b/tests/expectations/compiler/compiler/console/log_parameter.leo.out index ef0a0b55a2..fbd69c8791 100644 --- a/tests/expectations/compiler/compiler/console/log_parameter.leo.out +++ b/tests/expectations/compiler/compiler/console/log_parameter.leo.out @@ -4,5 +4,5 @@ expectation: Pass outputs: - output: - initial_input_ast: 38e6b369397fcf11fa921808be61baf33a705d4509bc15a46ec69e1a0aaa5031 - initial_ast: 1b5cb8e6d851548c2413ef9d0e90bc46b70ee109655c5396522ae06a73832015 + initial_ast: d95ed89ada21401d204e86326c24904a1155dce3b2c9189741152f2b0c0d2f2b symbol_table: e5159343ab03573032873783b28058a482dd401d534a0d3af03790a5286ba470 diff --git a/tests/expectations/compiler/compiler/console/log_parameter_many.leo.out b/tests/expectations/compiler/compiler/console/log_parameter_many.leo.out index 634260b8f8..2398d97482 100644 --- a/tests/expectations/compiler/compiler/console/log_parameter_many.leo.out +++ b/tests/expectations/compiler/compiler/console/log_parameter_many.leo.out @@ -4,5 +4,5 @@ expectation: Pass outputs: - output: - initial_input_ast: 38e6b369397fcf11fa921808be61baf33a705d4509bc15a46ec69e1a0aaa5031 - initial_ast: 620af027368aff6683ef9951f714867e1c53d335621b549978177c0951a67ecb + initial_ast: 916cd6ab87496b67555c23de086a4a309a9a7630c4d1e198f04d3eb591fabecf symbol_table: 757bb967973b87466c01be1a9dc78d30701964e0d234e0e65d1bbcbd3072370f diff --git a/tests/expectations/compiler/compiler/input_files/program_input/main_group.leo.out b/tests/expectations/compiler/compiler/input_files/program_input/main_group.leo.out index 0af1412d06..69431b0427 100644 --- a/tests/expectations/compiler/compiler/input_files/program_input/main_group.leo.out +++ b/tests/expectations/compiler/compiler/input_files/program_input/main_group.leo.out @@ -4,5 +4,5 @@ expectation: Pass outputs: - output: - initial_input_ast: 723e9ab87822d7d8d793ca1611eabcebc684097a64f37a4cd246ff9e506a4865 - initial_ast: 859a9100240b8dee329a930cae6345f5439da844613f48b19e342b007cb9e03a + initial_ast: 89442f5bc5d415d22f6a22b3641734b1e0c453f1822c7f9fb0d6d3072d047a8c symbol_table: 3b68eff86b45e4f940b0a1031e19a64178b0bf802acb59f3b743e664f3010876 diff --git a/tests/expectations/compiler/compiler/input_files/program_input_constants/main_group.leo.out b/tests/expectations/compiler/compiler/input_files/program_input_constants/main_group.leo.out index 1bdd228b21..2e65759104 100644 --- a/tests/expectations/compiler/compiler/input_files/program_input_constants/main_group.leo.out +++ b/tests/expectations/compiler/compiler/input_files/program_input_constants/main_group.leo.out @@ -4,5 +4,5 @@ expectation: Pass outputs: - output: - initial_input_ast: eebcd00b27aba004420d4f00da025325da9ff86d29162e54401fa55b5758ae39 - initial_ast: 94bd517ef2de4cf61c4e3283b072c8efdd9c824dd00479e59dae1e19aa1133b5 + initial_ast: 5fc06cd70dd3d4298f68efc459395ba391fb5845d4839586df0b6260094c5846 symbol_table: 14140f05d5fb8a85352940a67860fd36ed597f93ac882fdb76ef3d1ed89b5031 diff --git a/tests/expectations/parser/parser/statement/console.leo.out b/tests/expectations/parser/parser/statement/console.leo.out index ac03e47b00..f9f8b91d93 100644 --- a/tests/expectations/parser/parser/statement/console.leo.out +++ b/tests/expectations/parser/parser/statement/console.leo.out @@ -17,8 +17,8 @@ outputs: function: Error: string: - - Scalar: 123 - - Scalar: 125 + - Primitive: 123 + - Primitive: 125 parameters: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":21,\\\"col_stop\\\":22,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"console.error(\\\\\\\"{}\\\\\\\", x);\\\"}\"}" span: @@ -39,10 +39,10 @@ outputs: function: Error: string: - - Scalar: 123 - - Scalar: 125 - - Scalar: 123 - - Scalar: 125 + - Primitive: 123 + - Primitive: 125 + - Primitive: 123 + - Primitive: 125 parameters: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":23,\\\"col_stop\\\":24,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"console.error(\\\\\\\"{}{}\\\\\\\", x, y);\\\"}\"}" - Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":26,\\\"col_stop\\\":27,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"console.error(\\\\\\\"{}{}\\\\\\\", x, y);\\\"}\"}" @@ -64,7 +64,7 @@ outputs: function: Error: string: - - Scalar: 120 + - Primitive: 120 parameters: [] span: line_start: 1 @@ -84,8 +84,8 @@ outputs: function: Log: string: - - Scalar: 123 - - Scalar: 125 + - Primitive: 123 + - Primitive: 125 parameters: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":19,\\\"col_stop\\\":20,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"console.log(\\\\\\\"{}\\\\\\\", x);\\\"}\"}" span: @@ -106,10 +106,10 @@ outputs: function: Log: string: - - Scalar: 123 - - Scalar: 125 - - Scalar: 123 - - Scalar: 125 + - Primitive: 123 + - Primitive: 125 + - Primitive: 123 + - Primitive: 125 parameters: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":21,\\\"col_stop\\\":22,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"console.log(\\\\\\\"{}{}\\\\\\\", x, y);\\\"}\"}" - Identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":24,\\\"col_stop\\\":25,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"console.log(\\\\\\\"{}{}\\\\\\\", x, y);\\\"}\"}" @@ -131,7 +131,7 @@ outputs: function: Log: string: - - Scalar: 120 + - Primitive: 120 parameters: [] span: line_start: 1 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 2/2] 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), } } }