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