forked from mirrors/jj
templater: fix parsing of parenthesized expression
A "list" is a sequence of more than one "term" nodes, so it shouldn't contain a single parenthesized node. Also, a parenthesized "term" rule wasn't handled.
This commit is contained in:
parent
f7993f0fe9
commit
bf66beab36
3 changed files with 30 additions and 3 deletions
|
@ -32,7 +32,7 @@ maybe_method = { ("." ~ function)* }
|
|||
|
||||
// Note that "x(y)" is a function call but "x (y)" concatenates "x" and "y"
|
||||
term = {
|
||||
("(" ~ term ~ ")") ~ maybe_method
|
||||
("(" ~ template ~ ")") ~ maybe_method
|
||||
| function ~ maybe_method
|
||||
| identifier ~ maybe_method
|
||||
| literal ~ maybe_method
|
||||
|
@ -40,8 +40,7 @@ term = {
|
|||
}
|
||||
|
||||
list = {
|
||||
("(" ~ list ~ ")")
|
||||
| term ~ (whitespace+ ~ term)+
|
||||
term ~ (whitespace+ ~ term)+
|
||||
}
|
||||
|
||||
template = {
|
||||
|
|
|
@ -349,6 +349,7 @@ fn parse_commit_term<'a>(
|
|||
name => panic!("function {name} not implemented"),
|
||||
}
|
||||
}
|
||||
Rule::template => parse_commit_template_rule(repo, workspace_id, expr),
|
||||
other => panic!("unexpected term: {other:?}"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,3 +76,30 @@ fn test_templater_branches() {
|
|||
o 000000000000
|
||||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_templater_parsed_tree() {
|
||||
let test_env = TestEnvironment::default();
|
||||
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
||||
let repo_path = test_env.env_root().join("repo");
|
||||
|
||||
// Parenthesized single term
|
||||
let stdout = test_env.jj_cmd_success(
|
||||
&repo_path,
|
||||
&["log", "--no-graph", "-r@-", "-T", r#"(commit_id.short())"#],
|
||||
);
|
||||
insta::assert_snapshot!(stdout, @"000000000000");
|
||||
|
||||
// Parenthesized multiple terms and concatenation
|
||||
let stdout = test_env.jj_cmd_success(
|
||||
&repo_path,
|
||||
&[
|
||||
"log",
|
||||
"--no-graph",
|
||||
"-r@-",
|
||||
"-T",
|
||||
r#"(commit_id.short() " ") empty"#,
|
||||
],
|
||||
);
|
||||
insta::assert_snapshot!(stdout, @"000000000000 true");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue