1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! The keyword table: the one list every keyword-shaped table is generated from.
//!
//! Julia's reserved words are needed in several shapes — as text (completion),
//! as a text -> [`TokKind`](crate::parser) classifier, as a predicate over
//! `TokKind`, and as a predicate over [`SyntaxKind`](crate::syntax::SyntaxKind).
//! Writing the set out once per shape is how they drift.
//!
//! Instead, each site defines a generator macro and expands [`keyword_table`]
//! with it: the table below is handed to the generator as rows of
//! `"text" TokKindVariant SYNTAX_KIND_VARIANT,`, and the generator emits
//! whatever shape it needs (ignoring the columns it does not use). Adding a
//! keyword is one row here; every shape follows. Keywords are tokens too, so
//! the rows are also spliced into the crate-wide token table
//! ([`crate::tokens::token_table`]), which is where the enum variants and the
//! `TokKind` -> `SyntaxKind` materialization come from.
//!
//! The callback indirection is what lets the table live at the crate root: it
//! passes bare tokens, so it never has to name `TokKind` (private to the
//! `parser` module tree) or `SyntaxKind` itself.
/// Expand `$callback` with the keyword table.
///
/// `$callback` must be a macro accepting rows of
/// `"text" TokKindVariant SYNTAX_KIND_VARIANT,` and must already be in scope
/// (`macro_rules!` macros are textually scoped, so define it just above the
/// call).
///
/// The bracketed form, `keyword_table!([$path::to::callback] $extra...)`, names
/// the callback by path (so it need not be in scope at the call site) and passes
/// `$extra` through ahead of the rows. That is how [`token_table`] splices the
/// keyword rows into the larger token table: it hands *its* callback along as
/// the extra tokens.
///
/// [`token_table`]: crate::tokens::token_table
pub use keyword_table;