1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QQMLJSKEYWORDS_P_H
43 #define QQMLJSKEYWORDS_P_H
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
56 static inline int classify2(const QChar *s, bool qmlMode) {
57 if (s[0].unicode() == 'a') {
58 if (s[1].unicode() == 's') {
59 return qmlMode ? Lexer::T_AS : Lexer::T_RESERVED_WORD;
62 else if (s[0].unicode() == 'd') {
63 if (s[1].unicode() == 'o') {
67 else if (s[0].unicode() == 'i') {
68 if (s[1].unicode() == 'f') {
71 else if (s[1].unicode() == 'n') {
75 else if (qmlMode && s[0].unicode() == 'o') {
76 if (s[1].unicode() == 'n') {
80 return Lexer::T_IDENTIFIER;
83 static inline int classify3(const QChar *s, bool /*qmlMode*/) {
84 if (s[0].unicode() == 'f') {
85 if (s[1].unicode() == 'o') {
86 if (s[2].unicode() == 'r') {
91 else if (s[0].unicode() == 'i') {
92 if (s[1].unicode() == 'n') {
93 if (s[2].unicode() == 't') {
98 else if (s[0].unicode() == 'n') {
99 if (s[1].unicode() == 'e') {
100 if (s[2].unicode() == 'w') {
105 else if (s[0].unicode() == 't') {
106 if (s[1].unicode() == 'r') {
107 if (s[2].unicode() == 'y') {
112 else if (s[0].unicode() == 'v') {
113 if (s[1].unicode() == 'a') {
114 if (s[2].unicode() == 'r') {
119 return Lexer::T_IDENTIFIER;
122 static inline int classify4(const QChar *s, bool /*qmlMode*/) {
123 if (s[0].unicode() == 'b') {
124 if (s[1].unicode() == 'y') {
125 if (s[2].unicode() == 't') {
126 if (s[3].unicode() == 'e') {
127 return Lexer::T_BYTE;
132 else if (s[0].unicode() == 'c') {
133 if (s[1].unicode() == 'a') {
134 if (s[2].unicode() == 's') {
135 if (s[3].unicode() == 'e') {
136 return Lexer::T_CASE;
140 else if (s[1].unicode() == 'h') {
141 if (s[2].unicode() == 'a') {
142 if (s[3].unicode() == 'r') {
143 return Lexer::T_CHAR;
148 else if (s[0].unicode() == 'e') {
149 if (s[1].unicode() == 'l') {
150 if (s[2].unicode() == 's') {
151 if (s[3].unicode() == 'e') {
152 return Lexer::T_ELSE;
156 else if (s[1].unicode() == 'n') {
157 if (s[2].unicode() == 'u') {
158 if (s[3].unicode() == 'm') {
159 return Lexer::T_ENUM;
164 else if (s[0].unicode() == 'g') {
165 if (s[1].unicode() == 'o') {
166 if (s[2].unicode() == 't') {
167 if (s[3].unicode() == 'o') {
168 return Lexer::T_GOTO;
173 else if (s[0].unicode() == 'l') {
174 if (s[1].unicode() == 'o') {
175 if (s[2].unicode() == 'n') {
176 if (s[3].unicode() == 'g') {
177 return Lexer::T_LONG;
182 else if (s[0].unicode() == 'n') {
183 if (s[1].unicode() == 'u') {
184 if (s[2].unicode() == 'l') {
185 if (s[3].unicode() == 'l') {
186 return Lexer::T_NULL;
191 else if (s[0].unicode() == 't') {
192 if (s[1].unicode() == 'h') {
193 if (s[2].unicode() == 'i') {
194 if (s[3].unicode() == 's') {
195 return Lexer::T_THIS;
199 else if (s[1].unicode() == 'r') {
200 if (s[2].unicode() == 'u') {
201 if (s[3].unicode() == 'e') {
202 return Lexer::T_TRUE;
207 else if (s[0].unicode() == 'v') {
208 if (s[1].unicode() == 'o') {
209 if (s[2].unicode() == 'i') {
210 if (s[3].unicode() == 'd') {
211 return Lexer::T_VOID;
216 else if (s[0].unicode() == 'w') {
217 if (s[1].unicode() == 'i') {
218 if (s[2].unicode() == 't') {
219 if (s[3].unicode() == 'h') {
220 return Lexer::T_WITH;
225 return Lexer::T_IDENTIFIER;
228 static inline int classify5(const QChar *s, bool /*qmlMode*/) {
229 if (s[0].unicode() == 'b') {
230 if (s[1].unicode() == 'r') {
231 if (s[2].unicode() == 'e') {
232 if (s[3].unicode() == 'a') {
233 if (s[4].unicode() == 'k') {
234 return Lexer::T_BREAK;
240 else if (s[0].unicode() == 'c') {
241 if (s[1].unicode() == 'a') {
242 if (s[2].unicode() == 't') {
243 if (s[3].unicode() == 'c') {
244 if (s[4].unicode() == 'h') {
245 return Lexer::T_CATCH;
250 else if (s[1].unicode() == 'l') {
251 if (s[2].unicode() == 'a') {
252 if (s[3].unicode() == 's') {
253 if (s[4].unicode() == 's') {
254 return Lexer::T_CLASS;
259 else if (s[1].unicode() == 'o') {
260 if (s[2].unicode() == 'n') {
261 if (s[3].unicode() == 's') {
262 if (s[4].unicode() == 't') {
263 return Lexer::T_CONST;
269 else if (s[0].unicode() == 'f') {
270 if (s[1].unicode() == 'a') {
271 if (s[2].unicode() == 'l') {
272 if (s[3].unicode() == 's') {
273 if (s[4].unicode() == 'e') {
274 return Lexer::T_FALSE;
279 else if (s[1].unicode() == 'i') {
280 if (s[2].unicode() == 'n') {
281 if (s[3].unicode() == 'a') {
282 if (s[4].unicode() == 'l') {
283 return Lexer::T_FINAL;
288 else if (s[1].unicode() == 'l') {
289 if (s[2].unicode() == 'o') {
290 if (s[3].unicode() == 'a') {
291 if (s[4].unicode() == 't') {
292 return Lexer::T_FLOAT;
298 else if (s[0].unicode() == 's') {
299 if (s[1].unicode() == 'h') {
300 if (s[2].unicode() == 'o') {
301 if (s[3].unicode() == 'r') {
302 if (s[4].unicode() == 't') {
303 return Lexer::T_SHORT;
308 else if (s[1].unicode() == 'u') {
309 if (s[2].unicode() == 'p') {
310 if (s[3].unicode() == 'e') {
311 if (s[4].unicode() == 'r') {
312 return Lexer::T_SUPER;
318 else if (s[0].unicode() == 't') {
319 if (s[1].unicode() == 'h') {
320 if (s[2].unicode() == 'r') {
321 if (s[3].unicode() == 'o') {
322 if (s[4].unicode() == 'w') {
323 return Lexer::T_THROW;
329 else if (s[0].unicode() == 'w') {
330 if (s[1].unicode() == 'h') {
331 if (s[2].unicode() == 'i') {
332 if (s[3].unicode() == 'l') {
333 if (s[4].unicode() == 'e') {
334 return Lexer::T_WHILE;
340 return Lexer::T_IDENTIFIER;
343 static inline int classify6(const QChar *s, bool qmlMode) {
344 if (s[0].unicode() == 'd') {
345 if (s[1].unicode() == 'e') {
346 if (s[2].unicode() == 'l') {
347 if (s[3].unicode() == 'e') {
348 if (s[4].unicode() == 't') {
349 if (s[5].unicode() == 'e') {
350 return Lexer::T_DELETE;
356 else if (s[1].unicode() == 'o') {
357 if (s[2].unicode() == 'u') {
358 if (s[3].unicode() == 'b') {
359 if (s[4].unicode() == 'l') {
360 if (s[5].unicode() == 'e') {
361 return Lexer::T_DOUBLE;
368 else if (s[0].unicode() == 'e') {
369 if (s[1].unicode() == 'x') {
370 if (s[2].unicode() == 'p') {
371 if (s[3].unicode() == 'o') {
372 if (s[4].unicode() == 'r') {
373 if (s[5].unicode() == 't') {
374 return Lexer::T_EXPORT;
381 else if (s[0].unicode() == 'i') {
382 if (s[1].unicode() == 'm') {
383 if (s[2].unicode() == 'p') {
384 if (s[3].unicode() == 'o') {
385 if (s[4].unicode() == 'r') {
386 if (s[5].unicode() == 't') {
387 return qmlMode ? Lexer::T_IMPORT : Lexer::T_RESERVED_WORD;
394 else if (s[0].unicode() == 'n') {
395 if (s[1].unicode() == 'a') {
396 if (s[2].unicode() == 't') {
397 if (s[3].unicode() == 'i') {
398 if (s[4].unicode() == 'v') {
399 if (s[5].unicode() == 'e') {
400 return Lexer::T_NATIVE;
407 else if (s[0].unicode() == 'p') {
408 if (s[1].unicode() == 'u') {
409 if (s[2].unicode() == 'b') {
410 if (s[3].unicode() == 'l') {
411 if (s[4].unicode() == 'i') {
412 if (s[5].unicode() == 'c') {
413 return qmlMode ? Lexer::T_PUBLIC : Lexer::T_RESERVED_WORD;
420 else if (s[0].unicode() == 'r') {
421 if (s[1].unicode() == 'e') {
422 if (s[2].unicode() == 't') {
423 if (s[3].unicode() == 'u') {
424 if (s[4].unicode() == 'r') {
425 if (s[5].unicode() == 'n') {
426 return Lexer::T_RETURN;
433 else if (s[0].unicode() == 's') {
434 if (qmlMode && s[1].unicode() == 'i') {
435 if (s[2].unicode() == 'g') {
436 if (s[3].unicode() == 'n') {
437 if (s[4].unicode() == 'a') {
438 if (s[5].unicode() == 'l') {
439 return Lexer::T_SIGNAL;
445 else if (s[1].unicode() == 't') {
446 if (s[2].unicode() == 'a') {
447 if (s[3].unicode() == 't') {
448 if (s[4].unicode() == 'i') {
449 if (s[5].unicode() == 'c') {
450 return Lexer::T_STATIC;
456 else if (s[1].unicode() == 'w') {
457 if (s[2].unicode() == 'i') {
458 if (s[3].unicode() == 't') {
459 if (s[4].unicode() == 'c') {
460 if (s[5].unicode() == 'h') {
461 return Lexer::T_SWITCH;
468 else if (s[0].unicode() == 't') {
469 if (s[1].unicode() == 'h') {
470 if (s[2].unicode() == 'r') {
471 if (s[3].unicode() == 'o') {
472 if (s[4].unicode() == 'w') {
473 if (s[5].unicode() == 's') {
474 return Lexer::T_THROWS;
480 else if (s[1].unicode() == 'y') {
481 if (s[2].unicode() == 'p') {
482 if (s[3].unicode() == 'e') {
483 if (s[4].unicode() == 'o') {
484 if (s[5].unicode() == 'f') {
485 return Lexer::T_TYPEOF;
492 return Lexer::T_IDENTIFIER;
495 static inline int classify7(const QChar *s, bool /*qmlMode*/) {
496 if (s[0].unicode() == 'b') {
497 if (s[1].unicode() == 'o') {
498 if (s[2].unicode() == 'o') {
499 if (s[3].unicode() == 'l') {
500 if (s[4].unicode() == 'e') {
501 if (s[5].unicode() == 'a') {
502 if (s[6].unicode() == 'n') {
503 return Lexer::T_BOOLEAN;
511 else if (s[0].unicode() == 'd') {
512 if (s[1].unicode() == 'e') {
513 if (s[2].unicode() == 'f') {
514 if (s[3].unicode() == 'a') {
515 if (s[4].unicode() == 'u') {
516 if (s[5].unicode() == 'l') {
517 if (s[6].unicode() == 't') {
518 return Lexer::T_DEFAULT;
526 else if (s[0].unicode() == 'e') {
527 if (s[1].unicode() == 'x') {
528 if (s[2].unicode() == 't') {
529 if (s[3].unicode() == 'e') {
530 if (s[4].unicode() == 'n') {
531 if (s[5].unicode() == 'd') {
532 if (s[6].unicode() == 's') {
533 return Lexer::T_EXTENDS;
541 else if (s[0].unicode() == 'f') {
542 if (s[1].unicode() == 'i') {
543 if (s[2].unicode() == 'n') {
544 if (s[3].unicode() == 'a') {
545 if (s[4].unicode() == 'l') {
546 if (s[5].unicode() == 'l') {
547 if (s[6].unicode() == 'y') {
548 return Lexer::T_FINALLY;
556 else if (s[0].unicode() == 'p') {
557 if (s[1].unicode() == 'a') {
558 if (s[2].unicode() == 'c') {
559 if (s[3].unicode() == 'k') {
560 if (s[4].unicode() == 'a') {
561 if (s[5].unicode() == 'g') {
562 if (s[6].unicode() == 'e') {
563 return Lexer::T_PACKAGE;
570 else if (s[1].unicode() == 'r') {
571 if (s[2].unicode() == 'i') {
572 if (s[3].unicode() == 'v') {
573 if (s[4].unicode() == 'a') {
574 if (s[5].unicode() == 't') {
575 if (s[6].unicode() == 'e') {
576 return Lexer::T_PRIVATE;
584 return Lexer::T_IDENTIFIER;
587 static inline int classify8(const QChar *s, bool qmlMode) {
588 if (s[0].unicode() == 'a') {
589 if (s[1].unicode() == 'b') {
590 if (s[2].unicode() == 's') {
591 if (s[3].unicode() == 't') {
592 if (s[4].unicode() == 'r') {
593 if (s[5].unicode() == 'a') {
594 if (s[6].unicode() == 'c') {
595 if (s[7].unicode() == 't') {
596 return Lexer::T_ABSTRACT;
605 else if (s[0].unicode() == 'c') {
606 if (s[1].unicode() == 'o') {
607 if (s[2].unicode() == 'n') {
608 if (s[3].unicode() == 't') {
609 if (s[4].unicode() == 'i') {
610 if (s[5].unicode() == 'n') {
611 if (s[6].unicode() == 'u') {
612 if (s[7].unicode() == 'e') {
613 return Lexer::T_CONTINUE;
622 else if (s[0].unicode() == 'd') {
623 if (s[1].unicode() == 'e') {
624 if (s[2].unicode() == 'b') {
625 if (s[3].unicode() == 'u') {
626 if (s[4].unicode() == 'g') {
627 if (s[5].unicode() == 'g') {
628 if (s[6].unicode() == 'e') {
629 if (s[7].unicode() == 'r') {
630 return Lexer::T_DEBUGGER;
639 else if (s[0].unicode() == 'f') {
640 if (s[1].unicode() == 'u') {
641 if (s[2].unicode() == 'n') {
642 if (s[3].unicode() == 'c') {
643 if (s[4].unicode() == 't') {
644 if (s[5].unicode() == 'i') {
645 if (s[6].unicode() == 'o') {
646 if (s[7].unicode() == 'n') {
647 return Lexer::T_FUNCTION;
656 else if (qmlMode && s[0].unicode() == 'p') {
657 if (s[1].unicode() == 'r') {
658 if (s[2].unicode() == 'o') {
659 if (s[3].unicode() == 'p') {
660 if (s[4].unicode() == 'e') {
661 if (s[5].unicode() == 'r') {
662 if (s[6].unicode() == 't') {
663 if (s[7].unicode() == 'y') {
664 return Lexer::T_PROPERTY;
673 else if (qmlMode && s[0].unicode() == 'r') {
674 if (s[1].unicode() == 'e') {
675 if (s[2].unicode() == 'a') {
676 if (s[3].unicode() == 'd') {
677 if (s[4].unicode() == 'o') {
678 if (s[5].unicode() == 'n') {
679 if (s[6].unicode() == 'l') {
680 if (s[7].unicode() == 'y') {
681 return Lexer::T_READONLY;
690 else if (s[0].unicode() == 'v') {
691 if (s[1].unicode() == 'o') {
692 if (s[2].unicode() == 'l') {
693 if (s[3].unicode() == 'a') {
694 if (s[4].unicode() == 't') {
695 if (s[5].unicode() == 'i') {
696 if (s[6].unicode() == 'l') {
697 if (s[7].unicode() == 'e') {
698 return Lexer::T_VOLATILE;
707 return Lexer::T_IDENTIFIER;
710 static inline int classify9(const QChar *s, bool /*qmlMode*/) {
711 if (s[0].unicode() == 'i') {
712 if (s[1].unicode() == 'n') {
713 if (s[2].unicode() == 't') {
714 if (s[3].unicode() == 'e') {
715 if (s[4].unicode() == 'r') {
716 if (s[5].unicode() == 'f') {
717 if (s[6].unicode() == 'a') {
718 if (s[7].unicode() == 'c') {
719 if (s[8].unicode() == 'e') {
720 return Lexer::T_INTERFACE;
730 else if (s[0].unicode() == 'p') {
731 if (s[1].unicode() == 'r') {
732 if (s[2].unicode() == 'o') {
733 if (s[3].unicode() == 't') {
734 if (s[4].unicode() == 'e') {
735 if (s[5].unicode() == 'c') {
736 if (s[6].unicode() == 't') {
737 if (s[7].unicode() == 'e') {
738 if (s[8].unicode() == 'd') {
739 return Lexer::T_PROTECTED;
749 else if (s[0].unicode() == 't') {
750 if (s[1].unicode() == 'r') {
751 if (s[2].unicode() == 'a') {
752 if (s[3].unicode() == 'n') {
753 if (s[4].unicode() == 's') {
754 if (s[5].unicode() == 'i') {
755 if (s[6].unicode() == 'e') {
756 if (s[7].unicode() == 'n') {
757 if (s[8].unicode() == 't') {
758 return Lexer::T_TRANSIENT;
768 return Lexer::T_IDENTIFIER;
771 static inline int classify10(const QChar *s, bool /*qmlMode*/) {
772 if (s[0].unicode() == 'i') {
773 if (s[1].unicode() == 'm') {
774 if (s[2].unicode() == 'p') {
775 if (s[3].unicode() == 'l') {
776 if (s[4].unicode() == 'e') {
777 if (s[5].unicode() == 'm') {
778 if (s[6].unicode() == 'e') {
779 if (s[7].unicode() == 'n') {
780 if (s[8].unicode() == 't') {
781 if (s[9].unicode() == 's') {
782 return Lexer::T_IMPLEMENTS;
792 else if (s[1].unicode() == 'n') {
793 if (s[2].unicode() == 's') {
794 if (s[3].unicode() == 't') {
795 if (s[4].unicode() == 'a') {
796 if (s[5].unicode() == 'n') {
797 if (s[6].unicode() == 'c') {
798 if (s[7].unicode() == 'e') {
799 if (s[8].unicode() == 'o') {
800 if (s[9].unicode() == 'f') {
801 return Lexer::T_INSTANCEOF;
812 return Lexer::T_IDENTIFIER;
815 static inline int classify12(const QChar *s, bool /*qmlMode*/) {
816 if (s[0].unicode() == 's') {
817 if (s[1].unicode() == 'y') {
818 if (s[2].unicode() == 'n') {
819 if (s[3].unicode() == 'c') {
820 if (s[4].unicode() == 'h') {
821 if (s[5].unicode() == 'r') {
822 if (s[6].unicode() == 'o') {
823 if (s[7].unicode() == 'n') {
824 if (s[8].unicode() == 'i') {
825 if (s[9].unicode() == 'z') {
826 if (s[10].unicode() == 'e') {
827 if (s[11].unicode() == 'd') {
828 return Lexer::T_SYNCHRONIZED;
841 return Lexer::T_IDENTIFIER;
844 int Lexer::classify(const QChar *s, int n, bool qmlMode) {
846 case 2: return classify2(s, qmlMode);
847 case 3: return classify3(s, qmlMode);
848 case 4: return classify4(s, qmlMode);
849 case 5: return classify5(s, qmlMode);
850 case 6: return classify6(s, qmlMode);
851 case 7: return classify7(s, qmlMode);
852 case 8: return classify8(s, qmlMode);
853 case 9: return classify9(s, qmlMode);
854 case 10: return classify10(s, qmlMode);
855 case 12: return classify12(s, qmlMode);
856 default: return Lexer::T_IDENTIFIER;
860 #endif // QQMLJSKEYWORDS_P_H