aboutsummaryrefslogtreecommitdiff
path: root/crates/mbe/src/parser.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/mbe/src/parser.rs')
-rw-r--r--crates/mbe/src/parser.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/crates/mbe/src/parser.rs b/crates/mbe/src/parser.rs
index 2f3ebc831..f3047972d 100644
--- a/crates/mbe/src/parser.rs
+++ b/crates/mbe/src/parser.rs
@@ -8,7 +8,7 @@ use crate::{tt_iter::TtIter, ExpandError, MetaTemplate};
8 8
9#[derive(Clone, Debug, PartialEq, Eq)] 9#[derive(Clone, Debug, PartialEq, Eq)]
10pub(crate) enum Op { 10pub(crate) enum Op {
11 Var { name: SmolStr, kind: Option<SmolStr> }, 11 Var { name: SmolStr, kind: Option<SmolStr>, id: tt::TokenId },
12 Repeat { subtree: MetaTemplate, kind: RepeatKind, separator: Option<Separator> }, 12 Repeat { subtree: MetaTemplate, kind: RepeatKind, separator: Option<Separator> },
13 Leaf(tt::Leaf), 13 Leaf(tt::Leaf),
14 Subtree(MetaTemplate), 14 Subtree(MetaTemplate),
@@ -106,18 +106,25 @@ fn next_op<'a>(first: &tt::TokenTree, src: &mut TtIter<'a>, mode: Mode) -> Resul
106 } 106 }
107 let name = UNDERSCORE.clone(); 107 let name = UNDERSCORE.clone();
108 let kind = eat_fragment_kind(src, mode)?; 108 let kind = eat_fragment_kind(src, mode)?;
109 Op::Var { name, kind } 109 let id = punct.id;
110 Op::Var { name, kind, id }
111 }
112 tt::Leaf::Ident(ident) if ident.text == "crate" => {
113 // We simply produce identifier `$crate` here. And it will be resolved when lowering ast to Path.
114 Op::Leaf(tt::Leaf::from(tt::Ident { text: "$crate".into(), id: ident.id }))
110 } 115 }
111 tt::Leaf::Ident(ident) => { 116 tt::Leaf::Ident(ident) => {
112 let name = ident.text.clone(); 117 let name = ident.text.clone();
113 let kind = eat_fragment_kind(src, mode)?; 118 let kind = eat_fragment_kind(src, mode)?;
114 Op::Var { name, kind } 119 let id = ident.id;
120 Op::Var { name, kind, id }
115 } 121 }
116 tt::Leaf::Literal(lit) => { 122 tt::Leaf::Literal(lit) => {
117 if is_boolean_literal(&lit) { 123 if is_boolean_literal(&lit) {
118 let name = lit.text.clone(); 124 let name = lit.text.clone();
119 let kind = eat_fragment_kind(src, mode)?; 125 let kind = eat_fragment_kind(src, mode)?;
120 Op::Var { name, kind } 126 let id = lit.id;
127 Op::Var { name, kind, id }
121 } else { 128 } else {
122 bail!("bad var 2"); 129 bail!("bad var 2");
123 } 130 }