Exemplo n.º 1
0
func (ec *evalCtx) evalWithChanOut(op valuesOp, ch chan Value) (vs []Value, err error) {
	if op.f == nil {
		return nil, nil
	}
	if ch != nil {
		ec.ports[1] = &port{ch: ch, closeCh: false}
	}
	defer ec.closePorts()
	defer errutil.Catch(&err)
	vs = op.f(ec)
	return vs, nil
}
Exemplo n.º 2
0
// Parse parses the script to construct a representation of the script for
// execution.
func (p *Parser) Parse(text string, completing bool) (err error) {
	defer errutil.Catch(&err)
	defer p.stopParse()

	p.completing = completing
	p.text = text
	p.lex = Lex(p.Name, text)
	p.peekCount = 0

	p.Ctx = &Context{}
	p.Root = p.parse()

	return nil
}
Exemplo n.º 3
0
func (cc *compileCtx) compile(n *parse.Chunk) (op valuesOp, err error) {
	defer errutil.Catch(&err)
	return cc.chunk(n), nil
}
Exemplo n.º 4
0
func (rd *Reader) readOne(r rune) (k Key, cpr pos, err error) {
	defer errutil.Catch(&err)

	rd.currentSeq = ""

	switch r {
	case Tab, Enter, Backspace:
		k = Key{r, 0}
	case 0x0:
		k = Key{'`', Ctrl} // ^@
	case 0x1d:
		k = Key{'6', Ctrl} // ^^
	case 0x1f:
		k = Key{'/', Ctrl} // ^_
	case 0x1b: // ^[ Escape
		//rd.timed.Timeout = escTimeout
		//defer func() { rd.timed.Timeout = -1 }()
		r2 := rd.readRune(escTimeout)
		if r2 == runeTimeout {
			return Key{'[', Ctrl}, invalidPos, nil
		}
		switch r2 {
		case '[':
			// CSI style function key sequence, looks like [\d;]*[^\d;]
			// Read numeric parameters (if any)
			nums := make([]int, 0, 2)
			seq := "\x1b["
			timeout := escTimeout
			for {
				r = rd.readRune(timeout)
				// Timeout can only happen at first readRune.
				if r == runeTimeout {
					return Key{'[', Alt}, invalidPos, nil
				}
				seq += string(r)
				// After first rune read we turn off the timeout
				timeout = -1
				if r != ';' && (r < '0' || r > '9') {
					break
				}

				if len(nums) == 0 {
					nums = append(nums, 0)
				}
				if r == ';' {
					nums = append(nums, 0)
				} else {
					cur := len(nums) - 1
					nums[cur] = nums[cur]*10 + int(r-'0')
				}
			}
			if r == 'R' {
				// CPR
				if len(nums) != 2 {
					rd.badEscSeq("bad cpr")
				}
				return ZeroKey, pos{nums[0], nums[1]}, nil
			}
			k, err := parseCSI(nums, r, seq)
			return k, invalidPos, err
		case 'O':
			// G3 style function key sequence: read one rune.
			r = rd.readRune(escTimeout)
			if r == runeTimeout {
				return Key{r2, Alt}, invalidPos, nil
			}
			r, ok := g3Seq[r]
			if ok {
				return Key{r, 0}, invalidPos, nil
			}
			rd.badEscSeq("")
		}
		return Key{r2, Alt}, invalidPos, nil
	default:
		// Sane Ctrl- sequences that agree with the keyboard...
		if 0x1 <= r && r <= 0x1d {
			k = Key{r + 0x40, Ctrl}
		} else {
			k = Key{r, 0}
		}
	}
	return k, invalidPos, nil
}