Esempio n. 1
0
// Runs the commands given by the command string on the file and
// returns the error if one is found
func (s *Stream) Run(cmd string) error {
	// First parse the entire command string
	cm, er := parser.ParseString(cmd)
	if er != nil {
		return er
	}
	//spew.Dump(cm)
	// So now we run these commands on the file
	fi, er := interpreter.New(s.file)
	if er != nil {
		return er
	}
	return fi.Run(cm)
}
Esempio n. 2
0
File: main.go Progetto: 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
	}
}