1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use crateAchitekAst;
use Error;
use Parser;
/// Parses Achitekfile source text into an [`AchitekAst`].
///
/// This function configures a Tree-sitter parser with the Achitekfile grammar,
/// parses the supplied source, and returns an AST wrapper that keeps the source
/// text available for later node-to-text conversion.
///
/// The returned AST can be used directly for low-level Tree-sitter access or
/// for higher-level semantic operations:
///
/// ```
/// let source = r#"
/// blueprint {
/// version = "1.0.0"
/// name = "example"
/// }
///
/// prompt "project_name" {
/// type = string
/// help = "Project name"
/// }
/// "#;
///
/// let ast = achitekfile::from_str(source)?;
/// let prompts = ast.ordered_prompts()?;
///
/// assert_eq!(prompts[0].name, "project_name");
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
///
/// # Errors
///
/// Returns [`ParseError::Language`] if the parser cannot be configured with the
/// Achitek grammar, or [`ParseError::ParseCancelled`] if Tree-sitter does not
/// produce a tree.
/// Errors that can occur while parsing source text into an [`AchitekAst`].