forked from mirrors/jj
9d356b8094
This is basically a copy of revset::RevsetAliasesMap. We could extract a common table struct, but that wouldn't be worth the effort since the core alias substitution logic can't be easily abstracted.
70 lines
1.9 KiB
Text
70 lines
1.9 KiB
Text
// Copyright 2020 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.
|
|
|
|
// Example:
|
|
// "commit: " short(commit_id) "\n"
|
|
// predecessors % ("predecessor: " commit_id)
|
|
// parents % (commit_id " is a parent of " super.commit_id)
|
|
|
|
whitespace = _{ " " | "\n" }
|
|
|
|
escape = @{ "\\" ~ ("n" | "\"" | "\\") }
|
|
literal_char = @{ !("\"" | "\\") ~ ANY }
|
|
raw_literal = @{ literal_char+ }
|
|
literal = { "\"" ~ (raw_literal | escape)* ~ "\"" }
|
|
|
|
integer_literal = {
|
|
ASCII_NONZERO_DIGIT ~ ASCII_DIGIT*
|
|
| "0"
|
|
}
|
|
|
|
identifier = @{ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")* }
|
|
|
|
function = { identifier ~ "(" ~ whitespace* ~ function_arguments ~ whitespace* ~ ")" }
|
|
function_arguments = {
|
|
template ~ (whitespace* ~ "," ~ whitespace* ~ template)* ~ (whitespace* ~ ",")?
|
|
| ""
|
|
}
|
|
formal_parameters = {
|
|
identifier ~ (whitespace* ~ "," ~ whitespace* ~ identifier)* ~ (whitespace* ~ ",")?
|
|
| ""
|
|
}
|
|
|
|
// Note that "x(y)" is a function call but "x (y)" concatenates "x" and "y"
|
|
primary = _{
|
|
("(" ~ whitespace* ~ template ~ whitespace* ~ ")")
|
|
| function
|
|
| identifier
|
|
| literal
|
|
| integer_literal
|
|
}
|
|
|
|
term = {
|
|
primary ~ ("." ~ function)*
|
|
}
|
|
|
|
list = _{
|
|
term ~ (whitespace+ ~ term)+
|
|
}
|
|
|
|
template = { list | term }
|
|
|
|
program = _{ SOI ~ whitespace* ~ template? ~ whitespace* ~ EOI }
|
|
|
|
function_alias_declaration = {
|
|
identifier ~ "(" ~ whitespace* ~ formal_parameters ~ whitespace* ~ ")"
|
|
}
|
|
alias_declaration = _{
|
|
SOI ~ (function_alias_declaration | identifier) ~ EOI
|
|
}
|