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