diff --git a/lib/src/revset.pest b/lib/src/revset.pest index 2461f8d0b..39971ffec 100644 --- a/lib/src/revset.pest +++ b/lib/src/revset.pest @@ -18,7 +18,7 @@ identifier_part = @{ (ASCII_ALPHANUMERIC | "_" | "/")+ } identifier = @{ identifier_part ~ (("." | "-" | "+") ~ identifier_part)* } -symbol = { +symbol = _{ identifier | string_literal | raw_string_literal diff --git a/lib/src/revset_parser.rs b/lib/src/revset_parser.rs index 0cc4164b9..f7ab8fcee 100644 --- a/lib/src/revset_parser.rs +++ b/lib/src/revset_parser.rs @@ -585,32 +585,29 @@ fn parse_primary_node(pair: Pair) -> Result { - let pairs = first.into_inner(); - let first = pairs.peek().unwrap(); - match first.as_rule() { - Rule::identifier => ExpressionKind::Identifier(first.as_str()), - _ => ExpressionKind::String(parse_as_string_literal(pairs)), - } - } - Rule::symbol => { - let name = parse_as_string_literal(first.into_inner()); - assert_eq!(pairs.next().unwrap().as_rule(), Rule::at_op); - if let Some(second) = pairs.next() { - // infix "@" - assert_eq!(second.as_rule(), Rule::symbol); - let remote = parse_as_string_literal(second.into_inner()); - ExpressionKind::RemoteSymbol { name, remote } - } else { - // postfix "@" - ExpressionKind::AtWorkspace(name) + Rule::identifier if pairs.peek().is_none() => ExpressionKind::Identifier(first.as_str()), + Rule::identifier | Rule::string_literal | Rule::raw_string_literal => { + let name = parse_as_string_literal(first); + match pairs.next() { + None => ExpressionKind::String(name), + Some(op) => { + assert_eq!(op.as_rule(), Rule::at_op); + match pairs.next() { + // postfix "@" + None => ExpressionKind::AtWorkspace(name), + // infix "@" + Some(second) => { + let remote = parse_as_string_literal(second); + ExpressionKind::RemoteSymbol { name, remote } + } + } + } } } // nullary "@" @@ -621,18 +618,17 @@ fn parse_primary_node(pair: Pair) -> Result) -> String { - let first = pairs.next().unwrap(); - match first.as_rule() { - Rule::identifier => first.as_str().to_owned(), - Rule::string_literal => STRING_LITERAL_PARSER.parse(first.into_inner()), +fn parse_as_string_literal(pair: Pair) -> String { + match pair.as_rule() { + Rule::identifier => pair.as_str().to_owned(), + Rule::string_literal => STRING_LITERAL_PARSER.parse(pair.into_inner()), Rule::raw_string_literal => { - let (content,) = first.into_inner().collect_tuple().unwrap(); + let (content,) = pair.into_inner().collect_tuple().unwrap(); assert_eq!(content.as_rule(), Rule::raw_string_content); content.as_str().to_owned() } _ => { - panic!("unexpected symbol parse rule: {:?}", first.as_str()); + panic!("unexpected string literal rule: {:?}", pair.as_str()); } } }