From: panasenco Date: Tue, 27 Apr 2021 18:58:39 +0000 (-0700) Subject: Alphabetized character logic in macros.rs and system_calls.rs X-Git-Tag: v0.9.0~96^2~4 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=061221b073698eba39095d79aee7879895f27b5b;p=scryer-prolog.git Alphabetized character logic in macros.rs and system_calls.rs --- diff --git a/crates/prolog_parser/src/macros.rs b/crates/prolog_parser/src/macros.rs index c05ed69b..f8ec9072 100644 --- a/crates/prolog_parser/src/macros.rs +++ b/crates/prolog_parser/src/macros.rs @@ -5,183 +5,187 @@ macro_rules! char_class { } #[macro_export] -macro_rules! symbolic_control_char { +macro_rules! alpha_char { ($c: expr) => { - $crate::char_class!($c, ['a', 'b', 'f', 'n', 'r', 't', 'v', '0']) + match $c { + 'a'..='z' => true, + 'A'..='Z' => true, + '_' => true, + '\u{00A0}'..='\u{00BF}' => true, + '\u{00C0}'..='\u{00D6}' => true, + '\u{00D8}'..='\u{00F6}' => true, + '\u{00F8}'..='\u{00FF}' => true, + '\u{0100}'..='\u{017F}' => true, // Latin Extended-A + '\u{0180}'..='\u{024F}' => true, // Latin Extended-B + '\u{0250}'..='\u{02AF}' => true, // IPA Extensions + '\u{02B0}'..='\u{02FF}' => true, // Spacing Modifier Letters + '\u{0300}'..='\u{036F}' => true, // Combining Diacritical Marks + '\u{0370}'..='\u{03FF}' => true, // Greek/Coptic + '\u{0400}'..='\u{04FF}' => true, // Cyrillic + '\u{0500}'..='\u{052F}' => true, // Cyrillic Supplement + '\u{0530}'..='\u{058F}' => true, // Armenian + '\u{0590}'..='\u{05FF}' => true, // Hebrew + '\u{0600}'..='\u{06FF}' => true, // Arabic + '\u{0700}'..='\u{074F}' => true, // Syriac + _ => false, + } }; } #[macro_export] -macro_rules! space_char { +macro_rules! alpha_numeric_char { ($c: expr) => { - $c == ' ' + $crate::alpha_char!($c) || $crate::decimal_digit_char!($c) }; } #[macro_export] -macro_rules! layout_char { +macro_rules! backslash_char { ($c: expr) => { - $crate::char_class!($c, [' ', '\n', '\t', '\u{0B}', '\u{0C}']) + $c == '\\' }; } #[macro_export] -macro_rules! symbolic_hexadecimal_char { +macro_rules! back_quote_char { ($c: expr) => { - $c == 'x' + $c == '`' }; } #[macro_export] -macro_rules! octal_digit_char { +macro_rules! binary_digit_char { ($c: expr) => { - ('0'..='7').contains(&$c) + $c >= '0' && $c <= '1' }; } #[macro_export] -macro_rules! binary_digit_char { +macro_rules! capital_letter_char { ($c: expr) => { - $c >= '0' && $c <= '1' + ('A'..='Z').contains(&$c) }; } #[macro_export] -macro_rules! hexadecimal_digit_char { +macro_rules! comment_1_char { ($c: expr) => { - ('0'..='9').contains(&$c) || ('A'..='F').contains(&$c) || ('a'..='f').contains(&$c) + $c == '/' }; } #[macro_export] -macro_rules! exponent_char { +macro_rules! comment_2_char { ($c: expr) => { - $c == 'e' || $c == 'E' + $c == '*' }; } #[macro_export] -macro_rules! sign_char { +macro_rules! cut_char { ($c: expr) => { - $c == '-' || $c == '+' + $c == '!' }; } #[macro_export] -macro_rules! new_line_char { +macro_rules! decimal_digit_char { ($c: expr) => { - $c == '\n' + ('0'..='9').contains(&$c) }; } #[macro_export] -macro_rules! end_line_comment_char { +macro_rules! decimal_point_char { ($c: expr) => { - $c == '%' + $c == '.' }; } #[macro_export] -macro_rules! comment_1_char { +macro_rules! double_quote_char { ($c: expr) => { - $c == '/' + $c == '"' }; } #[macro_export] -macro_rules! comment_2_char { +macro_rules! end_line_comment_char { ($c: expr) => { - $c == '*' + $c == '%' }; } #[macro_export] -macro_rules! capital_letter_char { +macro_rules! exponent_char { ($c: expr) => { - ('A'..='Z').contains(&$c) + $c == 'e' || $c == 'E' }; } #[macro_export] -macro_rules! small_letter_char { - ($c: expr) => { - ('a'..='z').contains(&$c) - }; +macro_rules! graphic_char { + ($c: expr) => ($crate::char_class!($c, ['#', '$', '&', '*', '+', '-', '.', '/', ':', + '<', '=', '>', '?', '@', '^', '~'])) } #[macro_export] -macro_rules! variable_indicator_char { +macro_rules! graphic_token_char { ($c: expr) => { - $c == '_' + $crate::graphic_char!($c) || $crate::backslash_char!($c) }; } #[macro_export] -macro_rules! graphic_char { - ($c: expr) => ($crate::char_class!($c, ['#', '$', '&', '*', '+', '-', '.', '/', ':', - '<', '=', '>', '?', '@', '^', '~'])) +macro_rules! hexadecimal_digit_char { + ($c: expr) => { + ('0'..='9').contains(&$c) || ('A'..='F').contains(&$c) || ('a'..='f').contains(&$c) + }; } #[macro_export] -macro_rules! graphic_token_char { +macro_rules! layout_char { ($c: expr) => { - $crate::graphic_char!($c) || $crate::backslash_char!($c) + $crate::char_class!($c, [' ', '\n', '\t', '\u{0B}', '\u{0C}']) }; } #[macro_export] -macro_rules! alpha_char { +macro_rules! meta_char { ($c: expr) => { - match $c { - 'a'..='z' => true, - 'A'..='Z' => true, - '_' => true, - '\u{00A0}'..='\u{00BF}' => true, - '\u{00C0}'..='\u{00D6}' => true, - '\u{00D8}'..='\u{00F6}' => true, - '\u{00F8}'..='\u{00FF}' => true, - '\u{0100}'..='\u{017F}' => true, // Latin Extended-A - '\u{0180}'..='\u{024F}' => true, // Latin Extended-B - '\u{0250}'..='\u{02AF}' => true, // IPA Extensions - '\u{02B0}'..='\u{02FF}' => true, // Spacing Modifier Letters - '\u{0300}'..='\u{036F}' => true, // Combining Diacritical Marks - '\u{0370}'..='\u{03FF}' => true, // Greek/Coptic - '\u{0400}'..='\u{04FF}' => true, // Cyrillic - '\u{0500}'..='\u{052F}' => true, // Cyrillic Supplement - '\u{0530}'..='\u{058F}' => true, // Armenian - '\u{0590}'..='\u{05FF}' => true, // Hebrew - '\u{0600}'..='\u{06FF}' => true, // Arabic - '\u{0700}'..='\u{074F}' => true, // Syriac - _ => false, - } + $crate::char_class!($c, ['\\', '\'', '"', '`']) }; } #[macro_export] -macro_rules! decimal_digit_char { +macro_rules! new_line_char { ($c: expr) => { - ('0'..='9').contains(&$c) + $c == '\n' }; } #[macro_export] -macro_rules! decimal_point_char { +macro_rules! octal_digit_char { ($c: expr) => { - $c == '.' + ('0'..='7').contains(&$c) }; } #[macro_export] -macro_rules! alpha_numeric_char { +macro_rules! octet_char { ($c: expr) => { - $crate::alpha_char!($c) || $crate::decimal_digit_char!($c) + ('\u{0000}'..='\u{00FF}').contains(&$c) }; } #[macro_export] -macro_rules! cut_char { +macro_rules! prolog_char { ($c: expr) => { - $c == '!' + $crate::graphic_char!($c) + || $crate::alpha_numeric_char!($c) + || $crate::solo_char!($c) + || $crate::layout_char!($c) + || $crate::meta_char!($c) }; } @@ -193,9 +197,9 @@ macro_rules! semicolon_char { } #[macro_export] -macro_rules! backslash_char { +macro_rules! sign_char { ($c: expr) => { - $c == '\\' + $c == '-' || $c == '+' }; } @@ -207,40 +211,43 @@ macro_rules! single_quote_char { } #[macro_export] -macro_rules! double_quote_char { +macro_rules! small_letter_char { ($c: expr) => { - $c == '"' + ('a'..='z').contains(&$c) }; } #[macro_export] -macro_rules! back_quote_char { +macro_rules! solo_char { ($c: expr) => { - $c == '`' + $crate::char_class!($c, ['!', '(', ')', ',', ';', '[', ']', '{', '}', '|', '%']) }; } #[macro_export] -macro_rules! meta_char { +macro_rules! space_char { ($c: expr) => { - $crate::char_class!($c, ['\\', '\'', '"', '`']) + $c == ' ' }; } #[macro_export] -macro_rules! solo_char { +macro_rules! symbolic_control_char { ($c: expr) => { - $crate::char_class!($c, ['!', '(', ')', ',', ';', '[', ']', '{', '}', '|', '%']) + $crate::char_class!($c, ['a', 'b', 'f', 'n', 'r', 't', 'v', '0']) }; } #[macro_export] -macro_rules! prolog_char { +macro_rules! symbolic_hexadecimal_char { ($c: expr) => { - $crate::graphic_char!($c) - || $crate::alpha_numeric_char!($c) - || $crate::solo_char!($c) - || $crate::layout_char!($c) - || $crate::meta_char!($c) + $c == 'x' + }; +} + +#[macro_export] +macro_rules! variable_indicator_char { + ($c: expr) => { + $c == '_' }; } diff --git a/src/machine/system_calls.rs b/src/machine/system_calls.rs index 082a3e16..428230ca 100644 --- a/src/machine/system_calls.rs +++ b/src/machine/system_calls.rs @@ -1775,46 +1775,46 @@ impl MachineState { } }; } - macro_check!(symbolic_control_char, "symbolic_control"); - // macro_check!(space_char, "space"); - macro_check!(layout_char, "layout"); - macro_check!(symbolic_hexadecimal_char, "symbolic_hexadecimal"); - macro_check!(octal_digit_char, "octal_digit"); + macro_check!(alpha_char, "alpha"); + method_check!(is_alphabetic, "alphabetic"); + method_check!(is_alphanumeric, "alphanumeric"); + macro_check!(alpha_numeric_char, "alnum"); + method_check!(is_ascii, "ascii"); + method_check!(is_ascii_punctuation, "ascii_ponctuaction"); + method_check!(is_ascii_graphic, "ascii_graphic"); + // macro_check!(backslash_char, "backslash"); + // macro_check!(back_quote_char, "back_quote"); macro_check!(binary_digit_char, "binary_digit"); - macro_check!(hexadecimal_digit_char, "hexadecimal_digit"); - macro_check!(exponent_char, "exponent"); - macro_check!(sign_char, "sign"); - // macro_check!(new_line_char, "new_line"); + // macro_check!(capital_letter_char, "upper"); // macro_check!(comment_1_char, "comment_1"); // macro_check!(comment_2_char, "comment_2"); - // macro_check!(capital_letter_char, "upper"); - // macro_check!(small_letter_char, "lower"); - // macro_check!(variable_indicator_char, "variable_indicator"); - macro_check!(graphic_char, "graphic"); - macro_check!(graphic_token_char, "graphic_token"); - macro_check!(alpha_char, "alpha"); + method_check!(is_control, "control"); + // macro_check!(cut_char, "cut"); macro_check!(decimal_digit_char, "decimal_digit"); // macro_check!(decimal_point_char, "decimal_point"); - macro_check!(alpha_numeric_char, "alnum"); - // macro_check!(cut_char, "cut"); - // macro_check!(semicolon_char, "semicolon"); - // macro_check!(backslash_char, "backslash"); - // macro_check!(single_quote_char, "single_quote"); // macro_check!(double_quote_char, "double_quote"); - // macro_check!(back_quote_char, "back_quote"); + macro_check!(exponent_char, "exponent"); + macro_check!(graphic_char, "graphic"); + macro_check!(graphic_token_char, "graphic_token"); + macro_check!(hexadecimal_digit_char, "hexadecimal_digit"); + macro_check!(layout_char, "layout"); + method_check!(is_lowercase, "lower"); macro_check!(meta_char, "meta"); - macro_check!(solo_char, "solo"); + // macro_check!(new_line_char, "new_line"); + method_check!(is_numeric, "numeric"); + macro_check!(octal_digit_char, "octal_digit"); macro_check!(prolog_char, "prolog"); - method_check!(is_alphabetic, "alphabetic"); - method_check!(is_lowercase, "lower"); + // macro_check!(semicolon_char, "semicolon"); + macro_check!(sign_char, "sign"); + // macro_check!(single_quote_char, "single_quote"); + // macro_check!(small_letter_char, "lower"); + macro_check!(solo_char, "solo"); + // macro_check!(space_char, "space"); + macro_check!(symbolic_hexadecimal_char, "symbolic_hexadecimal"); + macro_check!(symbolic_control_char, "symbolic_control"); method_check!(is_uppercase, "upper"); + // macro_check!(variable_indicator_char, "variable_indicator"); method_check!(is_whitespace, "whitespace"); - method_check!(is_alphanumeric, "alphanumeric"); - method_check!(is_control, "control"); - method_check!(is_numeric, "numeric"); - method_check!(is_ascii, "ascii"); - method_check!(is_ascii_punctuation, "ascii_ponctuaction"); - method_check!(is_ascii_graphic, "ascii_graphic"); } &SystemClauseType::CheckCutPoint => { let addr = self.store(self.deref(self[temp_v!(1)]));