top | item 41536810

(no title)

quasigloam | 1 year ago

Yes, at the moment I just assume that all atoms are rust idents because that makes it easier to implement (I can just match against $x:ident), so it doesn't support dashes in atoms. I guess you could match against `$x:ident $(- $y:ident)*` instead? That should work I think, I'd have to change some details in some of the arms but it seems like that would be possible.

discuss

order

throwup238|1 year ago

Wouldn’t that match “(foo - bar)” as well as “(foo-bar)”? I don’t think you can get around token whitespace in macro_rules

quasigloam|1 year ago

Yes it would match both, this would require us to assume that "foo - bar" can only be an atom. It's not a great solution.

celeritascelery|1 year ago

It would, but lisp has prefix operators, so you wouldn’t have to worry about it getting confused.

anothername12|1 year ago

Does Rust have something like a reader macro where you can have arbitrary syntax for a bit?

throwup238|1 year ago

It's almost but not quite arbitrary. It still has to be a valid Rust token stream with matching braces/parens. Since it's whitespace insensitive with respect to tokens and "-" is its own token, "(foo-bar)" and "(foo - bar)" result in the same token stream minus the span information.

You can use proc_macro::Span.line()/column() [1] to track how much whitespace there is between tokens and merge them, but the macro will have to rename them to valid Rust identities ("foo-bar" to "foo_bar") and make sure there's no collisions.

[1] https://doc.rust-lang.org/proc_macro/struct.Span.html#method...