Skip to content

Looking proc_macro2 source as guidence for implementing ParseSlice on custom token type. #321

Answered by kevinmehall
devdave asked this question in Q&A
Discussion options

You must be logged in to vote

peg_macros/tokens.rs is a little complicated because it's translating between the tree-structured tokens that rustc uses and a flat array of tokens that rust-peg expects. TokenStream is the Rust compiler's token implementation used in procedural macros. proc-macro2 is the top of several abstraction layers over the implementation in the Rust compiler internals, but it comes with a fallback implementation that might be easier to understand if you're curious how it works. However you don't need any of that to use rust-peg unless you're trying to use it to implement a procedural Rust macro.

It looks like you have a Vec<Rc<Token>>, so the better example to look at would be the implementation for

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@devdave
Comment options

Answer selected by devdave
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants