2022-11-26 23:57:50 +00:00
|
|
|
// Copyright 2021 The Jujutsu Authors
|
2021-04-14 23:54:27 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2022-04-27 16:42:18 +00:00
|
|
|
identifier_part = @{ (ASCII_ALPHANUMERIC | "_" | "@" | "/")+ }
|
2021-12-12 07:56:37 +00:00
|
|
|
identifier = @{
|
2022-10-06 07:20:16 +00:00
|
|
|
identifier_part ~ ("." | "-" | "+" ) ~ identifier
|
|
|
|
| identifier_part
|
|
|
|
}
|
2021-04-23 05:15:19 +00:00
|
|
|
symbol = {
|
|
|
|
identifier
|
|
|
|
| literal_string
|
|
|
|
}
|
2022-11-20 03:06:09 +00:00
|
|
|
literal_string = { "\"" ~ (!"\"" ~ ANY)* ~ "\"" }
|
2023-03-03 07:25:39 +00:00
|
|
|
whitespace = _{ " " | "\t" | "\r" | "\n" | "\x0c" }
|
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 = { "+" }
|
2022-12-22 11:18:25 +00:00
|
|
|
compat_parents_op = { "^" }
|
2021-12-11 19:23:29 +00:00
|
|
|
|
2021-12-12 07:50:26 +00:00
|
|
|
dag_range_op = { ":" }
|
2022-11-16 11:46:53 +00:00
|
|
|
dag_range_pre_op = { ":" }
|
|
|
|
dag_range_post_op = { ":" }
|
2021-12-12 07:56:37 +00:00
|
|
|
range_op = { ".." }
|
2022-11-16 11:46:53 +00:00
|
|
|
range_pre_op = { ".." }
|
|
|
|
range_post_op = { ".." }
|
2022-11-16 11:42:04 +00:00
|
|
|
range_ops = _{ dag_range_op | range_op }
|
2022-11-16 11:46:53 +00:00
|
|
|
range_pre_ops = _{ dag_range_pre_op | range_pre_op }
|
|
|
|
range_post_ops = _{ dag_range_post_op | range_post_op }
|
2021-04-21 21:51:23 +00:00
|
|
|
|
2022-11-17 12:58:51 +00:00
|
|
|
negate_op = { "~" }
|
2021-04-21 20:42:37 +00:00
|
|
|
union_op = { "|" }
|
|
|
|
intersection_op = { "&" }
|
2021-12-13 06:40:16 +00:00
|
|
|
difference_op = { "~" }
|
2022-12-22 10:34:08 +00:00
|
|
|
compat_add_op = { "+" }
|
|
|
|
compat_sub_op = { "-" }
|
|
|
|
infix_op = _{ union_op | intersection_op | difference_op | compat_add_op | compat_sub_op }
|
2021-04-17 22:25:52 +00:00
|
|
|
|
2021-04-16 05:19:08 +00:00
|
|
|
function_name = @{ (ASCII_ALPHANUMERIC | "_")+ }
|
2023-02-08 09:55:15 +00:00
|
|
|
keyword_argument = { identifier ~ whitespace* ~ "=" ~ whitespace* ~ expression }
|
|
|
|
argument = _{ keyword_argument | expression }
|
2021-04-16 00:54:48 +00:00
|
|
|
function_arguments = {
|
2023-02-08 09:55:15 +00:00
|
|
|
argument ~ (whitespace* ~ "," ~ whitespace* ~ argument)* ~ (whitespace* ~ ",")?
|
2023-02-08 09:25:11 +00:00
|
|
|
| ""
|
2021-04-16 00:54:48 +00:00
|
|
|
}
|
2022-11-26 11:41:55 +00:00
|
|
|
formal_parameters = {
|
2023-02-08 09:25:11 +00:00
|
|
|
identifier ~ (whitespace* ~ "," ~ whitespace* ~ identifier)* ~ (whitespace* ~ ",")?
|
|
|
|
| ""
|
2022-11-26 11:41:55 +00:00
|
|
|
}
|
2021-04-16 00:54:48 +00:00
|
|
|
|
2021-04-18 04:22:46 +00:00
|
|
|
primary = {
|
2023-02-08 09:25:11 +00:00
|
|
|
function_name ~ "(" ~ whitespace* ~ function_arguments ~ whitespace* ~ ")"
|
|
|
|
| "(" ~ whitespace* ~ expression ~ whitespace* ~ ")"
|
2021-04-17 22:25:52 +00:00
|
|
|
| symbol
|
2021-04-18 04:22:46 +00:00
|
|
|
}
|
|
|
|
|
2022-12-22 11:18:25 +00:00
|
|
|
neighbors_expression = _{ primary ~ (parents_op | children_op | compat_parents_op)* }
|
2021-04-17 22:25:52 +00:00
|
|
|
|
2022-11-16 12:00:11 +00:00
|
|
|
range_expression = _{
|
2022-11-16 11:42:04 +00:00
|
|
|
neighbors_expression ~ range_ops ~ neighbors_expression
|
2022-11-16 11:46:53 +00:00
|
|
|
| neighbors_expression ~ range_post_ops
|
|
|
|
| range_pre_ops ~ neighbors_expression
|
2021-12-11 19:23:29 +00:00
|
|
|
| neighbors_expression
|
2021-04-23 05:45:58 +00:00
|
|
|
}
|
2021-04-21 21:51:23 +00:00
|
|
|
|
2021-04-14 23:54:27 +00:00
|
|
|
expression = {
|
2023-02-08 09:25:11 +00:00
|
|
|
(negate_op ~ whitespace*)* ~ range_expression
|
|
|
|
~ (whitespace* ~ infix_op ~ whitespace* ~ (negate_op ~ whitespace*)* ~ range_expression)*
|
2021-04-14 23:54:27 +00:00
|
|
|
}
|
2022-11-16 07:47:00 +00:00
|
|
|
|
2023-02-08 09:25:11 +00:00
|
|
|
program = _{ SOI ~ whitespace* ~ expression ~ whitespace* ~ EOI }
|
2022-11-25 03:53:01 +00:00
|
|
|
|
2022-11-26 11:41:55 +00:00
|
|
|
alias_declaration_part = _{
|
2023-02-08 09:25:11 +00:00
|
|
|
function_name ~ "(" ~ whitespace* ~ formal_parameters ~ whitespace* ~ ")"
|
2022-11-26 11:41:55 +00:00
|
|
|
| identifier
|
|
|
|
}
|
2022-11-25 03:53:01 +00:00
|
|
|
alias_declaration = _{
|
2022-11-26 11:41:55 +00:00
|
|
|
SOI ~ alias_declaration_part ~ EOI
|
2022-11-25 03:53:01 +00:00
|
|
|
}
|