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

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