Merge nucleic/sleek-thistle-egret-fyej into dev

This commit is contained in:
2026-07-18 05:19:31 -07:00
commit b6be87b72d
677 changed files with 102939 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
//! Simple example of miette usage
use std::io::Cursor;
use brush_parser::Parser;
use miette::{IntoDiagnostic, miette};
fn main() -> miette::Result<()> {
let f = std::env::args()
.nth(1)
.ok_or_else(|| miette!("Please provide a file name"))?;
let source = std::fs::read_to_string(&f).into_diagnostic()?;
let reader = Cursor::new(&source);
let mut parser = Parser::builder().build(reader);
let ast = parser
.parse_program()
.map_err(|e| e.to_pretty_error(&source))?;
println!("{ast:#?}");
Ok(())
}
+31
View File
@@ -0,0 +1,31 @@
//! 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(())
}