diff options
Diffstat (limited to 'crates/libsyntax2/src')
-rw-r--r-- | crates/libsyntax2/src/ast/generated.rs | 27 | ||||
-rw-r--r-- | crates/libsyntax2/src/grammar.ron | 9 |
2 files changed, 34 insertions, 2 deletions
diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs index 80670ce71..1ec05c950 100644 --- a/crates/libsyntax2/src/ast/generated.rs +++ b/crates/libsyntax2/src/ast/generated.rs | |||
@@ -249,6 +249,25 @@ impl<R: TreeRoot> AstNode<R> for NameRef<R> { | |||
249 | 249 | ||
250 | impl<R: TreeRoot> NameRef<R> {} | 250 | impl<R: TreeRoot> NameRef<R> {} |
251 | 251 | ||
252 | // NamedField | ||
253 | #[derive(Debug, Clone, Copy)] | ||
254 | pub struct NamedField<R: TreeRoot = Arc<SyntaxRoot>> { | ||
255 | syntax: SyntaxNode<R>, | ||
256 | } | ||
257 | |||
258 | impl<R: TreeRoot> AstNode<R> for NamedField<R> { | ||
259 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | ||
260 | match syntax.kind() { | ||
261 | NAMED_FIELD => Some(NamedField { syntax }), | ||
262 | _ => None, | ||
263 | } | ||
264 | } | ||
265 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | ||
266 | } | ||
267 | |||
268 | impl<R: TreeRoot> ast::NameOwner<R> for NamedField<R> {} | ||
269 | impl<R: TreeRoot> NamedField<R> {} | ||
270 | |||
252 | // NeverType | 271 | // NeverType |
253 | #[derive(Debug, Clone, Copy)] | 272 | #[derive(Debug, Clone, Copy)] |
254 | pub struct NeverType<R: TreeRoot = Arc<SyntaxRoot>> { | 273 | pub struct NeverType<R: TreeRoot = Arc<SyntaxRoot>> { |
@@ -436,7 +455,13 @@ impl<R: TreeRoot> AstNode<R> for StructDef<R> { | |||
436 | } | 455 | } |
437 | 456 | ||
438 | impl<R: TreeRoot> ast::NameOwner<R> for StructDef<R> {} | 457 | impl<R: TreeRoot> ast::NameOwner<R> for StructDef<R> {} |
439 | impl<R: TreeRoot> StructDef<R> {} | 458 | impl<R: TreeRoot> StructDef<R> { |
459 | pub fn fields<'a>(&'a self) -> impl Iterator<Item = NamedField<R>> + 'a { | ||
460 | self.syntax() | ||
461 | .children() | ||
462 | .filter_map(NamedField::cast) | ||
463 | } | ||
464 | } | ||
440 | 465 | ||
441 | // TraitDef | 466 | // TraitDef |
442 | #[derive(Debug, Clone, Copy)] | 467 | #[derive(Debug, Clone, Copy)] |
diff --git a/crates/libsyntax2/src/grammar.ron b/crates/libsyntax2/src/grammar.ron index 3ae403bb5..aa28ab922 100644 --- a/crates/libsyntax2/src/grammar.ron +++ b/crates/libsyntax2/src/grammar.ron | |||
@@ -222,7 +222,13 @@ Grammar( | |||
222 | ] | 222 | ] |
223 | ), | 223 | ), |
224 | "FnDef": ( traits: ["NameOwner"] ), | 224 | "FnDef": ( traits: ["NameOwner"] ), |
225 | "StructDef": ( traits: ["NameOwner"] ), | 225 | "StructDef": ( |
226 | traits: ["NameOwner"], | ||
227 | collections: [ | ||
228 | ["fields", "NamedField"] | ||
229 | ] | ||
230 | ), | ||
231 | "NamedField": ( traits: ["NameOwner"] ), | ||
226 | "EnumDef": ( traits: ["NameOwner"] ), | 232 | "EnumDef": ( traits: ["NameOwner"] ), |
227 | "TraitDef": ( traits: ["NameOwner"] ), | 233 | "TraitDef": ( traits: ["NameOwner"] ), |
228 | "Module": ( traits: ["NameOwner"] ), | 234 | "Module": ( traits: ["NameOwner"] ), |
@@ -230,6 +236,7 @@ Grammar( | |||
230 | "StaticDef": ( traits: ["NameOwner"] ), | 236 | "StaticDef": ( traits: ["NameOwner"] ), |
231 | "TypeDef": ( traits: ["NameOwner"] ), | 237 | "TypeDef": ( traits: ["NameOwner"] ), |
232 | "ImplItem": (), | 238 | "ImplItem": (), |
239 | |||
233 | "Name": (), | 240 | "Name": (), |
234 | "NameRef": (), | 241 | "NameRef": (), |
235 | 242 | ||