8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
+ //! Used by plugin crates to tell `rustc` about the plugins they provide.
12
+
11
13
use syntax:: ext:: base:: { SyntaxExtension , NamedSyntaxExtension , NormalTT } ;
12
14
use syntax:: ext:: base:: { IdentTT , ItemDecorator , ItemModifier , BasicMacroExpander } ;
13
15
use syntax:: ext:: base:: { MacroExpanderFn } ;
14
16
use syntax:: codemap:: Span ;
15
17
use syntax:: parse:: token;
16
18
use syntax:: ast;
17
19
20
+ /// Structure used to register plugins.
21
+ ///
22
+ /// A plugin registrar function takes an `&mut Registry` and should call
23
+ /// methods to register its plugins.
24
+ ///
25
+ /// This struct has public fields and other methods for use by `rustc`
26
+ /// itself. They are not documented here, and plugin authors should
27
+ /// not use them.
18
28
pub struct Registry {
19
29
#[ doc( hidden) ]
20
30
pub krate_span : Span ,
@@ -23,9 +33,6 @@ pub struct Registry {
23
33
pub syntax_exts : Vec < NamedSyntaxExtension > ,
24
34
}
25
35
26
- pub type PluginRegistrarFun =
27
- fn ( & mut Registry ) ;
28
-
29
36
impl Registry {
30
37
#[ doc( hidden) ]
31
38
pub fn new ( krate : & ast:: Crate ) -> Registry {
@@ -35,6 +42,9 @@ impl Registry {
35
42
}
36
43
}
37
44
45
+ /// Register a syntax extension of any kind.
46
+ ///
47
+ /// This is the most general hook into `libsyntax`'s expansion behavior.
38
48
pub fn register_syntax_extension ( & mut self , name : ast:: Name , extension : SyntaxExtension ) {
39
49
self . syntax_exts . push ( ( name, match extension {
40
50
NormalTT ( ext, _) => NormalTT ( ext, Some ( self . krate_span ) ) ,
@@ -44,6 +54,11 @@ impl Registry {
44
54
} ) ) ;
45
55
}
46
56
57
+ /// Register a macro of the usual kind.
58
+ ///
59
+ /// This is a convenience wrapper for `register_syntax_extension`.
60
+ /// It builds for you a `NormalTT` with a `BasicMacroExpander`,
61
+ /// and also takes care of interning the macro's name.
47
62
pub fn register_macro ( & mut self , name : & str , expander : MacroExpanderFn ) {
48
63
self . register_syntax_extension (
49
64
token:: intern ( name) ,
0 commit comments