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

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