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

Attempt to subtract with overflow #16

Closed
andrewbaxter opened this issue Oct 12, 2024 · 6 comments
Closed

Attempt to subtract with overflow #16

andrewbaxter opened this issue Oct 12, 2024 · 6 comments
Labels
bug Something isn't working critical Critical bug that should be fixed ASAP

Comments

@andrewbaxter
Copy link

andrewbaxter commented Oct 12, 2024

Describe the bug
The code panics at

                    .split_off(self.res_stack.len() - 3usize)

from the generated code:

            ProdKind::InlineElStrong => {
                let mut i = self
                    .res_stack
                    .split_off(self.res_stack.len() - 3usize)
                    .into_iter();
                match (i.next().unwrap(), i.next().unwrap(), i.next().unwrap()) {
                    (
                        Symbol::NonTerminal(NonTerminal::StrongDelim(p0)),
                        Symbol::NonTerminal(NonTerminal::Inline(p1)),
                        Symbol::NonTerminal(NonTerminal::StrongDelimOpt(p2)),
                    ) => {
                        NonTerminal::InlineEl(
                            inline_actions::inline_el_strong(&*context, p0, p1, p2),
                        )
                    }
                    _ => panic!("Invalid symbol parse stack data."),
                }
            }

It's possible that this is a grammar issue, but it's not clear what happened from info in the panic itself.

Here's the grammar:

Inline: InlineEl*;
InlineEl: prefix=StrongDelim children=Inline suffix=StrongDelim? {Strong, 11, left}
        | prefix=EmphasisDelim children=Inline suffix=EmphasisDelim? {Emphasis, 11, left} 
        | title_prefix=LinkTitlePrefix title=Inline continuation=Link1? {Link , 11, left}
        | prefix=CodeDelim text=CodeChar* suffix=CodeDelim? {Code, 11, left} 
        | text=TextChar+ {Text, 9, left};

StrongDelim: StrongT;

EmphasisDelim: EmphasisT;

LinkTitlePrefix: LinkTitlePrefixT;
LinkTitleSuffix: LinkTitleSuffixT;
LinkAddressPrefix: LinkAddressPrefixT;
LinkAddressSuffix: LinkAddressSuffixT;
Link1: title_suffix=LinkTitleSuffix address=LinkAddress?;
LinkAddress: prefix=LinkAddressPrefix address=LinkAddressChar* suffix=LinkAddressSuffix?;
LinkAddressChar: LinkAddressCharT | EscapedChar;

CodeDelim: CodeDelimT;
CodeChar: CodeCharT | EscapedChar;

TextChar: TextCharT | EscapedChar;

EscapeChar: EscapeT;
EscapedChar: prefix=EscapeChar text=AnyCharT;

Layout: Empty;

terminals
Empty: "";
EscapeT: "\\";
AnyCharT: /./;
TextCharT: /[^*_`\\]/;
CodeDelimT: "`";
CodeCharT: /[^`\\]/;
LinkTitlePrefixT: "[";
LinkTitleSuffixT: "](";
LinkAddressPrefixT: "(";
LinkAddressSuffixT: ")";
LinkAddressCharT: /[^)\\]/;
StrongT: "*";
EmphasisT: "_";

So foremost this is a bug about error messages.

@andrewbaxter andrewbaxter added the bug Something isn't working label Oct 12, 2024
@igordejanovic
Copy link
Owner

Thanks for the report. I don't think it could be a grammar issue. It smells to me like a bug in code gen. Could you make a PR with a failing regression test? Probably the best place to put it is in the tests crate. Something like src/regressions/issue_16_subtract_overflow_panic.

@andrewbaxter
Copy link
Author

andrewbaxter commented Oct 14, 2024

Oh sure! Sorry, it may take me a couple days. Thanks for the pointers for making the test.

Although TBH I'm not confident I have the exact text that caused the issue on hand... I'll see if I can reproduce it. I should have included the text too.

@igordejanovic
Copy link
Owner

Thanks much for the PR! No problem at all for the delays. I'm also sometimes very slow in responses depending on other tasks I have so no worries.

@igordejanovic igordejanovic added the critical Critical bug that should be fixed ASAP label Oct 24, 2024
@igordejanovic
Copy link
Owner

I figured out what the problem is but it requires a bit of work. Only default builder for GLR is affected. Thus, the workaround until I fix the issue is to either use generic builder or LR parsing.

@igordejanovic
Copy link
Owner

@andrewbaxter I've finished rework of the generator. This issue is resolved. Thanks again for the regression test. I'll make a bugfix release in the following days.

@andrewbaxter
Copy link
Author

Awesome, thanks! 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working critical Critical bug that should be fixed ASAP
Projects
None yet
Development

No branches or pull requests

2 participants