jj/lib/src/revset.pest

59 lines
1.6 KiB
Text
Raw Normal View History

2021-04-14 23:54:27 +00:00
// 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 = _{ " " }
2021-04-14 23:54:27 +00:00
parents_op = { ":" }
ancestors_op = { "*:" }
prefix_op = _{ parents_op | ancestors_op }
2021-04-14 23:54:27 +00:00
children_op = { ":" }
descendants_op = { ":*" }
postfix_op = _{ descendants_op | children_op }
union_op = { "|" }
intersection_op = { "&" }
difference_op = { "-" }
infix_op = _{ union_op | intersection_op | difference_op }
2021-04-17 22:25:52 +00:00
function_name = @{ (ASCII_ALPHANUMERIC | "_")+ }
function_arguments = {
(whitespace* ~ expression ~ whitespace* ~ ",")* ~ whitespace* ~ expression ~ whitespace*
| whitespace*
}
primary = {
function_name ~ "(" ~ function_arguments ~ ")"
| "(" ~ expression ~ ")"
| symbol
}
prefix_expression = { prefix_op* ~ primary }
postfix_expression = { prefix_expression ~ postfix_op* }
2021-04-17 22:25:52 +00:00
infix_expression = {
whitespace* ~ postfix_expression ~ whitespace* ~ (infix_op ~ whitespace* ~ postfix_expression ~ whitespace*)*
2021-04-17 22:25:52 +00:00
}
2021-04-14 23:54:27 +00:00
expression = {
whitespace* ~ infix_expression ~ whitespace*
2021-04-14 23:54:27 +00:00
}