Expand description
Parser for AgentScript source code.
This module provides a complete parser that converts AgentScript source
into a typed Abstract Syntax Tree (AgentFile).
§Architecture
The parser uses a two-phase approach:
- Lexical analysis - Source → Tokens (via
crate::lexer) - Parsing - Tokens → AST (via chumsky combinators)
§Usage
use busbar_sf_agentscript::parser::parse;
let source = r#"
config:
agent_name: "MyAgent"
topic main:
description: "Main topic"
"#;
match parse(source) {
Ok(agent) => {
println!("Parsed {} topics", agent.topics.len());
}
Err(errors) => {
for err in errors {
eprintln!("{}", err);
}
}
}§Error Handling
Use parse_with_errors() for partial parsing that returns both
the result and any errors encountered:
use busbar_sf_agentscript::parser::parse_with_errors;
let source = "config:\n agent_name: \"Test\"";
let (result, errors) = parse_with_errors(source);
if let Some(agent) = result {
println!("Parsed successfully");
}
for err in errors {
eprintln!("Warning: {}", err);
}§Module Structure
The parser is split into submodules for each block type:
config- Config block parsingvariables- Variable declarationssystem- System instructions and messagestopics- Topic and start_agent blocksactions- Action definitionsreasoning- Reasoning blocksexpressions- Expression parsinginstructions- Static and dynamic instructions
Functions§
- parse
- Parse an AgentScript file from source code.
- parse_
with_ errors - Parse an AgentScript file from source with full error reporting.
- parse_
with_ structured_ errors - Parse an AgentScript file and return structured errors with span information.
- parse_
with_ structured_ errors_ all - Parse an AgentScript file and return structured errors with span information.
Type Aliases§
- Span
- Token span type (from lexer).