-
Notifications
You must be signed in to change notification settings - Fork 0
/
SolusGrammar.giza
111 lines (88 loc) · 2.82 KB
/
SolusGrammar.giza
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
/*
* MetaphysicsIndustries.Solus
* Copyright (C) 2006-2022 Metaphysics Industries, Inc., Richard Sartor
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
*/
commands = ( command ';' )* command ';'? ;
command = (
help-command |
var-assign-command |
func-assign-command |
vars-command |
delete-command
);
help-command = 'help' identifier?:topic;
var-assign-command = varref ':=' expr;
func-assign-command = identifier:name
'(' ( identifier:param ( ':' varref )? ( ',' identifier:param ( ':' varref )? )* )? ')'
':=' expr ;
vars-command = ( 'vars' | 'variables' );
delete-command = 'delete' varref varref* ;
expr = subexpr ( binop subexpr )*;
<ignore case, token> number = (
'0b' [01]+ |
'0o' [01234567]+ |
'0x' [\dabcdef]+ |
float-number
);
// non-atomic, usable by the spanner
<ignore case, subtoken> float-number = [+-]? [\d]+ ( '.' [\d]+ )? ( [eE] [+-]? [\d]+ )? ;
<token> string = (
'\'' ( [^\\'] | '\\' [rnt\\'] | unicodechar )+ '\'' |
'"' ( [^\\"] | '\\' [rnt\\"] | unicodechar )+ '"'
);
<ignore case, subtoken> unicodechar = '\\x' [\dabcdef][\dabcdef][\dabcdef][\dabcdef];
<token> binop = ( [+-*/%^&|=<>] | '!=' | '<=' | '>=' | 'or' | 'and' );
unary-op = [+-] (
paren |
function-call-or-component-access |
string |
unary-op |
varref |
array-literal
);
subexpr = (
paren |
function-call-or-component-access |
number |
string |
unary-op |
varref |
array-literal
);
paren = '(' expr ')';
varref = identifier;
<token> identifier = [\w] [\d\w_]*;
array-literal = '[' expr ( ',' expr )* ','?
( ';' expr ( ',' expr )* ','? )* ';'? ']';
function-call-or-component-access =
call-comp-subexpr:target ( call-args | array-index )+;
call-args = '(' ( expr:arg ( ',' expr:arg )* ','? )? ')';
call-comp-subexpr = (
paren |
string |
varref |
array-literal
);
array-index = '[' expr ( ',' expr )* ','? ']';
// TODO: <expr> instead of <number> -> requires taking env out of parsing
interval = [\[(] number ',' number [\])];
var-interval = (
varref 'in' interval |
expr ( '<' | '<=' ) varref ( '<' | '<=' ) expr
);