...

Source file src/cuelang.org/go/cue/ast/comments.go

Documentation: cuelang.org/go/cue/ast

     1  // Copyright 2019 CUE Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package ast
    16  
    17  // Comments returns all comments associated with a given node.
    18  func Comments(n Node) []*CommentGroup {
    19  	c := n.commentInfo()
    20  	if c == nil {
    21  		return nil
    22  	}
    23  	return c.Comments()
    24  }
    25  
    26  // AddComment adds the given comment to the node if it supports it.
    27  // If a node does not support comments, such as for CommentGroup or Comment,
    28  // this call has no effect.
    29  func AddComment(n Node, cg *CommentGroup) {
    30  	c := n.commentInfo()
    31  	if c == nil {
    32  		return
    33  	}
    34  	c.AddComment(cg)
    35  }
    36  
    37  // SetComments replaces all comments of n with the given set of comments.
    38  // If a node does not support comments, such as for CommentGroup or Comment,
    39  // this call has no effect.
    40  func SetComments(n Node, cgs []*CommentGroup) {
    41  	c := n.commentInfo()
    42  	if c == nil {
    43  		return
    44  	}
    45  	c.SetComments(cgs)
    46  }
    47  

View as plain text