-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cobra.g4
59 lines (42 loc) · 1.05 KB
/
Cobra.g4
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
grammar Cobra;
@header {
package riki.cobra.language;
}
cobra: stat+;
stat: use '{' instructions* '}'
| assignment
| backup
;
backup: 'backup' 'on' string #backupon
;
use: 'use' (folder|file)+ #useStat
;
folder: 'folder' atomic (',' atomic)* #folders
| 'sub' folder excludes? #subFolder
;
excludes: 'exclude' atomic (',' atomic)* ;
file: 'file' atomic (',' atomic)* excludes?
;
instructions: assignment
| replace
| replacefrom
| cmd
;
// Single commands
cmd: 'exit' #exit
;
replace: 'replace' tofind ',' replacewith ;
replacefrom: 'replace' 'from' from=atomic 'to' to=atomic 'with' replacewith;
assignment: ID '=' atomic;
array: '[' atomic+ (',' atomic)* ']' ;
atomic: string
| array
| ID
;
tofind: atomic (',' atomic)*;
replacewith: atomic;
string : STRING;
STRING: '"' (~[\r\n"] | '\\"')* '"' {setText(getText().substring(1, getText().length()-1));};
ID: '$'[A-Z_]+ {setText(getText().substring(1, getText().length()));};
WS: [ \t\r\n] -> skip;
COMMENT: '#' ~[\r?\n]* -> skip ;