File indexing completed on 2024-04-21 04:36:20

0001 #include <cstdlib>
0002 #include <kdevelop-pg-qt/kdev-pg-token-stream.h>
0003 #include "kdev-pg-char-sets.h"
0004 
0005 #include <iostream>
0006 #include <string>
0007 #include <QDebug>
0008 using namespace std;
0009 
0010 
0011 class TokenStream : public KDevPG::TokenStream, public QUtf8ToUcs4Iterator {
0012     typedef QUtf8ToUcs4Iterator Iterator;
0013 public:
0014     TokenStream(const Iterator& iter) : Iterator(iter)
0015     {}
0016     inline KDevPG::Token& next() {
0017 #define CURR_POS Iterator::plain()
0018 #define NEXT_CHR __extension__( { if(!Iterator::hasNext()) goto _end; Iterator::next(); } )
0019         const Iterator::InputInt *lpos = Iterator::plain();
0020         Iterator::Int chr = 0;
0021         int lstate = 0;
0022 _state_0:
0023         chr = NEXT_CHR;
0024         if (chr < 98) {
0025             if (chr < 32) {
0026                 if (chr == 9 || chr == 10) {/*1 action */
0027                     lpos = CURR_POS;
0028                     lstate = 1;
0029                     goto _state_37;
0030                 } else goto _end;
0031             } else {
0032                 if (chr < 48) {
0033                     if (chr == 32) {/*1 action */
0034                         lpos = CURR_POS;
0035                         lstate = 1;
0036                         goto _state_37;
0037                     } else goto _end;
0038                 } else {
0039                     if (chr < 58) {/*2 action */
0040                         lpos = CURR_POS;
0041                         lstate = 2;
0042                         goto _state_36;
0043                     } else goto _end;
0044                 }
0045             }
0046         } else {
0047             if (chr < 102) {
0048                 if (chr == 98) {
0049                     goto _state_31;
0050                 } else goto _end;
0051             } else {
0052                 if (chr < 228) {
0053                     if (chr == 102) {
0054                         goto _state_34;
0055                     } else goto _end;
0056                 } else {
0057                     if (chr == 228) {
0058                         goto _state_23;
0059                     } else goto _end;
0060                 }
0061             }
0062         }
0063 _state_1:
0064         chr = NEXT_CHR;
0065         if (chr == 115) {/*9 action */
0066             lpos = CURR_POS;
0067             lstate = 9;
0068             goto _state_38;
0069         } else goto _end;
0070 
0071 _state_2:
0072         chr = NEXT_CHR;
0073         if (chr == 167) {
0074             goto _state_1;
0075         } else goto _end;
0076 
0077 _state_3:
0078         chr = NEXT_CHR;
0079         if (chr == 32) {
0080             goto _state_2;
0081         } else goto _end;
0082 
0083 _state_4:
0084         chr = NEXT_CHR;
0085         if (chr == 101) {
0086             goto _state_3;
0087         } else goto _end;
0088 
0089 _state_5:
0090         chr = NEXT_CHR;
0091         if (chr == 107) {
0092             goto _state_4;
0093         } else goto _end;
0094 
0095 _state_6:
0096         chr = NEXT_CHR;
0097         if (chr == 105) {
0098             goto _state_5;
0099         } else goto _end;
0100 
0101 _state_7:
0102         chr = NEXT_CHR;
0103         if (chr == 108) {
0104             goto _state_6;
0105         } else goto _end;
0106 
0107 _state_8:
0108         chr = NEXT_CHR;
0109         if (chr == 32) {
0110             goto _state_7;
0111         } else goto _end;
0112 
0113 _state_9:
0114         chr = NEXT_CHR;
0115         if (chr == 116) {
0116             goto _state_8;
0117         } else goto _end;
0118 
0119 _state_10:
0120         chr = NEXT_CHR;
0121         if (chr == 111) {
0122             goto _state_9;
0123         } else goto _end;
0124 
0125 _state_11:
0126         chr = NEXT_CHR;
0127         if (chr == 110) {
0128             goto _state_10;
0129         } else goto _end;
0130 
0131 _state_12:
0132         chr = NEXT_CHR;
0133         if (chr == 32) {
0134             goto _state_11;
0135         } else goto _end;
0136 
0137 _state_13:
0138         chr = NEXT_CHR;
0139         if (chr == 111) {
0140             goto _state_12;
0141         } else goto _end;
0142 
0143 _state_14:
0144         chr = NEXT_CHR;
0145         if (chr == 100) {
0146             goto _state_13;
0147         } else goto _end;
0148 
0149 _state_15:
0150         chr = NEXT_CHR;
0151         if (chr == 32) {
0152             goto _state_14;
0153         } else goto _end;
0154 
0155 _state_16:
0156         chr = NEXT_CHR;
0157         if (chr == 73) {
0158             goto _state_15;
0159         } else goto _end;
0160 
0161 _state_17:
0162         chr = NEXT_CHR;
0163         if (chr == 32) {
0164             goto _state_16;
0165         } else goto _end;
0166 
0167 _state_18:
0168         chr = NEXT_CHR;
0169         if (chr == 44) {
0170             goto _state_17;
0171         } else goto _end;
0172 
0173 _state_19:
0174         chr = NEXT_CHR;
0175         if (chr == 104) {
0176             goto _state_18;
0177         } else goto _end;
0178 
0179 _state_20:
0180         chr = NEXT_CHR;
0181         if (chr == 104) {
0182             goto _state_19;
0183         } else goto _end;
0184 
0185 _state_21:
0186         chr = NEXT_CHR;
0187         goto _end;
0188 _state_22:
0189         chr = NEXT_CHR;
0190         if (chr == 252) {/*8 action */
0191             lpos = CURR_POS;
0192             lstate = 8;
0193             goto _state_21;
0194         } else goto _end;
0195 
0196 _state_23:
0197         chr = NEXT_CHR;
0198         if (chr == 246) {
0199             goto _state_22;
0200         } else goto _end;
0201 
0202 _state_24:
0203         chr = NEXT_CHR;
0204         goto _end;
0205 _state_25:
0206         chr = NEXT_CHR;
0207         goto _end;
0208 _state_26:
0209         chr = NEXT_CHR;
0210         if (chr == 114) {/*6 action */
0211             lpos = CURR_POS;
0212             lstate = 6;
0213             goto _state_25;
0214         } else goto _end;
0215 
0216 _state_27:
0217         chr = NEXT_CHR;
0218         if (chr == 97) {
0219             goto _state_26;
0220         } else goto _end;
0221 
0222 _state_28:
0223         chr = NEXT_CHR;
0224         goto _end;
0225 _state_29:
0226         chr = NEXT_CHR;
0227         goto _end;
0228 _state_30:
0229         chr = NEXT_CHR;
0230         if (chr < 122) {
0231             if (chr == 114) {/*4 action */
0232                 lpos = CURR_POS;
0233                 lstate = 4;
0234                 goto _state_29;
0235             } else goto _end;
0236         } else {
0237             if (chr == 122) {/*5 action */
0238                 lpos = CURR_POS;
0239                 lstate = 5;
0240                 goto _state_28;
0241             } else goto _end;
0242         }
0243 _state_31:
0244         chr = NEXT_CHR;
0245         if (chr < 228) {
0246             if (chr == 97) {
0247                 goto _state_30;
0248             } else goto _end;
0249         } else {
0250             if (chr == 228) {
0251                 goto _state_20;
0252             } else goto _end;
0253         }
0254 _state_32:
0255         chr = NEXT_CHR;
0256         if (chr == 98) {
0257             goto _state_27;
0258         } else goto _end;
0259 
0260 _state_33:
0261         chr = NEXT_CHR;
0262         if (chr < 114) {
0263             if (chr == 111) {/*3 action */
0264                 lpos = CURR_POS;
0265                 lstate = 3;
0266                 goto _state_32;
0267             } else goto _end;
0268         } else {
0269             if (chr == 114) {/*7 action */
0270                 lpos = CURR_POS;
0271                 lstate = 7;
0272                 goto _state_24;
0273             } else goto _end;
0274         }
0275 _state_34:
0276         chr = NEXT_CHR;
0277         if (chr == 111) {
0278             goto _state_33;
0279         } else goto _end;
0280 
0281 _state_35:
0282         chr = NEXT_CHR;
0283         if (chr >= 48 && chr < 58) {/*2 action */
0284             lpos = CURR_POS;
0285             lstate = 2;
0286             goto _state_35;
0287         } else goto _end;
0288 
0289 _state_36:
0290         chr = NEXT_CHR;
0291         if (chr < 48) {
0292             if (chr == 46) {/*2 action */
0293                 lpos = CURR_POS;
0294                 lstate = 2;
0295                 goto _state_35;
0296             } else goto _end;
0297         } else {
0298             if (chr < 58) {/*2 action */
0299                 lpos = CURR_POS;
0300                 lstate = 2;
0301                 goto _state_36;
0302             } else goto _end;
0303         }
0304 _state_37:
0305         chr = NEXT_CHR;
0306         if (chr < 32) {
0307             if (chr == 9 || chr == 10) {/*1 action */
0308                 lpos = CURR_POS;
0309                 lstate = 1;
0310                 goto _state_37;
0311             } else goto _end;
0312         } else {
0313             if (chr == 32) {/*1 action */
0314                 lpos = CURR_POS;
0315                 lstate = 1;
0316                 goto _state_37;
0317             } else goto _end;
0318         }
0319 _state_38:
0320         chr = NEXT_CHR;
0321         goto _end;
0322 _end:
0323 KDevPG::Token t;
0324 plain() = lpos;
0325         switch (lstate) {
0326         case 0:
0327 _fail: qDebug() << "error" << *lpos; exit(-1); return t;
0328         case 1: qDebug() << "whitespace"; return t;
0329         case 2: qDebug() << "dec-number"; return t;
0330         case 3: qDebug() << "foo"; return t;
0331         case 4: qDebug() << "bar"; return t;
0332         case 5: qDebug() << "baz"; return t;
0333         case 6: qDebug() << "foobar"; return t;
0334         case 7: qDebug() << "for"; return t;
0335         case 8: qDebug() << "umlauts"; return t;
0336         case 9: qDebug() << "anti-law"; return t;
0337         }
0338     }
0339 };
0340 
0341 int main()
0342 {
0343     string str;
0344     getline(cin, str);
0345     QByteArray qba(str.c_str(), str.size());
0346     QUtf8ToUcs4Iterator iter(qba);
0347     TokenStream stream(iter);
0348     while(stream.hasNext())
0349       stream.next();
0350 }