github.com/markusbkk/elvish@v0.0.0-20231204143114-91dc52438621/pkg/parse/source.go (about)

     1  package parse
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  // TODO(xiaq): Move this into the diag package after implementing phantom types.
     8  
     9  // Source describes a piece of source code.
    10  type Source struct {
    11  	Name   string
    12  	Code   string
    13  	IsFile bool
    14  }
    15  
    16  // SourceForTest returns a Source used for testing.
    17  func SourceForTest(code string) Source {
    18  	return Source{Name: "[test]", Code: code}
    19  }
    20  
    21  // IsStructMap marks that Source is a structmap.
    22  func (src Source) IsStructMap() {}
    23  
    24  // Repr returns the representation of Source as if it were a map, except that
    25  // the code field is replaced by "...", since it is typically very large.
    26  func (src Source) Repr(int) string {
    27  	return fmt.Sprintf(
    28  		"[&name=%s &code=<...> &is-file=$%v]", Quote(src.Name), src.IsFile)
    29  }