Skip to main content

busbar_sf_agentscript/
lib.rs

1#![recursion_limit = "512"]
2
3//! # busbar-sf-agentscript
4//!
5//! A Rust parser for Salesforce's AgentScript language with graph analysis and WebAssembly support.
6//!
7//! ## Feature Flags
8//!
9//! - `graph` - Enable graph analysis, validation, and rendering (brings in `petgraph`)
10//! - `wasm` - Enable WebAssembly bindings for browser use
11//!
12//! ## Quick Start
13//!
14//! ```rust,ignore
15//! use busbar_sf_agentscript::{parse, AgentFile};
16//!
17//! let ast = parse(source).unwrap();
18//!
19//! // With the `graph` feature:
20//! use busbar_sf_agentscript::graph::RefGraph;
21//! let graph = RefGraph::from_ast(&ast).unwrap();
22//! println!("{} topics", graph.node_count());
23//! ```
24
25pub mod ast;
26pub mod error;
27pub mod lexer;
28pub mod parser;
29pub mod serializer;
30pub mod validation;
31
32#[cfg(feature = "wasm")]
33pub mod wasm;
34
35#[cfg(feature = "graph")]
36pub mod graph;
37
38// Re-export commonly used types
39pub use ast::{AgentFile, Expr, Reference, Spanned, Type};
40pub use error::{AgentScriptError, ErrorReporter};
41pub use parser::{parse, parse_with_structured_errors};
42pub use serializer::serialize;
43pub use validation::validate_ast;
44
45/// Parse AgentScript source code into an AST.
46pub fn parse_source(source: &str) -> Result<AgentFile, Vec<String>> {
47    let (result, errors) = parser::parse_with_errors(source);
48    if !errors.is_empty() {
49        return Err(errors);
50    }
51    result.ok_or_else(|| vec!["Unknown parse error".to_string()])
52}
53
54#[cfg(test)]
55mod tests {
56    use super::*;
57    use chumsky::prelude::*;
58
59    #[test]
60    fn test_parse_minimal() {
61        let source = r#"
62config:
63   agent_name: "Test"
64"#;
65        let result = parse_source(source);
66        assert!(result.is_ok());
67    }
68
69    #[test]
70    fn test_lexer_integration() {
71        let source = r#"@variables.user_id != """#;
72        let tokens = lexer::lexer().parse(source);
73        assert!(tokens.has_output());
74    }
75}