-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgrammar.ohm
More file actions
160 lines (127 loc) · 4.07 KB
/
grammar.ohm
File metadata and controls
160 lines (127 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
Kaashi {
Program = Import* Expr
Import = Extract_import | Alias_import
Extract_import = from_directive address import name Alias? (arg_sep name Alias?)*
Alias_import = import_directive address Alias
from_directive = "@from"
import_directive = "@import"
Alias = as name
as = "as"
import = "import"
address = (alnum
| "+" | "-" | "=" | "&" | "?" | "." | ":" | "," | ";"
| "[" | "]" | "/" | "\\" | "#" | "@" | "!" | "~" | "%"
| "'" | "\""
)+
Expr = Lambda
| Pipeline
| Operation
| Access
| Block
| Pattern
| Paranthesis
| Atomic
Block = open_block (Rule block_sep)* Rule? close_block
Rule = Parametric_rule
| Key_rule
| Constant_rule
| Expr
Parametric_rule = Args define Expr
Key_rule = name define Expr
Constant_rule = Value define Expr
Pattern = open_block (Matching block_sep)* Matching? close_block
Matching = Expr Condition
Condition = subject_to (Expr | otherwise)
Lambda = Args define Expr
Args = open_index (Arg arg_sep)* Arg close_index
Arg = Destructuring_arg
| Variable_arg
| Constant_arg
Destructuring_arg = Destructuring (subject_to Expr)?
Destructuring = open_block (Destructuring_element arg_sep)* (Destructuring_element)? close_block
Destructuring_element = Destructuring | destructuring_name | name
destructuring_name = rest name
Variable_arg = name Default_value? (subject_to Expr)?
Default_value = open_paran default Expr close_paran
Constant_arg = Value
Pipeline = (Pipeline | Pipeline_operand) pipe Pipeline_operand
Pipeline_operand = Operation | Operand
Operation = Operand (Operation | Operand)
Operand = ~pipe
( Block
| Pattern
| Access
| Atomic
| Paranthesis
)
Access = Index | Attr
Attr = (Access | Index_operand) access name
Index = (Access | Index_operand) open_index (Expr arg_sep)* Expr close_index
Index_operand = Block
| Pattern
| Paranthesis
| Atomic
Paranthesis = open_paran Expr close_paran
Atomic = variable | Value | env | operator
name = variable | operator
env = "$" variable
variable = ~reserved (var_letter (var_letter | alnum)*)
var_letter = "_" | letter
Value = boolean | number | String
String = Template_string
| single_quote_string
| dbl_quote_string
Template_string = Template | bland_template
Template = template_start Expr (template_middle Expr)* template_end
template_middle = close_block (~(backtick | open_block) any)* open_block
template_end = close_block (~(backtick | open_block) any)* backtick
template_start = backtick (~(backtick | open_block) any)* open_block
bland_template = backtick (~backtick any)* backtick
single_quote_string = single_quote (~single_quote any)* single_quote
dbl_quote_string = dbl_quote (~dbl_quote any)* dbl_quote
single_quote = "'"
dbl_quote = "\""
backtick = "`"
number = "-"? (bto | decimal)
bto = ddigit+ decimal?
decimal = "." ddigit+
ddigit = digit
| "_"
boolean = true
| false
operator = ~pipe
( rest
| is | and | or | not
| "==" | "!=" | "=>" | "<=" | ">=" | "=<" | "&&" | "||" | "++" | "--" | "**"
| ">>" | "<<" | "^^" | "??" | "!!"
| "+" | "-" | "*" | "/" | "=" | "!" | "&" | "%" | "~" | "?" | ">" | "<"
| "^"
)
otherwise = "otherwise"
and = "and"
or = "or"
not = "not"
is = "is"
true = "true"
false = "false"
default = "default"
reserved = otherwise | and | or | not | is | true | false | default
block_sep = ";" | ","
arg_sep = ","
subject_to = "|"
open_block = "{"
close_block = "}"
open_index = "["
close_index = "]"
open_paran = "("
close_paran = ")"
define = ":"
access = "."
rest = "..."
pipe = "->"
space := " " | "\t" | "\r" | "\n" | comment
comment = line_comment | multi_comment | endless_comment
line_comment = "//" (~"\n" any)*
multi_comment = "/*" (~"*/" any)* "*/"
endless_comment = "/*" (~"*/" any)*
}