Skip to main content

ucl_parser/
lib.rs

1//! # UCL Parser
2//!
3//! Parser for the Unified Content Language (UCL).
4//!
5//! UCL is a token-efficient command language for manipulating UCM documents.
6//!
7//! ## Document Structure
8//!
9//! ```text
10//! STRUCTURE
11//! <adjacency declarations>
12//!
13//! BLOCKS
14//! <block definitions>
15//!
16//! COMMANDS
17//! <transformation commands>
18//! ```
19
20pub mod ast;
21pub mod lexer;
22pub mod parser;
23
24pub use ast::*;
25pub use lexer::{Token, TokenKind};
26pub use parser::{ParseError, ParseResult, Parser};
27
28/// Parse a UCL document string
29pub fn parse(input: &str) -> ParseResult<UclDocument> {
30    let mut parser = Parser::new(input);
31    parser.parse_document()
32}
33
34/// Parse UCL commands only (without STRUCTURE/BLOCKS sections)
35pub fn parse_commands(input: &str) -> ParseResult<Vec<Command>> {
36    let mut parser = Parser::new(input);
37    parser.parse_commands_only()
38}
39
40#[cfg(test)]
41mod tests {
42    use super::*;
43
44    #[test]
45    fn test_parse_simple_document() {
46        let input = r#"
47STRUCTURE
48blk_000000000000: [blk_111111111111]
49
50BLOCKS
51text #blk_111111111111 label="Introduction" :: "Hello, world!"
52
53COMMANDS
54EDIT blk_111111111111 SET content.text = "Updated text"
55"#;
56
57        let doc = parse(input).unwrap();
58        assert!(!doc.structure.is_empty());
59        assert!(!doc.blocks.is_empty());
60        assert!(!doc.commands.is_empty());
61    }
62}