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