-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTLexer.g4
141 lines (112 loc) · 3.49 KB
/
TLexer.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
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
/* Copyright (C) 2021-2023 b1f6c1c4
*
* This file is part of ajnin.
*
* ajnin is free software: you can redistribute it and/or modify it under the
* terms of the GNU Affero General Public License as published by the Free
* Software Foundation, version 3.
*
* ajnin 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 Affero General Public License for
* more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with ajnin. If not, see <https://www.gnu.org/licenses/>.
*/
lexer grammar TLexer;
// These are all supported lexer sections:
// Lexer file header. Appears at the top of h + cpp files. Use e.g. for copyrights.
@lexer::header {/* lexer header section */}
// Appears before any #include in h + cpp files.
@lexer::preinclude {/* lexer precinclude section */}
// Follows directly after the standard #includes in h + cpp files.
@lexer::postinclude {
/* lexer postinclude section */
#ifndef _WIN32
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
}
// Directly preceds the lexer class declaration in the h file (e.g. for additional types etc.).
@lexer::context {/* lexer context section */}
// Appears in the public part of the lexer in the h file.
@lexer::members {/* public lexer declarations section */}
// Appears in the private part of the lexer in the h file.
@lexer::declarations {/* private lexer declarations/members section */}
// Appears in line with the other class member definitions in the cpp file.
@lexer::definitions {/* lexer definitions section */}
KList: 'list';
KRule: 'rule';
KForeach: 'foreach';
KInclude: 'include';
KIf: 'if';
KElse: 'else';
KAlso: 'also';
KSort: 'sort';
KUnique: 'uniq';
KDesc: 'desc';
KPrint: 'print';
KClear: 'clear';
KFile: 'file';
KTemplate: 'template';
KExecute: 'execute';
KMeta: 'meta';
KPool: 'pool';
KDefault: 'default';
IsEmpty: '-z';
IsNonEmpty: '-n';
ID: 'a'..'z' | 'A'..'Z';
SubID: ID [0-9];
ListSearch: ':=' -> mode(prePath);
ListEnum: '::=' -> mode(listItem);
ListEnumItem: '+=' -> mode(listItem);
ListEnumRItem: '-=' -> mode(listItem);
RuleAppend: '|=';
RuleAppend2: '||=';
Times: '*';
Exclamation: '!';
Mult: '>>';
Single: '--';
Append: '<<';
fragment LETTER : [a-zA-Z\u0080-\u{10FFFF}];
Token: LETTER ((LETTER | '0'..'9' | '_' | '-' | '.')* (LETTER | '0'..'9'))?;
TemplateName: '<' LETTER ((LETTER | '0'..'9' | '_' | '-' | '.')* (LETTER | '0'..'9'))? '>';
OpenCurly: '{';
OpenDoubleCurly: '{{';
CloseCurly: '}';
CloseDoubleCurly: '}}';
Bra: '[';
Ket: ']';
Tilde: '~';
Comment : '#' ~[\r\n]* NL1 -> skip;
WS: [ \t]+ -> skip;
BNL: '\\' '\r'? '\n' -> skip;
NL1: '\r'? '\n';
LiteralProlog : '> ' -> mode(literal);
LiteralEmptyText: '>' NL1;
OpenPar: '(' -> more, mode(stage);
Ampersand: '&' -> more, mode(assign);
Dollar: '$';
SingleString: '\'' (~'\'' | '$\'')* '\'';
DoubleString: '"' (~'"' | '$"')* '"';
mode prePath;
PathWS: [ \t]+ -> skip;
PrePathText: . -> more, mode(path);
mode path;
Path: NL1 -> mode(DEFAULT_MODE);
OpenCurlyPath: ' {' NL1 -> mode(DEFAULT_MODE);
OpenDoubleCurlyPath: ' {{' NL1 -> mode(DEFAULT_MODE);
PathText: . -> more;
mode stage;
Stage: ')' -> mode(DEFAULT_MODE);
StageText: . -> more;
mode assign;
Assign: '+'? '=' -> mode(DEFAULT_MODE);
AssignText: ~[+=] -> more;
mode listItem;
ListItemNL: NL1 -> mode(DEFAULT_MODE);
ListItemToken: ~[ \t\r\n]+;
ListItemWS: [ \t]+ -> skip;
mode literal;
LiteralNL: NL1 -> mode(DEFAULT_MODE);
LiteralText: . -> more;