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

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