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