mirror of https://github.com/Wilfred/difftastic/
185 lines
4.0 KiB
Plaintext
185 lines
4.0 KiB
Plaintext
============================================
|
|
Macro invocation - no arguments
|
|
============================================
|
|
|
|
a!();
|
|
b![];
|
|
c!{};
|
|
d::e!();
|
|
f::g::h!{};
|
|
|
|
---
|
|
|
|
(source_file
|
|
(macro_invocation (identifier) (token_tree))
|
|
(macro_invocation (identifier) (token_tree))
|
|
(macro_invocation (identifier) (token_tree))
|
|
(macro_invocation (scoped_identifier (identifier) (identifier)) (token_tree))
|
|
(macro_invocation (scoped_identifier (scoped_identifier (identifier) (identifier)) (identifier)) (token_tree)))
|
|
|
|
============================================
|
|
Macro invocation - arbitrary tokens
|
|
============================================
|
|
|
|
a!(* a *);
|
|
a!(& a &);
|
|
a!(- a -);
|
|
a!(b + c + +);
|
|
a!('a'..='z');
|
|
a!('\u{0}'..='\u{2}');
|
|
a!('lifetime)
|
|
default!(a);
|
|
union!(a);
|
|
|
|
----
|
|
|
|
(source_file
|
|
(macro_invocation
|
|
(identifier)
|
|
(token_tree (identifier)))
|
|
(macro_invocation
|
|
(identifier)
|
|
(token_tree (identifier)))
|
|
(macro_invocation
|
|
(identifier)
|
|
(token_tree (identifier)))
|
|
(macro_invocation
|
|
(identifier)
|
|
(token_tree (identifier) (identifier)))
|
|
(macro_invocation
|
|
(identifier)
|
|
(token_tree (char_literal) (char_literal)))
|
|
(macro_invocation
|
|
(identifier)
|
|
(token_tree (char_literal) (char_literal)))
|
|
(macro_invocation
|
|
(identifier)
|
|
(token_tree (identifier)))
|
|
(macro_invocation
|
|
(identifier)
|
|
(token_tree (identifier)))
|
|
(macro_invocation
|
|
(identifier)
|
|
(token_tree (identifier))))
|
|
|
|
=====================================
|
|
Macro invocation with comments
|
|
=====================================
|
|
|
|
ok! {
|
|
// one
|
|
/* two */
|
|
}
|
|
|
|
---
|
|
|
|
(source_file
|
|
(macro_invocation
|
|
(identifier)
|
|
(token_tree (line_comment) (block_comment))))
|
|
|
|
============================================
|
|
Macro definition
|
|
============================================
|
|
|
|
macro_rules! say_hello {
|
|
() => (
|
|
println!("Hello!");
|
|
)
|
|
}
|
|
|
|
macro_rules! four {
|
|
() => {1 + 3};
|
|
}
|
|
|
|
macro_rules! foo {
|
|
(x => $e:expr) => (println!("mode X: {}", $e));
|
|
(y => $e:expr) => (println!("mode Y: {}", $e))
|
|
}
|
|
|
|
macro_rules! o_O {
|
|
(
|
|
$($x:expr; [ $( $y:expr ),* ]);*
|
|
) => {
|
|
$($($x + $e),*),*
|
|
}
|
|
}
|
|
|
|
macro_rules! zero_or_one {
|
|
($($e:expr),?) => {
|
|
$($e),?
|
|
};
|
|
}
|
|
|
|
----
|
|
|
|
(source_file
|
|
(macro_definition
|
|
name: (identifier)
|
|
(macro_rule
|
|
left: (token_tree_pattern)
|
|
right: (token_tree
|
|
(identifier)
|
|
(token_tree
|
|
(string_literal)))))
|
|
(macro_definition
|
|
name: (identifier)
|
|
(macro_rule
|
|
left: (token_tree_pattern)
|
|
right: (token_tree
|
|
(integer_literal)
|
|
(integer_literal))))
|
|
(macro_definition
|
|
name: (identifier)
|
|
(macro_rule
|
|
left: (token_tree_pattern
|
|
(identifier)
|
|
(token_binding_pattern
|
|
name: (metavariable)
|
|
type: (fragment_specifier)))
|
|
right: (token_tree
|
|
(identifier)
|
|
(token_tree
|
|
(string_literal)
|
|
(metavariable))))
|
|
(macro_rule
|
|
left: (token_tree_pattern
|
|
(identifier)
|
|
(token_binding_pattern
|
|
name: (metavariable)
|
|
type: (fragment_specifier)))
|
|
right: (token_tree
|
|
(identifier)
|
|
(token_tree
|
|
(string_literal)
|
|
(metavariable)))))
|
|
(macro_definition
|
|
name: (identifier)
|
|
(macro_rule
|
|
left: (token_tree_pattern
|
|
(token_repetition_pattern
|
|
(token_binding_pattern
|
|
name: (metavariable)
|
|
type: (fragment_specifier))
|
|
(token_tree_pattern
|
|
(token_repetition_pattern
|
|
(token_binding_pattern
|
|
name: (metavariable)
|
|
type: (fragment_specifier))))))
|
|
right: (token_tree
|
|
(token_repetition
|
|
(token_repetition
|
|
(metavariable)
|
|
(metavariable))))))
|
|
(macro_definition
|
|
name: (identifier)
|
|
(macro_rule
|
|
left: (token_tree_pattern
|
|
(token_repetition_pattern
|
|
(token_binding_pattern
|
|
name: (metavariable)
|
|
type: (fragment_specifier))))
|
|
right: (token_tree
|
|
(token_repetition
|
|
(metavariable))))))
|