@@ -158,20 +158,14 @@ RegExp normalString = RegExp(r'[^{}]+');
158
158
RegExp brace = RegExp (r'{|}' );
159
159
160
160
RegExp whitespace = RegExp (r'\s+' );
161
- RegExp pluralKeyword = RegExp (r'plural' );
162
- RegExp selectKeyword = RegExp (r'select' );
163
- RegExp otherKeyword = RegExp (r'other' );
164
161
RegExp numeric = RegExp (r'[0-9]+' );
165
- RegExp alphanumeric = RegExp (r'[a-zA-Z0-9]+' );
162
+ RegExp alphanumeric = RegExp (r'[a-zA-Z0-9|_ ]+' );
166
163
RegExp comma = RegExp (r',' );
167
164
RegExp equalSign = RegExp (r'=' );
168
165
169
166
// List of token matchers ordered by precedence
170
167
Map <ST , RegExp > matchers = < ST , RegExp > {
171
168
ST .empty: whitespace,
172
- ST .plural: pluralKeyword,
173
- ST .select: selectKeyword,
174
- ST .other: otherKeyword,
175
169
ST .number: numeric,
176
170
ST .comma: comma,
177
171
ST .equalSign: equalSign,
@@ -303,12 +297,25 @@ class Parser {
303
297
// Do not add whitespace as a token.
304
298
startIndex = match.end;
305
299
continue ;
306
- } else if (< ST > [ST .plural, ST .select ].contains (matchedType) && tokens.last.type == ST .openBrace) {
307
- // Treat "plural" or "select" as identifier if it comes right after an open brace.
300
+ } else if (< ST > [ST .identifier ].contains (matchedType) && tokens.last.type == ST .openBrace) {
301
+ // Treat any token as identifier if it comes right after an open brace, whether it's a keyword or not .
308
302
tokens.add (Node (ST .identifier, startIndex, value: match.group (0 )));
309
303
startIndex = match.end;
310
304
continue ;
311
305
} else {
306
+ // Handle keywords separately. Otherwise, lexer will assume parts of identifiers may be keywords.
307
+ final String tokenStr = match.group (0 )! ;
308
+ switch (tokenStr) {
309
+ case 'plural' :
310
+ matchedType = ST .plural;
311
+ break ;
312
+ case 'select' :
313
+ matchedType = ST .select;
314
+ break ;
315
+ case 'other' :
316
+ matchedType = ST .other;
317
+ break ;
318
+ }
312
319
tokens.add (Node (matchedType! , startIndex, value: match.group (0 )));
313
320
startIndex = match.end;
314
321
continue ;
0 commit comments