github.com/Konstantin8105/c4go@v0.0.0-20240505174241-768bb1c65a51/ast/array_filler.go (about) 1 package ast 2 3 import ( 4 "strings" 5 ) 6 7 // ArrayFiller is type of array filler 8 type ArrayFiller struct { 9 ChildNodes []Node 10 } 11 12 var arrayFillerMarkers = []string{ 13 "array filler", 14 "array_filler", 15 } 16 17 func parseArrayFiller(line string) *ArrayFiller { 18 arrfill := &ArrayFiller{ 19 ChildNodes: []Node{}, 20 } 21 22 for _, af := range arrayFillerMarkers { 23 if strings.HasPrefix(line, af+":") { 24 line = line[len(af+":")+1:] 25 } 26 if strings.HasPrefix(line, af) { 27 line = line[len(af):] 28 } 29 } 30 line = strings.TrimSpace(line) 31 if line != "" { 32 rn, err := Parse(line) 33 if err != nil { 34 panic(err) 35 } 36 arrfill.AddChild(rn) 37 } 38 39 return arrfill 40 } 41 42 // AddChild adds a new child node. Child nodes can then be accessed with the 43 // Children attribute. 44 func (n *ArrayFiller) AddChild(node Node) { 45 n.ChildNodes = append(n.ChildNodes, node) 46 } 47 48 // Address returns the numeric address of the node. For an ArrayFilter this will 49 // always be zero. See the documentation for the Address type for more 50 // information. 51 func (n *ArrayFiller) Address() Address { 52 return 0 53 } 54 55 // Children returns the child nodes. If this node does not have any children or 56 // this node does not support children it will always return an empty slice. 57 func (n *ArrayFiller) Children() []Node { 58 return n.ChildNodes 59 } 60 61 // Position returns the position in the original source code. 62 func (n *ArrayFiller) Position() Position { 63 return Position{} 64 }