just playing with tangled
at ig/vimdiffwarn 109 lines 2.9 kB view raw
1// Copyright 2020 The Jujutsu Authors 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// https://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15// Example: 16// "commit: " ++ short(commit_id) ++ "\n" 17// predecessors.map(|p| "predecessor: " ++ p.commit_id) 18// parents.map(|p| p.commit_id ++ " is a parent of " ++ commit_id) 19 20whitespace = _{ " " | "\t" | "\r" | "\n" | "\x0c" } 21 22string_escape = @{ 23 "\\" 24 ~ ("t" | "r" | "n" | "0" | "e" | ("x" ~ ASCII_HEX_DIGIT{2}) | "\"" | "\\") 25} 26string_content_char = @{ !("\"" | "\\") ~ ANY } 27string_content = @{ string_content_char+ } 28string_literal = ${ "\"" ~ (string_content | string_escape)* ~ "\"" } 29 30raw_string_content = @{ (!"'" ~ ANY)* } 31raw_string_literal = ${ "'" ~ raw_string_content ~ "'" } 32 33integer_literal = @{ 34 ASCII_NONZERO_DIGIT ~ ASCII_DIGIT* 35 | "0" 36} 37 38identifier = @{ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")* } 39 40concat_op = { "++" } 41logical_or_op = { "||" } 42logical_and_op = { "&&" } 43eq_op = { "==" } 44ne_op = { "!=" } 45ge_op = { ">=" } 46gt_op = { ">" } 47le_op = { "<=" } 48lt_op = { "<" } 49logical_not_op = { "!" } 50negate_op = { "-" } 51prefix_ops = _{ logical_not_op | negate_op } 52infix_ops = _{ 53 logical_or_op 54 | logical_and_op 55 | eq_op 56 | ne_op 57 | ge_op 58 | gt_op 59 | le_op 60 | lt_op 61} 62 63function = { identifier ~ "(" ~ whitespace* ~ function_arguments ~ whitespace* ~ ")" } 64keyword_argument = { identifier ~ whitespace* ~ "=" ~ whitespace* ~ template } 65argument = _{ keyword_argument | template } 66function_arguments = { 67 argument ~ (whitespace* ~ "," ~ whitespace* ~ argument)* ~ (whitespace* ~ ",")? 68 | "" 69} 70lambda = { 71 "|" ~ whitespace* ~ formal_parameters ~ whitespace* ~ "|" 72 ~ whitespace* ~ template 73} 74formal_parameters = { 75 identifier ~ (whitespace* ~ "," ~ whitespace* ~ identifier)* ~ (whitespace* ~ ",")? 76 | "" 77} 78 79primary = _{ 80 ("(" ~ whitespace* ~ template ~ whitespace* ~ ")") 81 | function 82 | lambda 83 | identifier 84 | string_literal 85 | raw_string_literal 86 | integer_literal 87} 88 89term = { 90 primary ~ ("." ~ function)* 91} 92 93expression = { 94 (prefix_ops ~ whitespace*)* ~ term 95 ~ (whitespace* ~ infix_ops ~ whitespace* ~ (prefix_ops ~ whitespace*)* ~ term)* 96} 97 98template = { 99 expression ~ (whitespace* ~ concat_op ~ whitespace* ~ expression)* 100} 101 102program = _{ SOI ~ whitespace* ~ template? ~ whitespace* ~ EOI } 103 104function_alias_declaration = { 105 identifier ~ "(" ~ whitespace* ~ formal_parameters ~ whitespace* ~ ")" 106} 107alias_declaration = _{ 108 SOI ~ (function_alias_declaration | identifier) ~ EOI 109}