pub fn parse(input: &str) -> Result<Program, ParseError>Expand description
Parse a slash-command string into a Program AST.
§Grammar (informally)
program := pipeline ( ( '&&' | '||' ) pipeline )*
pipeline := command ( ( '|' | '|&' ) command )* redirect?
redirect := ( '>' | '>>' ) filename
command := SLASH_TOKEN arg*Tokenization splits on ASCII whitespace only — no quoting, no escaping.
§Priority inference
Priority is inferred from the raw command token’s casing before normalization:
| Shape | Priority |
|---|---|
ALL_CAPS | Max |
TitleCase | High |
camelCase | Medium |
kebab-case | Low |
snake_case | Lowest |
§Errors
Returns ParseError on any structural violation, including:
- Two commands in sequence without an operator
- Standalone
!/!!/!!!urgency tokens - More than three
!markers on a command - Double
??optional suffix - Malformed builder chain (unmatched parentheses)
- Redirection followed by a non-
&&/||token - Digits in command names outside the
/test-family
§Examples
use slash_lang::parser::parse;
use slash_lang::parser::ast::{Priority, Urgency};
let program = parse("/Build.target(release)! | /test").unwrap();
let cmd = &program.pipelines[0].commands[0];
assert_eq!(cmd.name, "build");
assert_eq!(cmd.priority, Priority::High);
assert_eq!(cmd.urgency, Urgency::Low);
assert_eq!(cmd.args[0].name, "target");
assert_eq!(cmd.args[0].value.as_deref(), Some("release"));