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

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