@@ -158,20 +158,14 @@ RegExp normalString = RegExp(r'[^{}]+');
158158RegExp brace = RegExp (r'{|}' );
159159
160160RegExp whitespace = RegExp (r'\s+' );
161- RegExp pluralKeyword = RegExp (r'plural' );
162- RegExp selectKeyword = RegExp (r'select' );
163- RegExp otherKeyword = RegExp (r'other' );
164161RegExp numeric = RegExp (r'[0-9]+' );
165- RegExp alphanumeric = RegExp (r'[a-zA-Z0-9]+' );
162+ RegExp alphanumeric = RegExp (r'[a-zA-Z0-9|_ ]+' );
166163RegExp comma = RegExp (r',' );
167164RegExp equalSign = RegExp (r'=' );
168165
169166// List of token matchers ordered by precedence
170167Map <ST , RegExp > matchers = < ST , RegExp > {
171168 ST .empty: whitespace,
172- ST .plural: pluralKeyword,
173- ST .select: selectKeyword,
174- ST .other: otherKeyword,
175169 ST .number: numeric,
176170 ST .comma: comma,
177171 ST .equalSign: equalSign,
@@ -303,12 +297,25 @@ class Parser {
303297 // Do not add whitespace as a token.
304298 startIndex = match.end;
305299 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 .
308302 tokens.add (Node (ST .identifier, startIndex, value: match.group (0 )));
309303 startIndex = match.end;
310304 continue ;
311305 } 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+ }
312319 tokens.add (Node (matchedType! , startIndex, value: match.group (0 )));
313320 startIndex = match.end;
314321 continue ;
0 commit comments