mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-27 14:57:14 +00:00
revsets: allow spaces in most places (but not after prefix operators)
This commit is contained in:
parent
c04f418e67
commit
2ac5d1f912
3 changed files with 33 additions and 9 deletions
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
symbol = @{ (ASCII_ALPHANUMERIC | "@" | "/" | ".")+ }
|
symbol = @{ (ASCII_ALPHANUMERIC | "@" | "/" | ".")+ }
|
||||||
literal_string = { "\"" ~ (!"\"" ~ ANY)+ ~ "\"" }
|
literal_string = { "\"" ~ (!"\"" ~ ANY)+ ~ "\"" }
|
||||||
|
whitespace = _{ " " }
|
||||||
|
|
||||||
parents = { ":" }
|
parents = { ":" }
|
||||||
ancestors = { "*:" }
|
ancestors = { "*:" }
|
||||||
|
@ -35,8 +36,8 @@ function_argument = {
|
||||||
| expression
|
| expression
|
||||||
}
|
}
|
||||||
function_arguments = {
|
function_arguments = {
|
||||||
(function_argument ~ ",")* ~ function_argument
|
(whitespace* ~ function_argument ~ whitespace* ~ ",")* ~ whitespace* ~ function_argument ~ whitespace*
|
||||||
| ""
|
| whitespace*
|
||||||
}
|
}
|
||||||
|
|
||||||
primary = {
|
primary = {
|
||||||
|
@ -48,9 +49,9 @@ primary = {
|
||||||
prefix_expression = { prefix_operator* ~ primary }
|
prefix_expression = { prefix_operator* ~ primary }
|
||||||
|
|
||||||
infix_expression = {
|
infix_expression = {
|
||||||
prefix_expression ~ (infix_operator ~ prefix_expression)*
|
whitespace* ~ prefix_expression ~ whitespace* ~ (infix_operator ~ whitespace* ~ prefix_expression ~ whitespace*)*
|
||||||
}
|
}
|
||||||
|
|
||||||
expression = {
|
expression = {
|
||||||
infix_expression
|
whitespace* ~ infix_expression ~ whitespace*
|
||||||
}
|
}
|
||||||
|
|
|
@ -343,6 +343,8 @@ fn parse_function_argument_to_string(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse(revset_str: &str) -> Result<RevsetExpression, RevsetParseError> {
|
pub fn parse(revset_str: &str) -> Result<RevsetExpression, RevsetParseError> {
|
||||||
|
// TODO: Return a better error message when parsing fails (such as when the user
|
||||||
|
// puts whitespace between a prefix operator and the operand)
|
||||||
let mut pairs: Pairs<Rule> = RevsetParser::parse(Rule::expression, revset_str).unwrap();
|
let mut pairs: Pairs<Rule> = RevsetParser::parse(Rule::expression, revset_str).unwrap();
|
||||||
let first = pairs.next().unwrap();
|
let first = pairs.next().unwrap();
|
||||||
assert!(pairs.next().is_none());
|
assert!(pairs.next().is_none());
|
||||||
|
|
|
@ -255,6 +255,27 @@ fn test_parse_revset() {
|
||||||
RevsetExpression::Symbol("@".to_string())
|
RevsetExpression::Symbol("@".to_string())
|
||||||
)))
|
)))
|
||||||
);
|
);
|
||||||
|
assert_eq!(
|
||||||
|
parse(" *:@ "),
|
||||||
|
Ok(RevsetExpression::Ancestors(Box::new(
|
||||||
|
RevsetExpression::Symbol("@".to_string())
|
||||||
|
)))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
parse(" description( arg1 , arg2 ) - parents( arg1 ) - all_heads( ) "),
|
||||||
|
Ok(RevsetExpression::Difference(
|
||||||
|
Box::new(RevsetExpression::Difference(
|
||||||
|
Box::new(RevsetExpression::Description {
|
||||||
|
needle: "arg1".to_string(),
|
||||||
|
base_expression: Box::new(RevsetExpression::Symbol("arg2".to_string()))
|
||||||
|
}),
|
||||||
|
Box::new(RevsetExpression::Parents(Box::new(
|
||||||
|
RevsetExpression::Symbol("arg1".to_string())
|
||||||
|
)))
|
||||||
|
)),
|
||||||
|
Box::new(RevsetExpression::AllHeads)
|
||||||
|
))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue