Пример #1
0
func (numericNode *Node) Int() int {
	sanity.Ensure(numericNode.Type == NUM, "Invalid cast from type [%s] to [%s]", numericNode.Type, NUM)
	intAsString := numericNode.Values[0].(string)
	intValue, parseErr := strconv.Atoi(intAsString)
	sanity.Ensure(parseErr == nil, "Invalid integer value [%s]", intAsString)
	return intValue
}
Пример #2
0
func (boolNode *Node) Bool() bool {
	sanity.Ensure(boolNode.Type == BOOL, "Invalid cast from type [%s] to [%s]", boolNode.Type, BOOL)
	boolAsString := boolNode.Values[0].(string)
	switch boolAsString {
	default:
		sanity.Fail("Invalid boolean value [%s]", boolAsString)
		return false
	case "true":
		return true
	case "false":
		return false
	}
}
Пример #3
0
func (stringNode *Node) Str() string {
	sanity.Ensure(stringNode.Type == STRING, "Invalid cast from type [%s] to [%s]", stringNode.Type, STRING)
	origStr := stringNode.Values[0].(string)

	var buffer bytes.Buffer
	var escaped bool
	for _, c := range origStr {
		if escaped {
			switch c {
			case '\\':
				buffer.WriteRune('\\')
			case '\'':
				buffer.WriteRune('\'')
			case '?':
				buffer.WriteRune('?')
			case '"':
				buffer.WriteRune('"')
			case 'a':
				buffer.WriteRune('\a')
			case 'b':
				buffer.WriteRune('\b')
			case 'f':
				buffer.WriteRune('\f')
			case 'n':
				buffer.WriteRune('\n')
			case 'r':
				buffer.WriteRune('\r')
			case 't':
				buffer.WriteRune('\t')
			case 'v':
				buffer.WriteRune('\v')
			}
			escaped = false
			continue
		}
		if c == '\\' {
			escaped = true
		} else {
			buffer.WriteRune(c)
		}
	}

	return buffer.String()
}
Пример #4
0
func ensureArity(expectedLength int, actualLength int) {
	sanity.Ensure(actualLength == expectedLength, "Function expects [%d] arguments, but got [%d]", expectedLength, actualLength)
}
Пример #5
0
Файл: vm.go Проект: jerluc/rift
func dereference(rift *lang.Rift, env collections.PersistentMap, ref *lang.Ref) interface{} {
	// TODO: Support gravity
	sanity.Ensure(env.Contains(ref.String()), "Undefined reference to [%s]", ref.String())
	return env.GetOrNil(ref.String())
}
Пример #6
0
Файл: ast.go Проект: jerluc/rift
func (n *Node) List() *List {
	sanity.Ensure(n.Type == LIST, "Node must be [%s], but was [%s]", LIST, n.Type)
	return &List{n}
}
Пример #7
0
Файл: ast.go Проект: jerluc/rift
func (n *Node) Block() *Block {
	sanity.Ensure(n.Type == BLOCK, "Node must be [%s], but was [%s]", BLOCK, n.Type)
	return &Block{n}
}
Пример #8
0
Файл: ast.go Проект: jerluc/rift
func (n *Node) Operation() *Operation {
	sanity.Ensure(n.Type == OP, "Node must be [%s], but was [%s]", OP, n.Type)
	return &Operation{n}
}
Пример #9
0
Файл: ast.go Проект: jerluc/rift
func (n *Node) If() *If {
	sanity.Ensure(n.Type == IF, "Node must be [%s], but was [%s]", IF, n.Type)
	return &If{n}
}
Пример #10
0
Файл: ast.go Проект: jerluc/rift
func (n *Node) Func() *Func {
	sanity.Ensure(n.Type == FUNC, "Node must be [%s], but was [%s]", FUNC, n.Type)
	return &Func{n}
}
Пример #11
0
Файл: ast.go Проект: jerluc/rift
func (n *Node) FuncApply() *FuncApply {
	sanity.Ensure(n.Type == FUNCAPPLY, "Node must be [%s], but was [%s]", FUNCAPPLY, n.Type)
	return &FuncApply{n}
}
Пример #12
0
Файл: ast.go Проект: jerluc/rift
func (n *Node) Assignment() *Assignment {
	sanity.Ensure(n.Type == ASSIGNMENT, "Node must be [%s], but was [%s]", ASSIGNMENT, n.Type)
	return &Assignment{n}
}
Пример #13
0
Файл: ast.go Проект: jerluc/rift
func (n *Node) Ref() *Ref {
	sanity.Ensure(n.Type == REF, "Node must be [%s], but was [%s]", REF, n.Type)
	return &Ref{n}
}
Пример #14
0
Файл: ast.go Проект: jerluc/rift
func (n *Node) Rift() *Rift {
	sanity.Ensure(n.Type == RIFT, "Node must be [%s], but was [%s]", RIFT, n.Type)
	return &Rift{n}
}