Skip to content

Commit

Permalink
Add handling for more literals and identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
Cypher1 committed Jan 27, 2025
1 parent ebc42d5 commit ff47e24
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions takolib/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,42 @@ fn handle_subtree<'a>(
// TODO: Handle constructing this kind of node from it's children
let nt = &ast.node_types;

// TODO: Handle ts_node.is_missing()
// TODO: Handle ts_node.is_extra()
// TODO: Handle ts_node.is_error()

// TODO: Handle complex node types?

// Handle text extraction node types

let contents = ts_node.utf8_text(input.as_bytes()).unwrap();
let start = ts_node.start_byte();
let end = ts_node.end_byte();
let start_pos = ts_node.start_position();
let end_pos = ts_node.end_position();
if ts_node.kind_id() == nt._ident {
println!("IDENT {:?} {:?}..{:?} {:?}..{:?}", contents, start, end, start_pos, end_pos);
return Ok(None);
}
if ts_node.kind_id() == nt._int_literal {
println!("INT_LITERAL");
println!("INT_LITERAL {:?} {:?}..{:?} {:?}..{:?}", contents, start, end, start_pos, end_pos);
return Ok(None);
}
if ts_node.kind_id() == nt._float_literal {
println!("FLOAT_LITERAL {:?} {:?}..{:?} {:?}..{:?}", contents, start, end, start_pos, end_pos);
return Ok(None);
}
if ts_node.kind_id() == nt._string_literal {
println!("STRING_LITERAL {:?} {:?}..{:?} {:?}..{:?}", contents, start, end, start_pos, end_pos);
return Ok(None);
}
if ts_node.kind_id() == nt._hex_literal {
println!("HEX_LITERAL {:?} {:?}..{:?} {:?}..{:?}", contents, start, end, start_pos, end_pos);
return Ok(None);
}
if ts_node.kind_id() == nt._color {
println!("COLOR {:?} {:?}..{:?} {:?}..{:?}", contents, start, end, start_pos, end_pos);
return Ok(None);
}
let info = (
ts_node.id(),
Expand All @@ -330,9 +364,9 @@ fn handle_subtree<'a>(
);
println!(
"{:?} {:?} FROM {}",
info,
ts_node,
ts_node.utf8_text(input.as_bytes()).unwrap()
info,
ts_node,
ts_node.utf8_text(input.as_bytes()).unwrap()
);
// TODO: return the ID
Ok(None)
Expand Down

0 comments on commit ff47e24

Please sign in to comment.