2022-11-26 23:57:50 +00:00
|
|
|
// Copyright 2020 The Jujutsu Authors
|
2020-12-12 08:00:42 +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.
|
|
|
|
|
|
|
|
// Example:
|
2023-02-28 11:30:57 +00:00
|
|
|
// "commit: " ++ short(commit_id) ++ "\n"
|
2023-03-07 10:14:00 +00:00
|
|
|
// predecessors.map(|p| "predecessor: " ++ p.commit_id)
|
|
|
|
// parents.map(|p| p.commit_id ++ " is a parent of " ++ commit_id)
|
2020-12-12 08:00:42 +00:00
|
|
|
|
2023-03-03 07:13:22 +00:00
|
|
|
whitespace = _{ " " | "\t" | "\r" | "\n" | "\x0c" }
|
2020-12-12 08:00:42 +00:00
|
|
|
|
2024-04-07 06:38:20 +00:00
|
|
|
string_escape = @{ "\\" ~ ("t" | "r" | "n" | "0" | "\"" | "\\") }
|
|
|
|
string_content_char = @{ !("\"" | "\\") ~ ANY }
|
|
|
|
string_content = @{ string_content_char+ }
|
2024-04-07 06:58:39 +00:00
|
|
|
string_literal = ${ "\"" ~ (string_content | string_escape)* ~ "\"" }
|
2020-12-12 08:00:42 +00:00
|
|
|
|
2024-04-17 12:17:40 +00:00
|
|
|
raw_string_content = @{ (!"'" ~ ANY)* }
|
|
|
|
raw_string_literal = ${ "'" ~ raw_string_content ~ "'" }
|
|
|
|
|
2024-04-07 06:58:39 +00:00
|
|
|
integer_literal = @{
|
2024-02-06 12:57:59 +00:00
|
|
|
ASCII_NONZERO_DIGIT ~ ASCII_DIGIT*
|
|
|
|
| "0"
|
2023-02-04 12:36:11 +00:00
|
|
|
}
|
|
|
|
|
2023-02-04 12:33:31 +00:00
|
|
|
identifier = @{ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")* }
|
2020-12-12 08:00:42 +00:00
|
|
|
|
2024-02-07 11:31:53 +00:00
|
|
|
concat_op = { "++" }
|
2024-02-05 10:30:12 +00:00
|
|
|
logical_or_op = { "||" }
|
|
|
|
logical_and_op = { "&&" }
|
|
|
|
logical_not_op = { "!" }
|
2024-02-06 12:57:59 +00:00
|
|
|
negate_op = { "-" }
|
|
|
|
prefix_ops = _{ logical_not_op | negate_op }
|
2024-02-05 10:30:12 +00:00
|
|
|
infix_ops = _{ logical_or_op | logical_and_op }
|
|
|
|
|
2023-02-09 09:32:29 +00:00
|
|
|
function = { identifier ~ "(" ~ whitespace* ~ function_arguments ~ whitespace* ~ ")" }
|
2023-01-29 03:39:51 +00:00
|
|
|
function_arguments = {
|
2023-02-09 09:32:29 +00:00
|
|
|
template ~ (whitespace* ~ "," ~ whitespace* ~ template)* ~ (whitespace* ~ ",")?
|
|
|
|
| ""
|
2023-01-29 03:39:51 +00:00
|
|
|
}
|
2023-03-07 10:14:00 +00:00
|
|
|
lambda = {
|
|
|
|
"|" ~ whitespace* ~ formal_parameters ~ whitespace* ~ "|"
|
|
|
|
~ whitespace* ~ template
|
|
|
|
}
|
2023-02-12 08:21:06 +00:00
|
|
|
formal_parameters = {
|
|
|
|
identifier ~ (whitespace* ~ "," ~ whitespace* ~ identifier)* ~ (whitespace* ~ ",")?
|
|
|
|
| ""
|
|
|
|
}
|
2020-12-12 08:00:42 +00:00
|
|
|
|
2023-02-04 12:28:14 +00:00
|
|
|
primary = _{
|
2023-02-09 09:32:29 +00:00
|
|
|
("(" ~ whitespace* ~ template ~ whitespace* ~ ")")
|
2023-02-04 12:28:14 +00:00
|
|
|
| function
|
2023-03-07 10:14:00 +00:00
|
|
|
| lambda
|
2023-02-04 12:28:14 +00:00
|
|
|
| identifier
|
2024-04-07 06:38:20 +00:00
|
|
|
| string_literal
|
2024-04-17 12:17:40 +00:00
|
|
|
| raw_string_literal
|
2023-02-04 12:36:11 +00:00
|
|
|
| integer_literal
|
2023-02-04 12:28:14 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 08:00:42 +00:00
|
|
|
term = {
|
2023-02-04 12:28:14 +00:00
|
|
|
primary ~ ("." ~ function)*
|
2020-12-12 08:00:42 +00:00
|
|
|
}
|
|
|
|
|
2024-02-05 10:30:12 +00:00
|
|
|
expression = {
|
|
|
|
(prefix_ops ~ whitespace*)* ~ term
|
|
|
|
~ (whitespace* ~ infix_ops ~ whitespace* ~ (prefix_ops ~ whitespace*)* ~ term)*
|
|
|
|
}
|
|
|
|
|
2024-04-03 15:25:14 +00:00
|
|
|
template = {
|
|
|
|
expression ~ (whitespace* ~ concat_op ~ whitespace* ~ expression)*
|
2020-12-12 08:00:42 +00:00
|
|
|
}
|
|
|
|
|
2023-02-09 09:32:29 +00:00
|
|
|
program = _{ SOI ~ whitespace* ~ template? ~ whitespace* ~ EOI }
|
2023-02-12 08:21:06 +00:00
|
|
|
|
|
|
|
function_alias_declaration = {
|
|
|
|
identifier ~ "(" ~ whitespace* ~ formal_parameters ~ whitespace* ~ ")"
|
|
|
|
}
|
|
|
|
alias_declaration = _{
|
|
|
|
SOI ~ (function_alias_declaration | identifier) ~ EOI
|
|
|
|
}
|