Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

better name and docs for macro

author
Giacomo Cavalieri
committer
Louis Pilfold
date (Jul 14, 2026, 12:57 PM +0100) commit aa58ba10 parent cebf7066 change-id xpyumpsq
+20 -16
+20 -16
erlang-abstract-format/src/lib.rs
··· 8 8 use regex::Regex; 9 9 use std::sync::OnceLock; 10 10 11 - macro_rules! pretty_printing_error { 11 + /// This is to raise an `unreachable` pretty printed error when we try producing 12 + /// some piece of code that is not allowed in the current position. 13 + macro_rules! invalid_code_for_position { 12 14 ($this:expr, $expected:literal) => { 13 - unreachable!("{}", $this.pretty_error_message($expected)) 15 + unreachable!("{}", $this.error_with_position($expected)) 14 16 }; 15 17 } 16 18 ··· 2233 2235 segment_size_needs_wrapping, 2234 2236 }) = self.position.last_mut() 2235 2237 else { 2236 - pretty_printing_error!(self, "bit array segment specifier"); 2238 + invalid_code_for_position!(self, "bit array segment specifier"); 2237 2239 }; 2238 2240 2239 2241 if *segment_value_needs_wrapping { ··· 2572 2574 fn new_top_level_form(&mut self) { 2573 2575 self.pop_leftover_items(); 2574 2576 if !self.position.is_empty() { 2575 - pretty_printing_error!(self, "new top level form"); 2577 + invalid_code_for_position!(self, "top level form"); 2576 2578 } 2577 2579 } 2578 2580 ··· 2587 2589 fn new_expression(&mut self) { 2588 2590 self.pop_leftover_items(); 2589 2591 let Some(position) = self.position.last_mut() else { 2590 - pretty_printing_error!(self, "new expression"); 2592 + invalid_code_for_position!(self, "expression"); 2591 2593 }; 2592 2594 2593 2595 match position { ··· 2796 2798 | PrettyEafPosition::List { 2797 2799 kind: ListKind::Pattern, 2798 2800 .. 2799 - } => pretty_printing_error!(self, "new expression"), 2801 + } => invalid_code_for_position!(self, "expression"), 2800 2802 } 2801 2803 } 2802 2804 ··· 2811 2813 fn new_type(&mut self) { 2812 2814 self.pop_leftover_items(); 2813 2815 let Some(position) = self.position.last_mut() else { 2814 - pretty_printing_error!(self, "new type"); 2816 + invalid_code_for_position!(self, "type"); 2815 2817 }; 2816 2818 2817 2819 match position { ··· 2883 2885 } 2884 2886 | PrettyEafPosition::MatchPattern { .. } 2885 2887 | PrettyEafPosition::TuplePattern { .. } => { 2886 - pretty_printing_error!(self, "new type") 2888 + invalid_code_for_position!(self, "type") 2887 2889 } 2888 2890 } 2889 2891 } ··· 2899 2901 fn new_pattern(&mut self) { 2900 2902 self.pop_leftover_items(); 2901 2903 let Some(position) = self.position.last_mut() else { 2902 - pretty_printing_error!(self, "new pattern"); 2904 + invalid_code_for_position!(self, "pattern"); 2903 2905 }; 2904 2906 2905 2907 match position { ··· 3012 3014 | PrettyEafPosition::CaseClause { 3013 3015 expected: ExpectedCaseClauseItem::Body { .. }, 3014 3016 } => { 3015 - pretty_printing_error!(self, "new pattern"); 3017 + invalid_code_for_position!(self, "pattern"); 3016 3018 } 3017 3019 } 3018 3020 } ··· 3178 3180 // generated, then that's an error! 3179 3181 expected: ExpectedCallItem::FunctionToBeCalled, 3180 3182 .. 3181 - } => pretty_printing_error!(self, "pop leftover item"), 3183 + } => invalid_code_for_position!(self, "pop leftover item"), 3182 3184 } 3183 3185 } 3184 3186 ··· 3224 3226 | PrettyEafPosition::UnionType { .. } 3225 3227 | PrettyEafPosition::RecordAttribute { .. } 3226 3228 | PrettyEafPosition::TupleType { .. } => { 3227 - pretty_printing_error!(self, "escaping string") 3229 + invalid_code_for_position!(self, "escaping string") 3228 3230 } 3229 3231 3230 3232 PrettyEafPosition::FunctionCall { .. } ··· 3283 3285 fn new_bit_array_segment(&mut self) -> BitArrayKind { 3284 3286 self.pop_leftover_items(); 3285 3287 let Some(PrettyEafPosition::BitArray { first, kind }) = self.position.last_mut() else { 3286 - pretty_printing_error!(self, "bit array segment") 3288 + invalid_code_for_position!(self, "bit array segment") 3287 3289 }; 3288 3290 3289 3291 if *first { ··· 3301 3303 expected: ExpectedCaseItem::Branches { first }, 3302 3304 }) = self.position.last_mut() 3303 3305 else { 3304 - pretty_printing_error!(self, "case clause") 3306 + invalid_code_for_position!(self, "case clause") 3305 3307 }; 3306 3308 3307 3309 if *first { ··· 3317 3319 fn new_map_field(&mut self) { 3318 3320 self.pop_leftover_items(); 3319 3321 let Some(PrettyEafPosition::Map { first }) = self.position.last_mut() else { 3320 - pretty_printing_error!(self, "map field"); 3322 + invalid_code_for_position!(self, "map field"); 3321 3323 }; 3322 3324 3323 3325 if *first { ··· 3583 3585 self.code.push_str(&" ".repeat(self.indentation)); 3584 3586 } 3585 3587 3586 - fn pretty_error_message(&self, expected: &str) -> String { 3588 + /// This produces a pretty printed error message including the current 3589 + /// position. 3590 + fn error_with_position(&self, expected: &str) -> String { 3587 3591 let position = self.position.last(); 3588 3592 format!("tried {expected}, position: {position:?}") 3589 3593 }