Files
RedBear-OS/local/recipes/shells/brush/source/brush-parser/examples/serde.rs
T
vasilito 25fb843c40 brush: vendor the source tree (un-ignore) to complete the local fork
The prior commit switched the recipe to `[source] path = "source"`, but
.gitignore:77 still listed `local/recipes/shells/brush/source` (a leftover from
when brush was a transient upstream git fetch), so the vendored tree was not
tracked — a fresh clone would have no brush source and the build would fail.
Drop that ignore line and commit the vendored working tree (reubeno/brush @
897b373e, with the Redox port patches pre-applied). brush is now a durable
local fork like the other path=source recipes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-26 23:34:31 +09:00

32 lines
1.0 KiB
Rust

//! Example demonstrating AST serialization and deserialization with the `serde` feature.
//!
//! Run with: `cargo run --package brush-parser --example serde --features serde`
use brush_parser::{Parser, ParserOptions};
use std::io::BufReader;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Parse a simple shell command
let input = "echo 'Hello, World!' && ls -la";
let reader = BufReader::new(input.as_bytes());
let options = ParserOptions::default();
let mut parser = Parser::new(reader, &options);
let program = parser.parse_program()?;
// Serialize the AST to JSON
let json = serde_json::to_string_pretty(&program)?;
println!("Parsed AST:");
println!("{json}");
// Demonstrate round-trip: deserialize the JSON back to AST
println!("\nRound-trip deserialization:");
let deserialized: brush_parser::ast::Program = serde_json::from_str(&json)?;
println!(
"Successfully deserialized AST with {} command(s)",
deserialized.complete_commands.len()
);
Ok(())
}