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

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