github.com/Konstantin8105/c4go@v0.0.0-20240505174241-768bb1c65a51/ast/case_stmt.go (about)

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