feat: decode Analysis v2 and v3 through a shared statement view
This commit is contained in:
1 parent
58cea75bab
commit
bcd07a43af
13 files changed
+1622
-72
No files matched your search
+4
-21
@@ -1,6 +1,8 @@
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::model::{semantic_nodes, AnalysisFunction, Carrier, MarkdownTree, NodeId, Span};
|
||||
use crate::model::{span_value, statements, AnalysisFunction, Carrier, MarkdownTree, NodeId, Span};
|
||||
|
||||
pub use crate::model::node_span;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ControlKind {
|
||||
@@ -244,17 +246,6 @@ fn semantic_controls(analysis: &AnalysisFunction) -> Vec<SemanticControl> {
|
||||
controls
|
||||
}
|
||||
|
||||
pub fn node_span(node: &Value) -> Option<Span> {
|
||||
span_value(node.get("span")?)
|
||||
}
|
||||
|
||||
fn span_value(span: &Value) -> Option<Span> {
|
||||
Some(Span::new(
|
||||
span.get("start")?.as_u64()? as usize,
|
||||
span.get("end")?.as_u64()? as usize,
|
||||
))
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
enum Keyword {
|
||||
If,
|
||||
@@ -283,13 +274,5 @@ impl Keyword {
|
||||
}
|
||||
|
||||
pub fn statement_count(analysis: &AnalysisFunction) -> usize {
|
||||
semantic_nodes(&analysis.body)
|
||||
.filter(|node| {
|
||||
node.get("kind")
|
||||
.and_then(Value::as_str)
|
||||
.is_some_and(|kind| {
|
||||
matches!(kind, "assign" | "expression" | "branch" | "loop" | "return")
|
||||
})
|
||||
})
|
||||
.count()
|
||||
statements(&analysis.body).count()
|
||||
}
|
||||
Reference in new issue
Block a user