github.com/oweisse/u-root@v0.0.0-20181109060735-d005ad25fef1/cmds/elvish/eval/compilation_error.go (about)

     1  package eval
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  
     7  	"github.com/u-root/u-root/cmds/elvish/util"
     8  )
     9  
    10  // CompilationError represents a compilation error and can pretty print it.
    11  type CompilationError struct {
    12  	Message string
    13  	Context util.SourceRange
    14  }
    15  
    16  func (ce *CompilationError) Error() string {
    17  	return fmt.Sprintf("compilation error: %d-%d in %s: %s",
    18  		ce.Context.Begin, ce.Context.End, ce.Context.Name, ce.Message)
    19  }
    20  
    21  // Pprint pretty-prints a compilation error.
    22  func (ce *CompilationError) Pprint(indent string) string {
    23  	var buf bytes.Buffer
    24  
    25  	fmt.Fprintf(&buf, "Compilation error: \033[31;1m%s\033[m\n", ce.Message)
    26  	buf.WriteString(ce.Context.PprintCompact(indent + "  "))
    27  
    28  	return buf.String()
    29  }