github.com/Konstantin8105/c4go@v0.0.0-20240505174241-768bb1c65a51/ast/returns_twice_attr.go (about) 1 package ast 2 3 // ReturnsTwiceAttr is a type of attribute that is optionally attached to a variable 4 // or struct field definition. 5 type ReturnsTwiceAttr struct { 6 Addr Address 7 Pos Position 8 ChildNodes []Node 9 IsInherited bool 10 IsImplicit bool 11 } 12 13 func parseReturnsTwiceAttr(line string) *ReturnsTwiceAttr { 14 groups := groupsFromRegex( 15 `<(?P<position>.*)> 16 (?P<inherited> Inherited)? 17 (?P<implicit> Implicit)? 18 `, 19 line, 20 ) 21 22 return &ReturnsTwiceAttr{ 23 Addr: ParseAddress(groups["address"]), 24 Pos: NewPositionFromString(groups["position"]), 25 ChildNodes: []Node{}, 26 IsInherited: len(groups["inherited"]) > 0, 27 IsImplicit: len(groups["implicit"]) > 0, 28 } 29 } 30 31 // AddChild adds a new child node. Child nodes can then be accessed with the 32 // Children attribute. 33 func (n *ReturnsTwiceAttr) AddChild(node Node) { 34 n.ChildNodes = append(n.ChildNodes, node) 35 } 36 37 // Address returns the numeric address of the node. See the documentation for 38 // the Address type for more information. 39 func (n *ReturnsTwiceAttr) Address() Address { 40 return n.Addr 41 } 42 43 // Children returns the child nodes. If this node does not have any children or 44 // this node does not support children it will always return an empty slice. 45 func (n *ReturnsTwiceAttr) Children() []Node { 46 return n.ChildNodes 47 } 48 49 // Position returns the position in the original source code. 50 func (n *ReturnsTwiceAttr) Position() Position { 51 return n.Pos 52 }