Debian Codegraph @

lib/src/fileset.pest

raw
1 // Copyright 2021-2024 The Jujutsu Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 whitespace = _{ " " | "\t" | "\r" | "\n" | "\x0c" }
16
17 // XID_CONTINUE: https://www.unicode.org/reports/tr31/#Default_Identifier_Syntax
18 // +, -, ., @, _: commonly used in file name including "." and ".."
19 // *, ?, [, ]: glob characters (not extended glob)
20 // /: path separator
21 // \: path separator (Windows)
22 identifier = @{
23 (XID_CONTINUE | "+" | "-" | "." | "@" | "_" | "*" | "?" | "[" | "]" | "/" | "\\")+
24 }
25 strict_identifier_part = @{ (ASCII_ALPHANUMERIC | "_")+ }
26 strict_identifier = @{
27 strict_identifier_part ~ ("-" ~ strict_identifier_part)*
28 }
29
30 // TODO: accept more ASCII meta characters such as "#" and ","?
31 bare_string = @{
32 ( ASCII_ALPHANUMERIC
33 | " " | "+" | "-" | "." | "@" | "_" | "*" | "?" | "[" | "]" | "/" | "\\"
34 | '\u{80}'..'\u{10ffff}' )+
35 }
36
37 string_escape = @{
38 "\\"
39 ~ ("t" | "r" | "n" | "0" | "e" | ("x" ~ ASCII_HEX_DIGIT{2}) | "\"" | "\\")
40 }
41 string_content_char = @{ !("\"" | "\\") ~ ANY }
42 string_content = @{ string_content_char+ }
43 string_literal = ${ "\"" ~ (string_content | string_escape)* ~ "\"" }
44
45 raw_string_content = @{ (!"'" ~ ANY)* }
46 raw_string_literal = ${ "'" ~ raw_string_content ~ "'" }
47
48 pattern_kind_op = { ":" }
49
50 negate_op = { "~" }
51 union_op = { "|" }
52 intersection_op = { "&" }
53 difference_op = { "~" }
54 prefix_ops = _{ negate_op }
55 infix_ops = _{ union_op | intersection_op | difference_op }
56
57 function = { function_name ~ "(" ~ whitespace* ~ function_arguments ~ whitespace* ~ ")" }
58 function_name = @{ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")* }
59 function_arguments = {
60 expression ~ (whitespace* ~ "," ~ whitespace* ~ expression)* ~ (whitespace* ~ ",")?
61 | ""
62 }
63 formal_parameters = {
64 strict_identifier ~ (whitespace* ~ "," ~ whitespace* ~ strict_identifier)* ~ (whitespace* ~ ",")?
65 | ""
66 }
67
68 pattern = { strict_identifier ~ pattern_kind_op ~ primary }
69 bare_string_pattern = { strict_identifier ~ pattern_kind_op ~ bare_string }
70
71 primary = {
72 "(" ~ whitespace* ~ expression ~ whitespace* ~ ")"
73 | function
74 | pattern
75 | identifier
76 | string_literal
77 | raw_string_literal
78 }
79
80 expression = {
81 (prefix_ops ~ whitespace*)* ~ primary
82 ~ (whitespace* ~ infix_ops ~ whitespace* ~ (prefix_ops ~ whitespace*)* ~ primary)*
83 }
84
85 program = _{ SOI ~ whitespace* ~ expression ~ whitespace* ~ EOI }
86 program_or_bare_string = _{
87 SOI ~ ( whitespace* ~ expression ~ whitespace* ~ EOI
88 | bare_string_pattern ~ EOI
89 | bare_string ~ EOI )
90 }
91
92 function_alias_declaration = {
93 function_name ~ "(" ~ whitespace* ~ formal_parameters ~ whitespace* ~ ")"
94 }
95 pattern_alias_declaration = {
96 strict_identifier ~ pattern_kind_op ~ strict_identifier
97 }
98 alias_declaration = _{
99 SOI ~ (function_alias_declaration
100 | pattern_alias_declaration
101 | strict_identifier) ~ EOI
102 }