Skip to content

Commit

Permalink
fix debug_assert bug
Browse files Browse the repository at this point in the history
  • Loading branch information
skius committed Aug 9, 2023
1 parent 1f5c8dd commit d1f7e7c
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions experimental/transliterator_parser/src/compile/pass2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use crate::compile::rule_group_agg::UniConversionRule;
use icu_transliteration::provider as ds;

macro_rules! impl_insert {
($fn_name:ident, $field:ident, $elt_type:ty, $next_field:ident) => {
($fn_name:ident, $field:ident, $elt_type:ty, $($next_field:tt)*) => {
fn $fn_name(&mut self, elt: $elt_type) -> char {
// pass 1 is responsible for this
debug_assert!(self.$field.current < self.$next_field.base - 1);
debug_assert!(self.$field.current < self.$($next_field)*);
#[allow(clippy::unwrap_used)] // the whole PUP (15) consists of valid chars
let standin = char::try_from(self.$field.current).unwrap();
self.$field.vec.push(elt);
Expand Down Expand Up @@ -107,36 +107,38 @@ impl MutVarTable {
})
}

impl_insert!(insert_compound, compounds, String, quantifiers_opt);
impl_insert!(insert_compound, compounds, String, quantifiers_opt.base);
impl_insert!(
insert_quantifier_opt,
quantifiers_opt,
String,
quantifiers_kleene
quantifiers_kleene.base
);
impl_insert!(
insert_quantifier_kleene,
quantifiers_kleene,
String,
quantifiers_kleene_plus
quantifiers_kleene_plus.base
);
impl_insert!(
insert_quantifier_kleene_plus,
quantifiers_kleene_plus,
String,
segments
segments.base
);
impl_insert!(insert_segment, segments, String, unicode_sets.base);
impl_insert!(
insert_unicode_set,
unicode_sets,
UnicodeSet,
function_calls.base
);
impl_insert!(
insert_function_call,
function_calls,
ds::FunctionCall<'static>,
backref_base
);
impl_insert!(insert_segment, segments, String, unicode_sets);
impl_insert!(insert_unicode_set, unicode_sets, UnicodeSet, function_calls);
fn insert_function_call(&mut self, elt: ds::FunctionCall<'static>) -> char {
// pass 1 is responsible for this
debug_assert!(self.function_calls.current < self.backref_base - 1);
#[allow(clippy::unwrap_used)] // the whole PUP (15) consists of valid chars
let standin = char::try_from(self.function_calls.current).unwrap();
self.function_calls.vec.push(elt);
self.function_calls.current += 1;
standin
}

fn standin_for_backref(&self, backref_num: u32) -> char {
debug_assert!(backref_num > 0);
Expand Down

0 comments on commit d1f7e7c

Please sign in to comment.