aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-14 12:45:56 +0100
committerAleksey Kladov <[email protected]>2018-08-14 12:45:56 +0100
commit199e3b73c712a74e36bbb75eebf9e9418f1b1341 (patch)
treec1d19ef695eedd9848eb9019a7c77c66f035a9bf /crates/libsyntax2
parent1141d448d960eedba0a5647d525910de706bf778 (diff)
fields are part of the structure
Diffstat (limited to 'crates/libsyntax2')
-rw-r--r--crates/libsyntax2/src/ast/generated.rs27
-rw-r--r--crates/libsyntax2/src/grammar.ron9
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
250impl<R: TreeRoot> NameRef<R> {} 250impl<R: TreeRoot> NameRef<R> {}
251 251
252// NamedField
253#[derive(Debug, Clone, Copy)]
254pub struct NamedField<R: TreeRoot = Arc<SyntaxRoot>> {
255 syntax: SyntaxNode<R>,
256}
257
258impl<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
268impl<R: TreeRoot> ast::NameOwner<R> for NamedField<R> {}
269impl<R: TreeRoot> NamedField<R> {}
270
252// NeverType 271// NeverType
253#[derive(Debug, Clone, Copy)] 272#[derive(Debug, Clone, Copy)]
254pub struct NeverType<R: TreeRoot = Arc<SyntaxRoot>> { 273pub struct NeverType<R: TreeRoot = Arc<SyntaxRoot>> {
@@ -436,7 +455,13 @@ impl<R: TreeRoot> AstNode<R> for StructDef<R> {
436} 455}
437 456
438impl<R: TreeRoot> ast::NameOwner<R> for StructDef<R> {} 457impl<R: TreeRoot> ast::NameOwner<R> for StructDef<R> {}
439impl<R: TreeRoot> StructDef<R> {} 458impl<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