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