MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / to_leaf_ops

Method to_leaf_ops

atomic-core/src/record/workflow/recipes/diff_op_rules.rs:74–91  ·  view source on GitHub ↗

Convert the line's tokens into `LeafOp::Insert` ops, allocating fresh leaf IDs via `alloc_leaf`.

(&self, next_leaf_idx: &mut u32, placeholder_change: NodeId)

Source from the content-addressed store, hash-verified

72 /// Convert the line's tokens into `LeafOp::Insert` ops, allocating
73 /// fresh leaf IDs via `alloc_leaf`.
74 pub fn to_leaf_ops(&self, next_leaf_idx: &mut u32, placeholder_change: NodeId) -> Vec<LeafOp> {
75 let tokenizer = ContentTokenizer::new(self.bytes);
76 let mut leaf_ops = Vec::new();
77 let mut prev_leaf: Option<LeafId> = None;
78 for tokenized in tokenizer.lines() {
79 for token in tokenized.tokens() {
80 let leaf_id = LeafId::new(placeholder_change, *next_leaf_idx);
81 *next_leaf_idx += 1;
82 leaf_ops.push(LeafOp::Insert {
83 after: prev_leaf,
84 kind: token.kind(),
85 content: token.content().to_vec(),
86 });
87 prev_leaf = Some(leaf_id);
88 }
89 }
90 leaf_ops
91 }
92}
93
94/// One translation rule.

Callers

nothing calls this directly

Calls 5

linesMethod · 0.45
tokensMethod · 0.45
pushMethod · 0.45
kindMethod · 0.45
contentMethod · 0.45

Tested by

no test coverage detected