-
Notifications
You must be signed in to change notification settings - Fork 21
/
grammar.owl
43 lines (40 loc) · 1.22 KB
/
grammar.owl
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
#using owl.v4
# This is the grammar for Owl itself.
# Compile with `owl -c grammar.owl -o src/1-parse.h`.
grammar = (rule | comment-token | custom-token | whitespace)*
rule = identifier '=' body
body = expr | (expr ':' identifier)+ operators*
operators = '.operators' fixity operator+
fixity =
'postfix' : postfix-op
'prefix' : prefix-op
'infix' assoc : infix-op
assoc =
'flat' : flat-op
'left' : left-op
'right' : right-op
'nonassoc' : nonassoc-op
operator = expr ':' identifier
expr =
identifier ('\\' ':' identifier@exception)* ('@' identifier@rename)? : ident
string : literal
[ '(' expr ')' ] : parens
[ '[' string@begin-token expr\:choice? string@end-token ']' ] : bracketed
.operators postfix
'*' : zero-or-more
'+' : one-or-more
'?' : optional
[ '{' (repetition | expr (',' repetition)?)? '}' ] : repetition
.operators infix flat
'' : concatenation
.operators infix flat
'|' : choice
repetition =
integer@begin : exact
integer@begin '+' : at-least
integer@begin ',' integer@end : range
comment-token = '.line-comment-token' string | comment-token-v1
comment-token-v1 = 'line-comment-token' string
custom-token = '.token' identifier string*
whitespace = '.whitespace' string*
.line-comment-token '#'