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-04-23 05:15:19 +00:00
|
|
|
identifier = @{ (ASCII_ALPHANUMERIC | "@" | "/" | ".")+ }
|
|
|
|
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-04-21 20:42:37 +00:00
|
|
|
parents_op = { ":" }
|
|
|
|
ancestors_op = { "*:" }
|
|
|
|
prefix_op = _{ parents_op | ancestors_op }
|
2021-04-14 23:54:27 +00:00
|
|
|
|
2021-04-21 21:51:23 +00:00
|
|
|
children_op = { ":" }
|
|
|
|
descendants_op = { ":*" }
|
|
|
|
postfix_op = _{ descendants_op | children_op }
|
|
|
|
|
2021-04-21 20:42:37 +00:00
|
|
|
union_op = { "|" }
|
|
|
|
intersection_op = { "&" }
|
|
|
|
difference_op = { "-" }
|
|
|
|
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-04-21 20:42:37 +00:00
|
|
|
prefix_expression = { prefix_op* ~ primary }
|
2021-04-17 22:25:52 +00:00
|
|
|
|
2021-04-21 21:51:23 +00:00
|
|
|
postfix_expression = { prefix_expression ~ postfix_op* }
|
|
|
|
|
2021-04-17 22:25:52 +00:00
|
|
|
infix_expression = {
|
2021-04-21 21:51:23 +00:00
|
|
|
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 = {
|
2021-04-18 21:48:47 +00:00
|
|
|
whitespace* ~ infix_expression ~ whitespace*
|
2021-04-14 23:54:27 +00:00
|
|
|
}
|