Fix simple value parsing
This commit is contained in:
parent
7fa5dd0f54
commit
9aaa9f1e6d
@ -99,17 +99,14 @@ impl<'context, 'code> Evaluator<'context, 'code> {
|
||||
}
|
||||
|
||||
fn run(self) -> Vec<Result<Value>> {
|
||||
let mut cursor_0 = self.tree.walk();
|
||||
let mut cursor_1 = self.tree.walk();
|
||||
let node = cursor_0.node();
|
||||
let item_count = node.child_count();
|
||||
let mut cursor = self.tree.walk();
|
||||
let root_node = cursor.node();
|
||||
let item_count = root_node.child_count();
|
||||
let mut results = Vec::with_capacity(item_count);
|
||||
|
||||
println!("{}", node.to_sexp());
|
||||
println!("{}", root_node.to_sexp());
|
||||
|
||||
assert_eq!(cursor_0.node().kind(), "root");
|
||||
|
||||
for item_node in node.children(&mut cursor_0) {
|
||||
for item_node in root_node.children(&mut cursor) {
|
||||
let item_result = Item::from_syntax_node(item_node, self.source);
|
||||
|
||||
match item_result {
|
||||
|
@ -54,9 +54,31 @@ impl Value {
|
||||
let child = node.child(0).unwrap();
|
||||
|
||||
match child.kind() {
|
||||
"integer" | "float" | "boolean" | "string" | "empty" => {
|
||||
Ok(Value::from_syntax_node(child, source)?)
|
||||
"integer" => {
|
||||
let bytes = &source[child.byte_range()];
|
||||
let raw_value = bytes.parse::<i64>().unwrap();
|
||||
|
||||
Ok(Value::Integer(raw_value))
|
||||
}
|
||||
"float" => {
|
||||
let bytes = &source[child.byte_range()];
|
||||
let raw_value = bytes.parse::<f64>().unwrap();
|
||||
|
||||
Ok(Value::Float(raw_value))
|
||||
}
|
||||
"string" => {
|
||||
let byte_range_without_quotes = child.start_byte() - 1..child.end_byte();
|
||||
let text = &source[byte_range_without_quotes];
|
||||
|
||||
Ok(Value::String(text.to_string()))
|
||||
}
|
||||
"boolean" => {
|
||||
let bytes = &source[child.byte_range()];
|
||||
let raw_value = bytes.parse::<bool>().unwrap();
|
||||
|
||||
Ok(Value::Boolean(raw_value))
|
||||
}
|
||||
"empty" => Ok(Value::Empty),
|
||||
"list" => {
|
||||
let item_count = child.named_child_count();
|
||||
let mut values = Vec::with_capacity(item_count);
|
||||
|
Loading…
Reference in New Issue
Block a user