forked from jj-vcs/jj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrevset.pest
103 lines (91 loc) · 3.12 KB
/
revset.pest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright 2021 The Jujutsu Authors
//
// 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_part = @{ (ASCII_ALPHANUMERIC | "_" | "/")+ }
identifier = @{
identifier_part ~ ("." | "-" | "+" ) ~ identifier
| identifier_part
}
symbol = {
identifier
| literal_string
}
literal_string = { "\"" ~ (!"\"" ~ ANY)* ~ "\"" }
whitespace = _{ " " | "\t" | "\r" | "\n" | "\x0c" }
at_op = { "@" }
parents_op = { "-" }
children_op = { "+" }
compat_parents_op = { "^" }
dag_range_op = { "::" }
dag_range_pre_op = { "::" }
dag_range_post_op = { "::" }
dag_range_all_op = { "::" }
// TODO: Drop support for these in 0.15+
legacy_dag_range_op = { ":" }
legacy_dag_range_pre_op = { ":" }
legacy_dag_range_post_op = { ":" }
range_op = { ".." }
range_pre_op = { ".." }
range_post_op = { ".." }
range_all_op = { ".." }
range_ops = _{ dag_range_op | legacy_dag_range_op | range_op }
range_pre_ops = _{ dag_range_pre_op | legacy_dag_range_pre_op | range_pre_op }
range_post_ops = _{ dag_range_post_op | legacy_dag_range_post_op | range_post_op }
range_all_ops = _{ dag_range_all_op | range_all_op }
negate_op = { "~" }
union_op = { "|" }
intersection_op = { "&" }
difference_op = { "~" }
compat_add_op = { "+" }
compat_sub_op = { "-" }
infix_op = _{ union_op | intersection_op | difference_op | compat_add_op | compat_sub_op }
function_name = @{ (ASCII_ALPHANUMERIC | "_")+ }
keyword_argument = { identifier ~ whitespace* ~ "=" ~ whitespace* ~ expression }
argument = _{ keyword_argument | expression }
function_arguments = {
argument ~ (whitespace* ~ "," ~ whitespace* ~ argument)* ~ (whitespace* ~ ",")?
| ""
}
formal_parameters = {
identifier ~ (whitespace* ~ "," ~ whitespace* ~ identifier)* ~ (whitespace* ~ ",")?
| ""
}
primary = {
function_name ~ "(" ~ whitespace* ~ function_arguments ~ whitespace* ~ ")"
| "(" ~ whitespace* ~ expression ~ whitespace* ~ ")"
// "@" operator cannot be nested
| symbol ~ at_op ~ symbol
| symbol ~ at_op
| symbol
| at_op
}
neighbors_expression = _{ primary ~ (parents_op | children_op | compat_parents_op)* }
range_expression = _{
neighbors_expression ~ range_ops ~ neighbors_expression
| neighbors_expression ~ range_post_ops
| range_pre_ops ~ neighbors_expression
| neighbors_expression
| range_all_ops
}
expression = {
(negate_op ~ whitespace*)* ~ range_expression
~ (whitespace* ~ infix_op ~ whitespace* ~ (negate_op ~ whitespace*)* ~ range_expression)*
}
program = _{ SOI ~ whitespace* ~ expression ~ whitespace* ~ EOI }
alias_declaration_part = _{
function_name ~ "(" ~ whitespace* ~ formal_parameters ~ whitespace* ~ ")"
| identifier
}
alias_declaration = _{
SOI ~ alias_declaration_part ~ EOI
}