Skip to content

Instantly share code, notes, and snippets.

@H2CO3
Created October 11, 2015 17:31
Show Gist options
  • Save H2CO3/8d8001b30d72d74e6300 to your computer and use it in GitHub Desktop.
Save H2CO3/8d8001b30d72d74e6300 to your computer and use it in GitHub Desktop.
// takes no arguments, and returns a StringLiteral AST node containing the current date formatted as a string
macro CompilationDateAsString() -> std::ASTNode * {
// imagine that we already have date/time support in our standard library
let cur_date = new std::Date();
return std::StringLiteralAST(cur_date.to_string());
}
// So, the following main() function:
fn main() {
print(@CompilationDateAsString());
}
// will be expanded to this:
fn main() {
print("11/10/2015");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment