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