Let me provide a summary of what was accomplished:#28
Conversation
Summary
Implemented full JSON object and array parsing with arbitrary-length support.
Key Changes
1. Runtime: variant-append (runtime/src/variant_ops.rs)
- New primitive: ( Variant Value -- Variant' )
- Creates a new variant with the value appended (functional/immutable)
- Foundation for building dynamic-length collections
2. Compiler updates (compiler/src/ast.rs, builtins.rs, codegen.rs)
- Registered variant-append as a builtin operation
3. JSON library: Functional builders (stdlib/json.seq)
- array-with: ( arr val -- arr' ) - append element to array
- obj-with: ( obj key val -- obj' ) - add key-value pair to object
4. JSON parsing: Recursive approach (stdlib/json.seq)
- pstate-parse-one-element + pstate-parse-array-elements for arrays
- pstate-parse-one-pair + pstate-parse-object-pairs for objects
- Both use functional builders to grow collections incrementally
- Supports arbitrary-length arrays and objects
5. JSON serialization - Extended to handle 3-element arrays and 2-pair objects
What Works Now
./json_tree '[1, 2, 3, 4, 5]' # Parses ✓ (serializes as [...] for 4+)
./json_tree '[[1, 2], [3, 4]]' # Nested arrays ✓
./json_tree '{"a": 1, "b": 2, "c": 3}' # Parses ✓ (serializes as {...} for 3+)
./json_tree '{"person": {"name": "John", "age": 30}}' # Nested ✓
./json_tree '[{"name": "John", "age": 30}, {"name": "Jane", "age": 25}]' # ✓
Pull Request Review - PR #28: JSON Object and Array ParsingSummaryThis PR implements full JSON object and array parsing with arbitrary-length support through a new ✅ Strengths1. Well-Designed Core PrimitiveThe
runtime/src/variant_ops.rs:178-203 pub unsafe extern "C" fn patch_seq_variant_append(stack: Stack) -> Stack {
// Creates new variant without modifying original
let mut new_fields = variant_data.fields.to_vec();
new_fields.push(value);
Value::Variant(Box::new(VariantData::new(variant_data.tag, new_fields)))
}2. Functional Builder PatternThe high-level builders (
3. Recursive Parsing ArchitectureThe recursive parsing approach is elegant:
|
Summary
Implemented full JSON object and array parsing with arbitrary-length support.
Key Changes
What Works Now
./json_tree '[1, 2, 3, 4, 5]' # Parses ✓ (serializes as [...] for 4+)
./json_tree '[[1, 2], [3, 4]]' # Nested arrays ✓
./json_tree '{"a": 1, "b": 2, "c": 3}' # Parses ✓ (serializes as {...} for 3+)
./json_tree '{"person": {"name": "John", "age": 30}}' # Nested ✓
./json_tree '[{"name": "John", "age": 30}, {"name": "Jane", "age": 25}]' # ✓