Debian Codegraph @

repl/parser/Commands.g4

raw
1 // Copyright 2022 Google LLC
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 grammar Commands;
16
17 import CEL;
18
19 // parser rules:
20 startCommand: command EOF;
21
22 command: help |
23 let |
24 declare |
25 delete |
26 simple |
27 compile |
28 parse |
29 exprCmd |
30 empty;
31
32 help: '%help' | '%?';
33
34 let: '%let' ( (var=varDecl '=') | (fn=fnDecl '->') ) e=expr;
35
36 declare: '%declare' (var=varDecl | fn=fnDecl);
37
38 varDecl: id=qualId (':' t=type)?;
39
40 fnDecl: id=qualId '(' (params+=param (',' params+=param)*)? ')' ':' rType=type;
41
42 param: pid=IDENTIFIER ':' t=type;
43
44 delete: '%delete' (var=varDecl | fn=fnDecl);
45
46 simple: cmd=COMMAND (args+=FLAG | args+=STRING)*;
47
48 empty: ;
49
50 compile: '%compile' e=expr;
51
52 parse: '%parse' e=expr;
53
54 exprCmd: ('%eval' (flags+=FLAG (flags+=FLAG)* '--')?)? e=expr;
55
56 qualId: leadingDot='.'? rid=IDENTIFIER ('.' qualifiers+=IDENTIFIER)*;
57
58 // type sublanguage
59 startType : t=type EOF;
60
61 type :
62 id=typeId params=typeParamList? ;
63
64 typeId :
65 leadingDot='.'? id=(IDENTIFIER|NUL) ('.' qualifiers+=IDENTIFIER )* ;
66
67 typeParamList:
68 '(' ( types+=type (',' types+=type)* )? ')' ;
69
70 // lexer rules:
71 COMMAND: '%' IDENTIFIER;
72 FLAG: '-' ('-' IDENTIFIER)+;
73 ARROW: '->';
74 EQUAL_ASSIGN: '=';