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

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