Example #1
0
func parseInput(d dynamics.Dwimmer, context *term.SettingT, quotedInput, quotedNames term.T) term.T {
	input, err := represent.ToStr(d, quotedInput)
	if err != nil {
		return represent.ConversionError.T(quotedInput, err)
	}
	quotedList, err := represent.ToList(d, quotedNames)
	if err != nil {
		return represent.ConversionError.T(quotedNames, err)
	}
	names := make([]string, len(quotedList))
	for i, quoted := range quotedList {
		names[i], err = represent.ToStr(d, quoted)
		if err != nil {
			return represent.ConversionError.T(quoted, err)
		}
	}
	if input == "jump up" {
		return GoMeta.T()
	}
	a := parsing.ParseAction(input, names)
	if a == nil {
		c := parsing.ParseTerm(input, names)
		if c != nil {
			switch c := c.(type) {
			case *term.CompoundC:
				if questionLike(c) {
					a = new(term.ActionC)
					*a = term.AskC(c)
				}
			case term.ReferenceC:
				a = new(term.ActionC)
				*a = term.ViewC(c)
			}
			context.AppendTerm(IsTerm.T())
			return nil
		} else {
			context.AppendTerm(ParseError.T())
			return nil
		}
	} else {
		for _, n := range a.IntArgs {
			if n < 0 {
				context.AppendTerm(ParseError.T())
				return nil
			}
		}
		return core.Answer.T(represent.ActionC(*a))
	}
}
Example #2
0
func (r *lexer) setActionResult(head string, e *Expr, n int) {
	var a term.ActionC
	var t term.C
	if e != nil {
		t = toC(e)
	}
	switch strings.ToLower(head) {
	case "return", "reply", "say", "respond", "answer":
		if t == nil {
			t = term.Cc(represent.Int(n))
		}
		a = term.ReturnC(t)
	case "ask", "inquire", "do":
		a = term.AskC(t)
	case "view", "check", "inspect", "see":
		if t == nil {
			t = term.Cc(represent.Int(n))
		}
		a = term.ViewC(t)
	case "replace", "rewrite", "change", "jump", "set":
		a = term.ReplaceC(t, n)
	case "replay", "redo", "repeat":
		a = term.ReplayC(n)
	case "correct", "fix", "debug":
		a = term.CorrectC(n)
	case "meta", "self", "here", "this":
		a = term.MetaC()
	case "close", "dismiss", "stop", "delete", "del", "remove":
		c := toC(e)
		switch c := c.(type) {
		case term.ReferenceC:
			a = term.DeleteC(c.Index)
		}
	default:
		return
	}
	r.actionResult = &a
}
Example #3
0
func OldElicitAction(d dynamics.Dwimmer, context *term.SettingT, subject *term.Setting, hints bool) term.ActionC {
	settingS := addNames(subject)
	ShowSettingS(d, settingS)
	hint_strings := []string{}
	tool_map := make(map[rune]string)
	if hints {
		hint_strings = GetHints(d, context, settingS, 6)
		tools := similarity.SuggestedTemplates(d, subject, 6)
		if len(hint_strings) > 0 || len(tools) > 0 {
			d.Println("")
		}
		if len(tools) > 0 {
			d.Println("")
		}
		tips := []rune{'a', 's', 'd', 'w', 'e', 'j'}
		for i, tool := range tools {
			tool_map[tips[i]] = tool.String()
			d.Println(fmt.Sprintf("%c: %v", tips[i], tool))
		}
		if len(hint_strings) > 0 {
			d.Println("")
		}
		for i, hint := range hint_strings {
			d.Println(fmt.Sprintf("%d. %s", i, hint))
		}
	}
	d.Println("")
	for {
		input := d.Readln(" < ", hint_strings, tool_map)
		if input == "jump up" {
			StartShell(d, Interrupted.T(represent.SettingT(context)))
		}
		a := parsing.ParseAction(input, settingS.Names)
		if a == nil {
			c := parsing.ParseTerm(input, settingS.Names)
			if c != nil {
				switch c := c.(type) {
				case *term.CompoundC:
					if questionLike(c) {
						a = new(term.ActionC)
						*a = term.AskC(c)
					}
				case term.ReferenceC:
					a = new(term.ActionC)
					*a = term.ViewC(c)
				}
				d.Println("please input an action (ask, view, return, close, delete, correct, or tell)")
			} else {
				d.Println("that response wasn't parsed correctly")
			}
		}
		if a != nil {
			for i, n := range a.IntArgs {
				if n == -1 {
					a.IntArgs[i] = subject.Size - 1
				}
			}
			return *a
		}
	}
}