ok/jj
1
0
Fork 0
forked from mirrors/jj
jj/lib/src/revset.pest
2021-12-11 23:47:34 -08:00

67 lines
1.9 KiB
Text

// Copyright 2021 Google LLC
//
// 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 = @{ (ASCII_ALPHANUMERIC | "_" | "@" | "/" | ".")+ }
symbol = {
identifier
| literal_string
}
literal_string = { "\"" ~ (!"\"" ~ ANY)+ ~ "\"" }
whitespace = _{ " " }
parents_op = { "~" }
children_op = { "+" }
// We could use the same rule name for the shared operators if we can
// think of a good name.
ancestors_op = { ",," }
descendants_op = { ",," }
dag_range_op = { ",," }
range_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*
}
primary = {
function_name ~ "(" ~ function_arguments ~ ")"
| "(" ~ expression ~ ")"
| symbol
}
neighbors_expression = { primary ~ (parents_op | children_op)* }
range_expression = {
neighbors_expression ~ dag_range_op ~ neighbors_expression
| neighbors_expression ~ range_op ~ neighbors_expression
| ancestors_op ~ neighbors_expression
| neighbors_expression ~ descendants_op
| neighbors_expression
}
infix_expression = {
whitespace* ~ range_expression ~ whitespace* ~ (infix_op ~ whitespace* ~ range_expression ~ whitespace*)*
}
expression = {
whitespace* ~ infix_expression ~ whitespace*
}