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