forked from mirrors/jj
52 lines
1.5 KiB
Text
52 lines
1.5 KiB
Text
// Copyright 2020 Google LLC
|
|
//
|
|
// 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_ALPHANUMERIC | "_")+ }
|
|
|
|
function = { identifier ~ "(" ~ template ~ ("," ~ template)* ~ ")" }
|
|
|
|
method = { "." ~ identifier ~ "(" ~ template ~ ("," ~ template)* ~ ")" ~ maybe_method }
|
|
|
|
maybe_method = { method | "" }
|
|
|
|
// Note that "x(y)" is a function call but "x (y)" concatenates "x" and "y"
|
|
term = {
|
|
("(" ~ term ~ ")") ~ maybe_method
|
|
| function ~ maybe_method
|
|
| identifier ~ maybe_method
|
|
| literal ~ maybe_method
|
|
| ""
|
|
}
|
|
|
|
list = {
|
|
("(" ~ list ~ ")")
|
|
| term ~ (whitespace+ ~ term)+
|
|
}
|
|
|
|
template = {
|
|
list
|
|
| term
|
|
}
|