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

Capture both details and full input #377

Closed
chrysn opened this issue Jun 10, 2024 · 1 comment
Closed

Capture both details and full input #377

chrysn opened this issue Jun 10, 2024 · 1 comment

Comments

@chrysn
Copy link

chrysn commented Jun 10, 2024

For an aspect of parsing CBOR with the peg crate, I find myself in need to capture in a single rule both details and the full input, because the parser output gets post-processed differently. In a simplified example:

    pub rule basenumber() -> NumberParts<'input>
        = sign:sign()? "0" parts:(
                            / ['x'|'X'] "." postdot:$(HEXDIG()+) ['p'|'P'] expsign:sign()? exp:$(DIGIT()+)
                              { (16, "", Some(postdot), expsign, Some(exp)) }
                            / ['o'|'O'] predot:$(ODIGIT()+)
                              { (8, predot, None, None, None) }
                            / /.../
            )
        {
            let (base, predot, postdot, expsign, exp) = parts;
            NumberParts {
                base,
                sign,
                /.../,
                // would like to have the full input here as well
            }
        }

It would be convenient to write

        = full:$(sign:sign()? "0" parts:( /.../ )) {
            NumberParts {
                base,
                sign,
                /.../,
                full,
            }
        }

but then I can only get access to the full result and not to sign any more.

Is there an existing trick I'm missing, or could this be made available in a compatible way, eg. by providing a part's inner variables transparently by declaring them in the generated code, such that they might be shadowed by the outer assignments?

@kevinmehall
Copy link
Owner

Duplicate of #283, which has a workaround in the comments.

@kevinmehall kevinmehall closed this as not planned Won't fix, can't repro, duplicate, stale Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants