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

     1  package ast
     2  
     3  import (
     4  	"github.com/Konstantin8105/c4go/util"
     5  )
     6  
     7  // CharacterLiteral is type of character literal
     8  type CharacterLiteral struct {
     9  	Addr       Address
    10  	Pos        Position
    11  	Type       string
    12  	Value      int
    13  	ChildNodes []Node
    14  }
    15  
    16  func parseCharacterLiteral(line string) *CharacterLiteral {
    17  	groups := groupsFromRegex(
    18  		"<(?P<position>.*)> '(?P<type>.*?)' (?P<value>\\d+)",
    19  		line,
    20  	)
    21  
    22  	return &CharacterLiteral{
    23  		Addr:       ParseAddress(groups["address"]),
    24  		Pos:        NewPositionFromString(groups["position"]),
    25  		Type:       groups["type"],
    26  		Value:      util.Atoi(groups["value"]),
    27  		ChildNodes: []Node{},
    28  	}
    29  }
    30  
    31  // AddChild adds a new child node. Child nodes can then be accessed with the
    32  // Children attribute.
    33  func (n *CharacterLiteral) AddChild(node Node) {
    34  	n.ChildNodes = append(n.ChildNodes, node)
    35  }
    36  
    37  // Address returns the numeric address of the node. See the documentation for
    38  // the Address type for more information.
    39  func (n *CharacterLiteral) Address() Address {
    40  	return n.Addr
    41  }
    42  
    43  // Children returns the child nodes. If this node does not have any children or
    44  // this node does not support children it will always return an empty slice.
    45  func (n *CharacterLiteral) Children() []Node {
    46  	return n.ChildNodes
    47  }
    48  
    49  // Position returns the position in the original source code.
    50  func (n *CharacterLiteral) Position() Position {
    51  	return n.Pos
    52  }
    53  
    54  // CharacterLiteralError represents one instance of an error where the exact
    55  // character value of a CharacterLiteral could not be determined from the
    56  // original source. See RepairCharacterLiteralsFromSource for a full explanation.
    57  type CharacterLiteralError struct {
    58  	Node *CharacterLiteral
    59  	Err  error
    60  }