Example #1
0
File: value.go Project: jerluc/rift
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
}
Example #2
0
File: value.go Project: jerluc/rift
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
	}
}
Example #3
0
File: value.go Project: jerluc/rift
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()
}
Example #4
0
func ensureArity(expectedLength int, actualLength int) {
	sanity.Ensure(actualLength == expectedLength, "Function expects [%d] arguments, but got [%d]", expectedLength, actualLength)
}
Example #5
0
File: vm.go Project: 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())
}
Example #6
0
File: ast.go Project: 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}
}
Example #7
0
File: ast.go Project: 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}
}
Example #8
0
File: ast.go Project: 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}
}
Example #9
0
File: ast.go Project: 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}
}
Example #10
0
File: ast.go Project: 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}
}
Example #11
0
File: ast.go Project: 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}
}
Example #12
0
File: ast.go Project: 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}
}
Example #13
0
File: ast.go Project: 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}
}
Example #14
0
File: ast.go Project: 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}
}