Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix handling of very long sequences/choices #20

Merged
merged 1 commit into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/src/choice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ macro_rules! choice_type {
};
}

pub use choice_type;

choice_type! {
Choice2,
(Choice0, T0, choice_0),
Expand Down
2 changes: 2 additions & 0 deletions core/src/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ macro_rules! sequence_type {
};
}

pub use sequence_type;

sequence_type! {
Sequence2,
(field_0, T0, TR0),
Expand Down
7 changes: 6 additions & 1 deletion derive/tests/grammar.pest
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ pop_ = pest::stack::push(range) - pest::stack::push(range) - pest::stack::pop -
pop_all = pest::stack::push(range) - pest::stack::push(range) - pest::stack::pop_all
pop_fail = pest::stack::push(range) - !pest::stack::pop - range - pest::stack::pop
checkpoint_restore = pest::stack::push("") - (pest::stack::push("a") - "b" - pest::stack::pop | pest::stack::drop - "b" | pest::stack::pop - "a") - pest::EOI

longchoice_builtin = ( "01" | "02" | "03" | "04" | "05" | "06" | "07" | "08" | "09" | "10" | "11" | "12" | "13" | "14" | "15" | "16")
longseq_builtin = ( "01" ~ "02" ~ "03" ~ "04" ~ "05" ~ "06" ~ "07" ~ "08" ~ "09" ~ "10" ~ "11" ~ "12" ~ "13" ~ "14" ~ "15" ~ "16")
longchoice_critical = ( "01" | "02" | "03" | "04" | "05" | "06" | "07" | "08" | "09" | "10" | "11" | "12" | "13" | "14" | "15" | "16" | "17")
longseq_critical = ( "01" ~ "02" ~ "03" ~ "04" ~ "05" ~ "06" ~ "07" ~ "08" ~ "09" ~ "10" ~ "11" ~ "12" ~ "13" ~ "14" ~ "15" ~ "16" ~ "17")
longchoice_jump = ( "01" | "02" | "03" | "04" | "05" | "06" | "07" | "08" | "09" | "10" | "11" | "12" | "13" | "14" | "15" | "16" | "17" | "18" | "19")
longseq_jump = ( "01" ~ "02" ~ "03" ~ "04" ~ "05" ~ "06" ~ "07" ~ "08" ~ "09" ~ "10" ~ "11" ~ "12" ~ "13" ~ "14" ~ "15" ~ "16" ~ "17" ~ "18" ~ "19")
/*
ascii_digits = ASCII_DIGIT+
ascii_nonzero_digits = ASCII_NONZERO_DIGIT+
Expand Down
32 changes: 17 additions & 15 deletions generator/src/typed/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,25 @@ impl<'g> Tracker<'g> {
seq: bool| {
for len in set.iter().cloned() {
let generics_i = format_ident!("{}{}", prefix, len);
let (types, field): (Vec<_>, Vec<_>) = (0..len)
.map(|i| {
let field = if seq {
let i = Index::from(i);
let i = format_ident!("field_{}", i);
quote! {#i}
} else {
let i = format_ident!("Choice{}", i);
quote! {#i}
};
(format_ident!("T{}", i), field)
})
.unzip();
let branch = (0..len).map(|i| {
if seq {
format_ident!("field_{}", i)
} else {
format_ident!("Choice{}", i)
}
});
let the_type = (0..len).map(|i| format_ident!("T{}", i));
let trivia_or_getter = (0..len).map(|i| {
if seq {
format_ident!("TR{}", i)
} else {
format_ident!("choice_{}", i)
}
});
// `pest` is already imported, so can be referred directly.
if len >= 16 {
if len > 16 {
target.push(quote! {
#pest::#mac!(#generics_i, #(#types, #field, )*);
#pest::#module::#mac!(#generics_i, #((#branch, #the_type, #trivia_or_getter),)*);
});
} else {
target.push(quote! {
Expand Down