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

Macros #59

Open
VincentRPS opened this issue Nov 15, 2024 · 1 comment
Open

Macros #59

VincentRPS opened this issue Nov 15, 2024 · 1 comment
Milestone

Comments

@VincentRPS
Copy link
Contributor

Add support for syntactic macros. These are almost like functions which intake syntax
and output different syntax during compilation. Macros should be a front-middle end process
and shouldn't involve the backend with anything other than codegen.

@VincentRPS VincentRPS added this to the 0.1 milestone Nov 15, 2024
@elenakrittik
Copy link
Contributor

elenakrittik commented Nov 15, 2024

We need to decide whether supporting macros-by-example is worth it. Given the tooling/support level we are aiming to provide to procedural macros, it may be better to implement support for easily making MBE-style macros inside procedural macros. For example, instead of writing

macro print_many($($arg:expr),*) {
	$(
		print($arg);
	),*
}

One could instead write something like

import std::syntax::{Syntax, syntax, lexer::Delimiter, parser::{parse_delimited, parse_expr}};

macro print_many(syntax: Syntax) -> Syntax {
	parse_delimited(Delimiter::Comma, parse_expr)
		.map((expr) => syntax! { print($expr); })
		.collect()
}

(Syntax is something akin to TokenStream in Rust, and syntax! is very similar to the quote macro of the quote Rust crate)

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