// Copyright 2021 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. // If making significant changes to this grammar, consider also updating the// tree-sitter grammar: https://github.com/bryceberger/tree-sitter-jjrevset whitespace = _{ " " | "\t" | "\r" | "\n" | "\x0c" } // XID_CONTINUE: https://www.unicode.org/reports/tr31/#Default_Identifier_Syntax// +, -, .: often included in tag/bookmark name or version number// /: sometimes used as a tag/bookmark namespace separatoridentifier_part = @{ (XID_CONTINUE | "_" | "/")+ }identifier = @{ identifier_part ~ (("." | "-" | "+") ~ identifier_part)*}// TODO: remove "/", ".", "+" for consistency with fileset?strict_identifier_part = @{ (ASCII_ALPHANUMERIC | "_" | "/")+ }strict_identifier = @{ strict_identifier_part ~ (("." | "-" | "+") ~ strict_identifier_part)*} symbol = _{ identifier | string_literal | raw_string_literal} string_escape = @{ "\\" ~ ("t" | "r" | "n" | "0" | "e" | ("x" ~ ASCII_HEX_DIGIT{2}) | "\"" | "\\")}string_content_char = @{ !("\"" | "\\") ~ ANY }string_content = @{ string_content_char+ }string_literal = ${ "\"" ~ (string_content | string_escape)* ~ "\"" } raw_string_content = @{ (!"'" ~ ANY)* }raw_string_literal = ${ "'" ~ raw_string_content ~ "'" } at_op = { "@" }pattern_kind_op = { ":" } parents_op = { "-" }children_op = { "+" }compat_parents_op = { "^" } dag_range_op = { "::" }dag_range_pre_op = { "::" }dag_range_post_op = { "::" }dag_range_all_op = { "::" }compat_dag_range_op = { ":" }compat_dag_range_pre_op = { ":" }compat_dag_range_post_op = { ":" }range_op = { ".." }range_pre_op = { ".." }range_post_op = { ".." }range_all_op = { ".." }range_ops = _{ dag_range_op | compat_dag_range_op | range_op }range_pre_ops = _{ dag_range_pre_op | compat_dag_range_pre_op | range_pre_op }range_post_ops = _{ dag_range_post_op | compat_dag_range_post_op | range_post_op }range_all_ops = _{ dag_range_all_op | range_all_op } negate_op = { "~" }union_op = { "|" }intersection_op = { "&" }difference_op = { "~" }compat_add_op = { "+" }compat_sub_op = { "-" }infix_op = _{ union_op | intersection_op | difference_op | compat_add_op | compat_sub_op } function = { function_name ~ "(" ~ whitespace* ~ function_arguments ~ whitespace* ~ ")" }function_name = @{ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")* }keyword_argument = { strict_identifier ~ whitespace* ~ "=" ~ whitespace* ~ expression }argument = _{ keyword_argument | expression }function_arguments = { argument ~ (whitespace* ~ "," ~ whitespace* ~ argument)* ~ (whitespace* ~ ",")? | ""}formal_parameters = { strict_identifier ~ (whitespace* ~ "," ~ whitespace* ~ strict_identifier)* ~ (whitespace* ~ ",")? | ""} string_pattern = { strict_identifier ~ pattern_kind_op ~ symbol } primary = { "(" ~ whitespace* ~ expression ~ whitespace* ~ ")" | function | string_pattern // "@" operator cannot be nested | symbol ~ at_op ~ symbol | symbol ~ at_op | symbol | at_op} neighbors_expression = _{ primary ~ (parents_op | children_op | compat_parents_op)* } range_expression = _{ neighbors_expression ~ range_ops ~ neighbors_expression | neighbors_expression ~ range_post_ops | range_pre_ops ~ neighbors_expression | neighbors_expression | range_all_ops} expression = { (negate_op ~ whitespace*)* ~ range_expression ~ (whitespace* ~ infix_op ~ whitespace* ~ (negate_op ~ whitespace*)* ~ range_expression)*} program_modifier = { strict_identifier ~ pattern_kind_op ~ !":" }program = _{ SOI ~ whitespace* ~ (program_modifier ~ whitespace*)? ~ expression ~ whitespace* ~ EOI} symbol_name = _{ SOI ~ symbol ~ EOI } function_alias_declaration = { function_name ~ "(" ~ whitespace* ~ formal_parameters ~ whitespace* ~ ")"}alias_declaration = _{ SOI ~ (function_alias_declaration | strict_identifier) ~ EOI}
// Copyright 2021 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.
// If making significant changes to this grammar, consider also updating the
// tree-sitter grammar: https://github.com/bryceberger/tree-sitter-jjrevset
whitespace = _{ " " | "\t" | "\r" | "\n" | "\x0c" }
// XID_CONTINUE: https://www.unicode.org/reports/tr31/#Default_Identifier_Syntax
// +, -, .: often included in tag/bookmark name or version number
// /: sometimes used as a tag/bookmark namespace separator
identifier_part = @{ (XID_CONTINUE | "_" | "/")+ }
identifier = @{
identifier_part ~ (("." | "-" | "+") ~ identifier_part)*
}
// TODO: remove "/", ".", "+" for consistency with fileset?
strict_identifier_part = @{ (ASCII_ALPHANUMERIC | "_" | "/")+ }
strict_identifier = @{
strict_identifier_part ~ (("." | "-" | "+") ~ strict_identifier_part)*
}
symbol = _{
identifier
| string_literal
| raw_string_literal
}
string_escape = @{
"\\"
~ ("t" | "r" | "n" | "0" | "e" | ("x" ~ ASCII_HEX_DIGIT{2}) | "\"" | "\\")
}
string_content_char = @{ !("\"" | "\\") ~ ANY }
string_content = @{ string_content_char+ }
string_literal = ${ "\"" ~ (string_content | string_escape)* ~ "\"" }
raw_string_content = @{ (!"'" ~ ANY)* }
raw_string_literal = ${ "'" ~ raw_string_content ~ "'" }
at_op = { "@" }
pattern_kind_op = { ":" }
parents_op = { "-" }
children_op = { "+" }
compat_parents_op = { "^" }
dag_range_op = { "::" }
dag_range_pre_op = { "::" }
dag_range_post_op = { "::" }
dag_range_all_op = { "::" }
compat_dag_range_op = { ":" }
compat_dag_range_pre_op = { ":" }
compat_dag_range_post_op = { ":" }
range_op = { ".." }
range_pre_op = { ".." }
range_post_op = { ".." }
range_all_op = { ".." }
range_ops = _{ dag_range_op | compat_dag_range_op | range_op }
range_pre_ops = _{ dag_range_pre_op | compat_dag_range_pre_op | range_pre_op }
range_post_ops = _{ dag_range_post_op | compat_dag_range_post_op | range_post_op }
range_all_ops = _{ dag_range_all_op | range_all_op }
negate_op = { "~" }
union_op = { "|" }
intersection_op = { "&" }
difference_op = { "~" }
compat_add_op = { "+" }
compat_sub_op = { "-" }
infix_op = _{ union_op | intersection_op | difference_op | compat_add_op | compat_sub_op }
function = { function_name ~ "(" ~ whitespace* ~ function_arguments ~ whitespace* ~ ")" }
function_name = @{ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")* }
keyword_argument = { strict_identifier ~ whitespace* ~ "=" ~ whitespace* ~ expression }
argument = _{ keyword_argument | expression }
function_arguments = {
argument ~ (whitespace* ~ "," ~ whitespace* ~ argument)* ~ (whitespace* ~ ",")?
| ""
}
formal_parameters = {
strict_identifier ~ (whitespace* ~ "," ~ whitespace* ~ strict_identifier)* ~ (whitespace* ~ ",")?
| ""
}
string_pattern = { strict_identifier ~ pattern_kind_op ~ symbol }
primary = {
"(" ~ whitespace* ~ expression ~ whitespace* ~ ")"
| function
| string_pattern
// "@" operator cannot be nested
| symbol ~ at_op ~ symbol
| symbol ~ at_op
| symbol
| at_op
}
neighbors_expression = _{ primary ~ (parents_op | children_op | compat_parents_op)* }
range_expression = _{
neighbors_expression ~ range_ops ~ neighbors_expression
| neighbors_expression ~ range_post_ops
| range_pre_ops ~ neighbors_expression
| neighbors_expression
| range_all_ops
}
expression = {
(negate_op ~ whitespace*)* ~ range_expression
~ (whitespace* ~ infix_op ~ whitespace* ~ (negate_op ~ whitespace*)* ~ range_expression)*
}
program_modifier = { strict_identifier ~ pattern_kind_op ~ !":" }
program = _{
SOI ~ whitespace* ~ (program_modifier ~ whitespace*)? ~ expression ~ whitespace* ~ EOI
}
symbol_name = _{ SOI ~ symbol ~ EOI }
function_alias_declaration = {
function_name ~ "(" ~ whitespace* ~ formal_parameters ~ whitespace* ~ ")"
}
alias_declaration = _{
SOI ~ (function_alias_declaration | strict_identifier) ~ EOI
}