github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/compile/internal/syntax/testing.go (about)

     1  // Copyright 2020 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // This file implements testing support.
     6  
     7  package syntax
     8  
     9  import (
    10  	"github.com/shogo82148/std/io"
    11  	"github.com/shogo82148/std/regexp"
    12  )
    13  
    14  // CommentsDo parses the given source and calls the provided handler for each
    15  // comment or error. If the text provided to handler starts with a '/' it is
    16  // the comment text; otherwise it is the error message.
    17  func CommentsDo(src io.Reader, handler func(line, col uint, text string))
    18  
    19  // CommentMap collects all comments in the given src with comment text
    20  // that matches the supplied regular expression rx and returns them as
    21  // []Error lists in a map indexed by line number. The comment text is
    22  // the comment with any comment markers ("//", "/*", or "*/") stripped.
    23  // The position for each Error is the position of the token immediately
    24  // preceding the comment and the Error message is the comment text,
    25  // with all comments that are on the same line collected in a slice, in
    26  // source order. If there is no preceding token (the matching comment
    27  // appears at the beginning of the file), then the recorded position
    28  // is unknown (line, col = 0, 0). If there are no matching comments,
    29  // the result is nil.
    30  func CommentMap(src io.Reader, rx *regexp.Regexp) (res map[uint][]Error)