mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-08 13:39:56 +00:00
Because a unary negation node '~y' is more primitive than the corresponding difference node 'x~y', '~y' is easier to deal with while rewriting the tree. That's the main reason to add RevsetExpression::NotIn node. As we have a NotIn node, it makes sense to add an operator for that. This patch reuses '~' token, which I feel intuitive since the other set operators looks like bitwise ops. Another option is '!'. The unary '~' operator has the highest precedence among the set operators, but they are lower than the ranges. This might be counter intuitive, but useful because a prefix range ':x' can be negated without parens. Maybe we can remove the redundant infix operator 'x ~ y', but it isn't decided yet.
84 lines
2.4 KiB
Text
84 lines
2.4 KiB
Text
// Copyright 2021 The Jujutsu Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
identifier_part = @{ (ASCII_ALPHANUMERIC | "_" | "@" | "/")+ }
|
|
identifier = @{
|
|
identifier_part ~ ("." | "-" | "+" ) ~ identifier
|
|
| identifier_part
|
|
}
|
|
symbol = {
|
|
identifier
|
|
| literal_string
|
|
}
|
|
literal_string = { "\"" ~ (!"\"" ~ ANY)* ~ "\"" }
|
|
whitespace = _{ " " }
|
|
|
|
parents_op = { "-" }
|
|
children_op = { "+" }
|
|
|
|
dag_range_op = { ":" }
|
|
dag_range_pre_op = { ":" }
|
|
dag_range_post_op = { ":" }
|
|
range_op = { ".." }
|
|
range_pre_op = { ".." }
|
|
range_post_op = { ".." }
|
|
range_ops = _{ dag_range_op | range_op }
|
|
range_pre_ops = _{ dag_range_pre_op | range_pre_op }
|
|
range_post_ops = _{ dag_range_post_op | range_post_op }
|
|
|
|
negate_op = { "~" }
|
|
union_op = { "|" }
|
|
intersection_op = { "&" }
|
|
difference_op = { "~" }
|
|
infix_op = _{ union_op | intersection_op | difference_op }
|
|
|
|
function_name = @{ (ASCII_ALPHANUMERIC | "_")+ }
|
|
function_arguments = {
|
|
(whitespace* ~ expression ~ whitespace* ~ ",")* ~ whitespace* ~ expression ~ whitespace*
|
|
| whitespace*
|
|
}
|
|
formal_parameters = {
|
|
(whitespace* ~ identifier ~ whitespace* ~ ",")* ~ whitespace* ~ identifier ~ whitespace*
|
|
| whitespace*
|
|
}
|
|
|
|
primary = {
|
|
function_name ~ "(" ~ function_arguments ~ ")"
|
|
| "(" ~ expression ~ ")"
|
|
| symbol
|
|
}
|
|
|
|
neighbors_expression = _{ primary ~ (parents_op | children_op)* }
|
|
|
|
range_expression = _{
|
|
neighbors_expression ~ range_ops ~ neighbors_expression
|
|
| neighbors_expression ~ range_post_ops
|
|
| range_pre_ops ~ neighbors_expression
|
|
| neighbors_expression
|
|
}
|
|
|
|
expression = {
|
|
whitespace* ~ (negate_op ~ whitespace*)* ~ range_expression ~ whitespace*
|
|
~ (infix_op ~ whitespace* ~ (negate_op ~ whitespace*)* ~ range_expression ~ whitespace*)*
|
|
}
|
|
|
|
program = _{ SOI ~ expression ~ EOI }
|
|
|
|
alias_declaration_part = _{
|
|
function_name ~ "(" ~ formal_parameters ~ ")"
|
|
| identifier
|
|
}
|
|
alias_declaration = _{
|
|
SOI ~ alias_declaration_part ~ EOI
|
|
}
|