138 lines · 3.4 KB · Text
RawDownload
// 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.map(|p| "predecessor: " ++ p.commit_id)// parents.map(|p| p.commit_id ++ " is a parent of " ++ commit_id) // If making significant changes to this grammar, consider also updating the// tree-sitter grammar: https://github.com/bryceberger/tree-sitter-jjtemplate WHITESPACE = _{ " " | "\t" | "\r" | "\n" | "\x0c" } 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 ~ "'" } integer_literal = @{  ASCII_NONZERO_DIGIT ~ ASCII_DIGIT*  | "0"} identifier = @{ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")* } concat_op = { "++" }logical_or_op = { "||" }logical_and_op = { "&&" }eq_op = { "==" }ne_op = { "!=" }ge_op = { ">=" }gt_op = { ">" }le_op = { "<=" }lt_op = { "<" }add_op = { "+" }sub_op = { "-" }mul_op = { "*" }div_op = { "/" }rem_op = { "%" }logical_not_op = { "!" }negate_op = { "-" }pattern_kind_op = { ":" }prefix_ops = _{ logical_not_op | negate_op }infix_ops = _{  logical_or_op  | logical_and_op  | eq_op  | ne_op  | ge_op  | gt_op  | le_op  | lt_op  | add_op  | sub_op  | mul_op  | div_op  | rem_op} function = { identifier ~ "(" ~ function_arguments ~ ")" }keyword_argument = { identifier ~ "=" ~ template }argument = _{ keyword_argument | template }function_arguments = {  argument ~ ("," ~ argument)* ~ ","?  | ""}lambda = {  "|" ~ formal_parameters ~ "|" ~ template}formal_parameters = {  identifier ~ ("," ~ identifier)* ~ ","?  | ""} // NOTE: Pattern identifiers additionally allow "-" in them, which results in// some oddness with the `-` operator.pattern_identifier = @{ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_" | "-")* }pattern = ${ pattern_identifier ~ pattern_kind_op ~ pattern_value_expression }pattern_value_expression = { prefixed_term } primary = {  ("(" ~ template ~ ")")  | function  | lambda  | pattern  | identifier  | string_literal  | raw_string_literal  | integer_literal} term = {  primary ~ ("." ~ function)*} prefixed_term = _{  prefix_ops* ~ term} expression = {  prefixed_term ~ (infix_ops ~ prefixed_term)*} // Whitespace is allowed in value part of <name>:(<template>) expression.template = !{  expression ~ (concat_op ~ expression)*} program = _{ SOI ~ template? ~ EOI } function_alias_declaration = {  identifier ~ "(" ~ formal_parameters ~ ")"}pattern_alias_declaration = {  pattern_identifier ~ pattern_kind_op ~ identifier}alias_declaration = _{  SOI ~ (function_alias_declaration        | pattern_alias_declaration        | identifier) ~ EOI}