util/lexgen/tokenizer.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the utils of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 // auto generated. DO NOT EDIT.
       
    42 class RegExpTokenizer
       
    43 {
       
    44 public:
       
    45     RegExpTokenizer(const QString &inp);
       
    46 
       
    47     inline QChar next() {
       
    48         return (pos < input.length()) ? input.at(pos++) : QChar();
       
    49     }
       
    50     int lex();
       
    51 
       
    52     QString input;
       
    53     int pos;
       
    54     int lexemStart;
       
    55     int lexemLength;
       
    56 };
       
    57 
       
    58 RegExpTokenizer::RegExpTokenizer(const QString &inp)
       
    59 {
       
    60     input = inp;
       
    61     pos = 0;
       
    62     lexemStart = 0;
       
    63     lexemLength = 0;
       
    64 }
       
    65 
       
    66 
       
    67 int RegExpTokenizer::lex()
       
    68 {
       
    69     lexemStart = pos;
       
    70     lexemLength = 0;
       
    71     int lastAcceptingPos = -1;
       
    72     int token = -1;
       
    73     QChar ch;
       
    74     
       
    75     // initial state
       
    76         ch = next();
       
    77         if (ch.unicode() >= 1 && ch.unicode() <= 33)
       
    78             goto state_1;
       
    79         if (ch.unicode() == 34)
       
    80             goto state_2;
       
    81         if (ch.unicode() >= 35 && ch.unicode() <= 39)
       
    82             goto state_1;
       
    83         if (ch.unicode() == 40) {
       
    84             token = RE2NFA::TOK_LPAREN;
       
    85             goto found;
       
    86         }
       
    87         if (ch.unicode() == 41) {
       
    88             token = RE2NFA::TOK_RPAREN;
       
    89             goto found;
       
    90         }
       
    91         if (ch.unicode() == 42) {
       
    92             token = RE2NFA::TOK_STAR;
       
    93             goto found;
       
    94         }
       
    95         if (ch.unicode() == 43) {
       
    96             token = RE2NFA::TOK_PLUS;
       
    97             goto found;
       
    98         }
       
    99         if (ch.unicode() == 44) {
       
   100             token = RE2NFA::TOK_COMMA;
       
   101             goto found;
       
   102         }
       
   103         if (ch.unicode() == 45)
       
   104             goto state_1;
       
   105         if (ch.unicode() == 46) {
       
   106             token = RE2NFA::TOK_DOT;
       
   107             goto found;
       
   108         }
       
   109         if (ch.unicode() >= 47 && ch.unicode() <= 62)
       
   110             goto state_1;
       
   111         if (ch.unicode() == 63) {
       
   112             token = RE2NFA::TOK_QUESTION;
       
   113             goto found;
       
   114         }
       
   115         if (ch.unicode() >= 64 && ch.unicode() <= 90)
       
   116             goto state_1;
       
   117         if (ch.unicode() == 91)
       
   118             goto state_10;
       
   119         if (ch.unicode() == 92)
       
   120             goto state_11;
       
   121         if (ch.unicode() >= 93 && ch.unicode() <= 122)
       
   122             goto state_1;
       
   123         if (ch.unicode() == 123) {
       
   124             token = RE2NFA::TOK_LBRACE;
       
   125             goto found;
       
   126         }
       
   127         if (ch.unicode() == 124) {
       
   128             token = RE2NFA::TOK_OR;
       
   129             goto found;
       
   130         }
       
   131         if (ch.unicode() == 125) {
       
   132             token = RE2NFA::TOK_RBRACE;
       
   133             goto found;
       
   134         }
       
   135         if (ch.unicode() >= 126)
       
   136             goto state_1;
       
   137         goto out;
       
   138     state_1:
       
   139         lastAcceptingPos = pos;
       
   140         token = RE2NFA::TOK_STRING;
       
   141         goto out;
       
   142     state_2:
       
   143         lastAcceptingPos = pos;
       
   144         token = RE2NFA::TOK_STRING;
       
   145         ch = next();
       
   146         if (ch.unicode() >= 1 && ch.unicode() <= 33)
       
   147             goto state_15;
       
   148         if (ch.unicode() == 34)
       
   149             goto state_16;
       
   150         if (ch.unicode() >= 35)
       
   151             goto state_15;
       
   152         goto out;
       
   153     state_10:
       
   154         ch = next();
       
   155         if (ch.unicode() >= 1 && ch.unicode() <= 91)
       
   156             goto state_17;
       
   157         if (ch.unicode() == 92)
       
   158             goto state_18;
       
   159         if (ch.unicode() == 93)
       
   160             goto state_19;
       
   161         if (ch.unicode() >= 94)
       
   162             goto state_17;
       
   163         goto out;
       
   164     state_11:
       
   165         lastAcceptingPos = pos;
       
   166         token = RE2NFA::TOK_STRING;
       
   167         ch = next();
       
   168         if (ch.unicode() >= 1)
       
   169             goto state_20;
       
   170         goto out;
       
   171     state_15:
       
   172         ch = next();
       
   173         if (ch.unicode() >= 1 && ch.unicode() <= 33)
       
   174             goto state_15;
       
   175         if (ch.unicode() == 34)
       
   176             goto state_16;
       
   177         if (ch.unicode() >= 35)
       
   178             goto state_15;
       
   179         goto out;
       
   180     state_16:
       
   181         lastAcceptingPos = pos;
       
   182         token = RE2NFA::TOK_QUOTED_STRING;
       
   183         goto out;
       
   184     state_17:
       
   185         ch = next();
       
   186         if (ch.unicode() >= 1 && ch.unicode() <= 91)
       
   187             goto state_17;
       
   188         if (ch.unicode() == 92)
       
   189             goto state_18;
       
   190         if (ch.unicode() == 93)
       
   191             goto state_19;
       
   192         if (ch.unicode() >= 94)
       
   193             goto state_17;
       
   194         goto out;
       
   195     state_18:
       
   196         ch = next();
       
   197         if (ch.unicode() >= 1 && ch.unicode() <= 91)
       
   198             goto state_17;
       
   199         if (ch.unicode() == 92)
       
   200             goto state_18;
       
   201         if (ch.unicode() == 93)
       
   202             goto state_21;
       
   203         if (ch.unicode() >= 94)
       
   204             goto state_17;
       
   205         goto out;
       
   206     state_19:
       
   207         lastAcceptingPos = pos;
       
   208         token = RE2NFA::TOK_SEQUENCE;
       
   209         goto out;
       
   210     state_20:
       
   211         lastAcceptingPos = pos;
       
   212         token = RE2NFA::TOK_STRING;
       
   213         goto out;
       
   214     state_21:
       
   215         lastAcceptingPos = pos;
       
   216         token = RE2NFA::TOK_SEQUENCE;
       
   217         ch = next();
       
   218         if (ch.unicode() >= 1 && ch.unicode() <= 91)
       
   219             goto state_17;
       
   220         if (ch.unicode() == 92)
       
   221             goto state_18;
       
   222         if (ch.unicode() == 93)
       
   223             goto state_19;
       
   224         if (ch.unicode() >= 94)
       
   225             goto state_17;
       
   226         goto out;
       
   227     found:
       
   228     lastAcceptingPos = pos;
       
   229     
       
   230     out:
       
   231     if (lastAcceptingPos != -1) {
       
   232         lexemLength = lastAcceptingPos - lexemStart;
       
   233         pos = lastAcceptingPos;
       
   234     }
       
   235     return token;
       
   236 }
       
   237