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.
|
|
|
|
|
2021-12-12 07:56:37 +00:00
|
|
|
non_period_identifier = @{ (ASCII_ALPHANUMERIC | "_" | "@" | "/")+ }
|
|
|
|
identifier = @{
|
|
|
|
(non_period_identifier+ ~ ".")+ ~ non_period_identifier+
|
|
|
|
| non_period_identifier+
|
|
|
|
}
|
2021-04-23 05:15:19 +00:00
|
|
|
symbol = {
|
|
|
|
identifier
|
|
|
|
| literal_string
|
|
|
|
}
|
2021-04-16 00:54:48 +00:00
|
|
|
literal_string = { "\"" ~ (!"\"" ~ ANY)+ ~ "\"" }
|
2021-04-18 21:48:47 +00:00
|
|
|
whitespace = _{ " " }
|
2021-04-14 23:54:27 +00:00
|
|
|
|
2021-12-13 06:40:16 +00:00
|
|
|
parents_op = { "-" }
|
2021-12-11 19:23:29 +00:00
|
|
|
children_op = { "+" }
|
|
|
|
|
2021-04-23 05:45:58 +00:00
|
|
|
// We could use the same rule name for the shared operators if we can
|
|
|
|
// think of a good name.
|
2021-12-12 07:50:26 +00:00
|
|
|
ancestors_op = { ":" }
|
|
|
|
descendants_op = { ":" }
|
|
|
|
dag_range_op = { ":" }
|
2021-12-12 07:56:37 +00:00
|
|
|
range_op = { ".." }
|
2021-04-21 21:51:23 +00:00
|
|
|
|
2021-04-21 20:42:37 +00:00
|
|
|
union_op = { "|" }
|
|
|
|
intersection_op = { "&" }
|
2021-12-13 06:40:16 +00:00
|
|
|
difference_op = { "~" }
|
2021-04-21 20:42:37 +00:00
|
|
|
infix_op = _{ union_op | intersection_op | difference_op }
|
2021-04-17 22:25:52 +00:00
|
|
|
|
2021-04-16 05:19:08 +00:00
|
|
|
function_name = @{ (ASCII_ALPHANUMERIC | "_")+ }
|
2021-04-16 00:54:48 +00:00
|
|
|
function_arguments = {
|
2021-04-23 17:37:42 +00:00
|
|
|
(whitespace* ~ expression ~ whitespace* ~ ",")* ~ whitespace* ~ expression ~ whitespace*
|
2021-04-18 21:48:47 +00:00
|
|
|
| whitespace*
|
2021-04-16 00:54:48 +00:00
|
|
|
}
|
|
|
|
|
2021-04-18 04:22:46 +00:00
|
|
|
primary = {
|
2021-04-17 22:25:52 +00:00
|
|
|
function_name ~ "(" ~ function_arguments ~ ")"
|
2021-04-18 04:22:46 +00:00
|
|
|
| "(" ~ expression ~ ")"
|
2021-04-17 22:25:52 +00:00
|
|
|
| symbol
|
2021-04-18 04:22:46 +00:00
|
|
|
}
|
|
|
|
|
2021-12-11 19:23:29 +00:00
|
|
|
neighbors_expression = { primary ~ (parents_op | children_op)* }
|
2021-04-17 22:25:52 +00:00
|
|
|
|
2021-04-23 05:45:58 +00:00
|
|
|
range_expression = {
|
2021-12-11 19:23:29 +00:00
|
|
|
neighbors_expression ~ dag_range_op ~ neighbors_expression
|
|
|
|
| neighbors_expression ~ range_op ~ neighbors_expression
|
|
|
|
| ancestors_op ~ neighbors_expression
|
|
|
|
| neighbors_expression ~ descendants_op
|
|
|
|
| neighbors_expression
|
2021-04-23 05:45:58 +00:00
|
|
|
}
|
2021-04-21 21:51:23 +00:00
|
|
|
|
2021-04-17 22:25:52 +00:00
|
|
|
infix_expression = {
|
2021-04-23 05:45:58 +00:00
|
|
|
whitespace* ~ range_expression ~ whitespace* ~ (infix_op ~ whitespace* ~ range_expression ~ whitespace*)*
|
2021-04-17 22:25:52 +00:00
|
|
|
}
|
|
|
|
|
2021-04-14 23:54:27 +00:00
|
|
|
expression = {
|
2021-04-18 21:48:47 +00:00
|
|
|
whitespace* ~ infix_expression ~ whitespace*
|
2021-04-14 23:54:27 +00:00
|
|
|
}
|