Exemplo n.º 1
0
Arquivo: main.go Projeto: vron/sem
// Run all the commands on the data in in and if no error happens
// then do the output to out
func do(cmds []parser.Command, in io.Reader, out io.Writer) {
	f := gap.NewReader(in)
	i, e := interpreter.New(f)
	if e != nil {
		fmt.Println("error: could not create interpreter:", e)
		return
	}
	e = i.Run(cmds)
	if e != nil {
		fmt.Println("error while executing commands:", e)
		return
	}
	_, e = i.File().Seek(0, 0)
	if e != nil {
		fmt.Println("error: could not setupt output:", e)
		return
	}
	_, e = io.Copy(out, i.File())
	if e != nil {
		fmt.Println("error: could not write all data to output:", e)
		return
	}
}
Exemplo n.º 2
0
// Create a new stream by reading all ontents of the reader
func New(in io.Reader) *Stream {
	s := &Stream{}
	// Read in to the file
	s.file = gap.NewReader(in)
	return s
}