jj/src/template.pest

56 lines
1.5 KiB
Text
Raw Normal View History

// 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)* ~ "\"" }
identifier = @{ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")* }
function = { identifier ~ "(" ~ function_arguments ~ ")" }
function_arguments = {
template ~ ("," ~ template)*
| whitespace*
}
// Note that "x(y)" is a function call but "x (y)" concatenates "x" and "y"
primary = _{
("(" ~ template ~ ")")
| function
| identifier
| literal
}
term = {
primary ~ ("." ~ function)*
}
list = _{
term ~ (whitespace+ ~ term)+
}
template = {
whitespace* ~ (list | term) ~ whitespace*
}
program = _{ SOI ~ (template | whitespace*) ~ EOI }