|
1 | 1 | use std::fmt::Display; |
2 | 2 |
|
| 3 | +#[derive(Debug, Clone, PartialEq, Eq, Hash)] |
| 4 | +pub enum Member { |
| 5 | + Literal(String), |
| 6 | + Ident(String), |
| 7 | +} |
| 8 | + |
| 9 | +impl Display for Member { |
| 10 | + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 11 | + match self { |
| 12 | + Self::Literal(lit) => f.write_str(&format!( |
| 13 | + r#""{}""#, |
| 14 | + lit.trim_start_matches('"').trim_end_matches('"') |
| 15 | + )), |
| 16 | + Self::Ident(ident) => f.write_str(ident), |
| 17 | + } |
| 18 | + } |
| 19 | +} |
| 20 | + |
3 | 21 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
4 | 22 | pub enum TagType { |
5 | 23 | /// ```lua |
@@ -63,9 +81,13 @@ pub enum TagType { |
63 | 81 | /// ``` |
64 | 82 | Alias(String, Option<Ty>), |
65 | 83 | /// ```lua |
66 | | - /// ---| '<value>' [# description] |
| 84 | + /// ---| '<literal>' [# description] |
| 85 | + /// |
| 86 | + /// -- or |
| 87 | + /// |
| 88 | + /// ---| `<ident>` [# description] |
67 | 89 | /// ``` |
68 | | - Variant(String, Option<String>), |
| 90 | + Variant(Member, Option<String>), |
69 | 91 | /// ```lua |
70 | 92 | /// ---@type <type> [desc] |
71 | 93 | /// ``` |
@@ -166,6 +188,7 @@ pub enum Ty { |
166 | 188 | Userdata, |
167 | 189 | Lightuserdata, |
168 | 190 | Ref(String), |
| 191 | + Member(Member), |
169 | 192 | Array(Box<Ty>), |
170 | 193 | Table(Option<(Box<Ty>, Box<Ty>)>), |
171 | 194 | Fun(Vec<(Name, Ty)>, Option<Vec<Ty>>), |
@@ -234,6 +257,7 @@ impl Display for Ty { |
234 | 257 | f.write_str("|")?; |
235 | 258 | f.write_str(&lhs.to_string()) |
236 | 259 | } |
| 260 | + Self::Member(mem) => mem.fmt(f), |
237 | 261 | } |
238 | 262 | } |
239 | 263 | } |
0 commit comments