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

Values parsed inside span #297

Closed
Kile-Asmussen opened this issue May 13, 2022 · 4 comments
Closed

Values parsed inside span #297

Kile-Asmussen opened this issue May 13, 2022 · 4 comments

Comments

@Kile-Asmussen
Copy link
Contributor

It would be really convenient to be able to do something like this:

rule with_span<T>(thing: rule<T>) -> (T, &'input str)
= span:$( val:thing() ) { (val, span) } ;

As it stands I've made this kludge:

rule with_span<T>(thing: rule<T>) -> (T, &'input str)
= span:&( $( thing() ) ) ) val:thing() { (val, span) } ;

Which apparently parses thing() twice.

@Mingun
Copy link

Mingun commented May 13, 2022

Probably it is better to return Spanned<T> from $(), where

struct Spanned<T> {
  pub value: T,
  pub span: Span,
}

@Kile-Asmussen
Copy link
Contributor Author

@Mingun Sure, but how?

@Mingun
Copy link

Mingun commented May 13, 2022

I mean, that currently rust-peg returns just Span in that case and it should be modified to return Spanned<T> (if I all understand correctly... I've not looked at the code).

@kevinmehall
Copy link
Owner

Duplicate of #283. There's a potential wokaround there, but I think it might be worth adding syntax for this.

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

3 participants