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

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