just playing with tangled
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 = @{ "\\" ~ ("t" | "r" | "n" | "0" | "\"" | "\\") }
23string_content_char = @{ !("\"" | "\\") ~ ANY }
24string_content = @{ string_content_char+ }
25string_literal = ${ "\"" ~ (string_content | string_escape)* ~ "\"" }
26
27raw_string_content = @{ (!"'" ~ ANY)* }
28raw_string_literal = ${ "'" ~ raw_string_content ~ "'" }
29
30integer_literal = @{
31 ASCII_NONZERO_DIGIT ~ ASCII_DIGIT*
32 | "0"
33}
34
35identifier = @{ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")* }
36
37concat_op = { "++" }
38logical_or_op = { "||" }
39logical_and_op = { "&&" }
40logical_not_op = { "!" }
41negate_op = { "-" }
42prefix_ops = _{ logical_not_op | negate_op }
43infix_ops = _{ logical_or_op | logical_and_op }
44
45function = { identifier ~ "(" ~ whitespace* ~ function_arguments ~ whitespace* ~ ")" }
46function_arguments = {
47 template ~ (whitespace* ~ "," ~ whitespace* ~ template)* ~ (whitespace* ~ ",")?
48 | ""
49}
50lambda = {
51 "|" ~ whitespace* ~ formal_parameters ~ whitespace* ~ "|"
52 ~ whitespace* ~ template
53}
54formal_parameters = {
55 identifier ~ (whitespace* ~ "," ~ whitespace* ~ identifier)* ~ (whitespace* ~ ",")?
56 | ""
57}
58
59primary = _{
60 ("(" ~ whitespace* ~ template ~ whitespace* ~ ")")
61 | function
62 | lambda
63 | identifier
64 | string_literal
65 | raw_string_literal
66 | integer_literal
67}
68
69term = {
70 primary ~ ("." ~ function)*
71}
72
73expression = {
74 (prefix_ops ~ whitespace*)* ~ term
75 ~ (whitespace* ~ infix_ops ~ whitespace* ~ (prefix_ops ~ whitespace*)* ~ term)*
76}
77
78template = {
79 expression ~ (whitespace* ~ concat_op ~ whitespace* ~ expression)*
80}
81
82program = _{ SOI ~ whitespace* ~ template? ~ whitespace* ~ EOI }
83
84function_alias_declaration = {
85 identifier ~ "(" ~ whitespace* ~ formal_parameters ~ whitespace* ~ ")"
86}
87alias_declaration = _{
88 SOI ~ (function_alias_declaration | identifier) ~ EOI
89}