zeolite-lang-0.3.0.0: example/tree/tree-demo.0rx
concrete TreeDemo {
@type run () -> ()
}
define TreeDemo {
run () {
TypeTree tree <- TypeTree$new()
TypeKey<Int> keyInt <- TypeKey<Int>$new()
TypeKey<String> keyString <- TypeKey<String>$new()
TypeKey<Float> keyFloat <- TypeKey<Float>$new()
TypeKey<Value> keyValue <- TypeKey<Value>$new()
\ tree.set<Int>(keyInt,1)
\ tree.set<String>(keyString,"a")
\ check<Int>(tree,keyInt)
\ check<String>(tree,keyString)
\ check<Float>(tree,keyFloat) // Not found, since we never added a value.
\ tree.set<Value>(keyValue,Value$new())
\ check<Value>(tree,keyValue)
}
@category check<#x>
#x requires Formatted
(TypeTree,TypeKey<#x>) -> ()
check (tree,key) {
scoped {
optional #x value <- tree.get<#x>(key)
} in if (present(value)) {
\ LazyStream<Formatted>$new()
.append("Found '")
.append(require(value))
.append("'\n")
.writeTo(SimpleOutput$stderr())
} else {
\ LazyStream<Formatted>$new()
.append(typename<TypeKey<#x>>())
.append(" Not Found\n")
.writeTo(SimpleOutput$stderr())
}
}
}
concrete Value {
refines Formatted
@type new () -> (Value)
}
define Value {
new () { return Value{} }
formatted () { return "Value" }
}