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

Better macro support #136

Merged
merged 5 commits into from
Oct 5, 2020
Merged

Better macro support #136

merged 5 commits into from
Oct 5, 2020

Conversation

udoprog
Copy link
Collaborator

@udoprog udoprog commented Oct 5, 2020

This reworks the Query system so that it can be passed around statically, and adds support for performing constant evaluation in macros. That means that the following (or any constantly evaled expressions) will work without issues:

const FORMAT_STRING = build_format_string("Hello");

const fn build_format_string(prefix) {
    `{prefix} \{\}`
}

fn main() {
    println!(FORMAT_STRING, "World"); // -> will produce "Hello World"
}

Note that the current state of the println! macro is still only a skeleton, i.e. arg parsing hasn't been implemented yet. But right now it can receive a constant value as the first argument.

I've also reworked template strings so that they solely are lexer sugaring over a different kind of expression which uses a new reserved keyword template. That means that this:

`Hello {world}`

Desugars to this during lexing:

template { "Hello ", world }

This makes it vastly easier to work with template string in macros, since the desugared version uses syntax which works well with Rust and the quote! macro.

@udoprog udoprog added the enhancement New feature or request label Oct 5, 2020
@udoprog udoprog force-pushed the better-macro-support branch from 6dd6f6b to 709e98d Compare October 5, 2020 18:00
@udoprog udoprog merged commit 8b1ac98 into master Oct 5, 2020
@udoprog udoprog deleted the better-macro-support branch October 5, 2020 18:01
@udoprog udoprog added the changelog Issue has been added to the changelog label Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog Issue has been added to the changelog enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant