/**************************************************************************** ** ** Lexical analyzer for meta object compiler ** ** Created : 930417 ** ** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. ** ** This file is part of the TQt GUI Toolkit. ** ** This file may be used under the terms of the GNU General ** Public License versions 2.0 or 3.0 as published by the Free ** Software Foundation and appearing in the files LICENSE.GPL2 ** and LICENSE.GPL3 included in the packaging of this file. ** Alternatively you may (at your option) use any later version ** of the GNU General Public License if such license has been ** publicly approved by Trolltech ASA (or its successors, if any) ** and the KDE Free TQt Foundation. ** ** Please review the following information to ensure GNU General ** Public Licensing requirements will be met: ** http://trolltech.com/products/qt/licenses/licensing/opensource/. ** If you are unsure which license is appropriate for your use, please ** review the following information: ** http://trolltech.com/products/qt/licenses/licensing/licensingoverview ** or contact the sales department at sales@trolltech.com. ** ** This file may be used under the terms of the Q Public License as ** defined by Trolltech ASA and appearing in the file LICENSE.TQPL ** included in the packaging of this file. Licensees holding valid TQt ** Commercial licenses may use this file in accordance with the TQt ** Commercial License Agreement provided with the Software. ** ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted ** herein. ** *****************************************************************************/ %{ #ifdef MOC_YACC_CODE #ifdef MOC_MWERKS_PLUGIN #ifdef Q_OS_MAC9 # define isascii(c) ((int)( (unsigned int) (c) <= (unsigned char)0x7F )) #endif const char *buf_buffer = NULL; long buf_size_total = 0, buf_index = 0; #define YY_INPUT(buf, result, max_size) \ { \ if(buf_index < buf_size_total ) { \ while(!isascii(buf_buffer[buf_index])) buf_index++; \ int ms = ((max_size < buf_size_total) ? max_size : buf_size_total); \ for(result = 0; result < ms; result++) { \ char c = buf_buffer[buf_index + result]; \ if(!isascii(c)) { \ buf_index++; \ break; \ } \ buf[result] = c == '\r' ? '\n' : c; \ } \ buf_index += result; \ } else result = YY_NULL; \ } #endif #include "tqstring.h" #define input yyinput // yyinput in C++ #define X if(lexDebug){fprintf(stderr,"LEX (%i) : %s\n",lineNo,yytext);}; #define Y if(lexDebug){fprintf(stderr,"LEX (%i) : %s\n",lineNo,yytext);}; /* #define Y if(lexDebug){fprintf(stderr,"LEX (%i) : %s updates level to %i\n"\ ,lineNo,yytext,templLevel);}; */ #define Z if(lexDebug){fprintf(stderr,"LEX (%i) : skipped the string %s\"\n"\ ,lineNo,yytext);}; #define BEGIN_INSIDE #define linput() \ ( (c = input()) == '\n' ? (lineNo++, c) : (c == EOF) ? 0 : c ) #include #include int classPLevel = 1; /* Depth of nested curly braces in IN_CLASS */ int namespacePLevel = 1; /* Depth of nested curly braces in IN_NAMESPACE */ int expLevel = 1; /* Depth of nested parentheses in IN_EXPR */ int enumLevel = 1; /* Depth of nested parentheses in IN_ENUM */ int fctLevel = 1; /* Depth of nested parentheses in IN_FCT */ int templLevel = 1; /* Depth of levels in IN_TEMPL_ARGS */ int lastState = 0; /* Remembers the state when a MOC_SKIP_BEGIN is encountered */ int skipLevel = 0; /* Depth of MOC_SKIP_BEGINs */ class TQString; extern void addExpressionChar( const char ); extern void addExpressionString( const char * ); extern void moc_warn( const char *msg ); %} %start OUTSIDE QT_DEF IN_CLASS IN_NAMESPACE IN_ENUM IN_EXPR IN_DEF_ARG IN_FCT IN_TEMPL_ARGS GIMME_SEMICOLON SKIP IN_PROPERTY IN_CLASSINFO ALMOSTSTRING \"([^"\n\\]|\\(.|\n))* STRING {ALMOSTSTRING}\" %% "class" { X; BEGIN QT_DEF; return CLASS; } "namespace" { X; BEGIN QT_DEF; return NAMESPACE; } "using" { X; BEGIN QT_DEF; return USING; } "template" { X; BEGIN QT_DEF; return TEMPLATE; } "TQ_OBJECT" { X; return TQ_OBJECT; } "signals" { X; return SIGNALS; } "slots" { X; return SLOTS; } "TQ_CLASSINFO" { X; return TQ_CLASSINFO; } "TQ_PROPERTY" { X; return TQ_PROPERTY; } "TQ_OVERRIDE" { X; return TQ_OVERRIDE; } "TQ_ENUMS" { X; return TQ_ENUMS; } "TQ_SETS" { X; return TQ_SETS; } "{" { fctLevel++;Y; } "}" { fctLevel--;Y;if (fctLevel==0){X;return '}';}} "{" { classPLevel++;Y; } "}" { classPLevel--;Y;if (classPLevel == 0) {X;return '}';} } "public" { X;if( classPLevel == 1 ) return PUBLIC; } "protected" { X;if( classPLevel == 1 ) return PROTECTED; } "private" { X;if( classPLevel == 1 ) return PRIVATE; } "signals" { X;if( classPLevel == 1 ) return SIGNALS; } "slots" { X;if( classPLevel == 1 ) return SLOTS; } "TQ_CLASSINFO" { X;if( classPLevel == 1 ) return TQ_CLASSINFO; } "TQ_OBJECT" { X; if ( classPLevel == 1 ) return TQ_OBJECT; else if ( classPLevel > 1 ) moc_warn( "Cannot use TQ_OBJECT in nested class." ); } "TQ_PROPERTY" { X;if( classPLevel == 1 ) return TQ_PROPERTY; } "TQ_OVERRIDE" { X;if( classPLevel == 1 ) return TQ_OVERRIDE; } "TQ_ENUMS" { X;if( classPLevel == 1 ) return TQ_ENUMS; } "TQ_SETS" { X;if( classPLevel == 1 ) return TQ_SETS; } "{" { namespacePLevel++;Y; } "}" { namespacePLevel--;Y;if (namespacePLevel == 0) {X;return '}';}} "class" { X; BEGIN QT_DEF; return CLASS; } "template" { X; BEGIN QT_DEF; return TEMPLATE; } "namespace" { X; BEGIN QT_DEF; return NAMESPACE; } "using" { X; BEGIN QT_DEF; return USING; } "(" { X; return '('; } ")" { X; return ')'; } "READ" { X; return READ; } "WRITE" { X; return WRITE; } "STORED" { X; return STORED; } "RESET" { X; return RESET; } "DESIGNABLE" { X; return DESIGNABLE; } "SCRIPTABLE" { X; return SCRIPTABLE; } "(" { expLevel++;X; } ")" { expLevel--;Y;if (expLevel == 0) { X; BEGIN QT_DEF; return ')';} } "[" { expLevel++;X; } "]" { expLevel--;X;if (expLevel == 0) { X; BEGIN QT_DEF; return ']';} } "," { if (expLevel == 0) { X; BEGIN QT_DEF; return ',' ;} } ";" { if (expLevel == 0) { X; BEGIN QT_DEF; return ';' ;} } "(" { expLevel++;X; } ")" { expLevel--;Y;if (expLevel == 0) { X; BEGIN QT_DEF; return ')';} } "[" { expLevel++;X; } "]" { expLevel--;X;if (expLevel == 0) { X; BEGIN QT_DEF; return ']';} } "," { if (expLevel <= 1) { X; BEGIN QT_DEF; return ',' ;} } ";" { if (expLevel == 0) { X; BEGIN QT_DEF; return ';' ;} } "(" { enumLevel++;X; } ")" { enumLevel--;X; } "[" { enumLevel++;X; } "]" { enumLevel--;X } "," { if (enumLevel == 0) { X; BEGIN QT_DEF; return ',' ;} } ";" { if (enumLevel == 0) { X; BEGIN QT_DEF; return ';' ;} } "}" { if (enumLevel == 0) { X; BEGIN QT_DEF; return '}' ;} } [[(<] { templLevel++; Y; addExpressionChar( yytext[0] ); } [])>] { templLevel--; Y; if ( templLevel == 0 ) { X; BEGIN QT_DEF; return yytext[0]; } else { addExpressionChar( yytext[0] ); } } "friend" { X;return FRIEND; } "typedef" { X;return TYPEDEF; } "auto" { X;return AUTO; } "register" { X;return REGISTER; } "static" { X;return STATIC; } "extern" { X;return EXTERN; } "inline" { X;return INLINE; } "__inline__" { X;return INLINE; } "virtual" { X;return VIRTUAL; } "const" { X;return CONST; } "volatile" { X;return VOLATILE; } "char" { X;return CHAR; } "short" { X;return SHORT; } "int" { X;return INT; } "long" { X;return LONG; } "signed" { X;return SIGNED; } "unsigned" { X;return UNSIGNED; } "float" { X;return FLOAT; } "double" { X;return DOUBLE; } "void" { X;return VOID; } "enum" { X;return ENUM; } "class" { X;return CLASS; } "struct" { X;return STRUCT; } "union" { X;return UNION; } "asm" { X;return ASM; } "private" { X;return PRIVATE; } "protected" { X;return PROTECTED; } "public" { X;return PUBLIC; } "operator" { X;return OPERATOR; } "::" { X;return DBL_COLON; } "..." { X;return TRIPLE_DOT; } "template" { X;return TEMPLATE; } "mutable" { X;return MUTABLE; } "throw" { X;return THROW; } "using" { X;return USING; } "namespace" { X;return NAMESPACE; } [_a-zA-Z][_a-zA-Z0-9]* { X; yylval.string = tqstrdup(yytext); return IDENTIFIER; } [_a-zA-Z][_a-zA-Z0-9]* { X; yylval.string = tqstrdup(yytext); return IDENTIFIER; } "(" { X; return '('; } ")" { X; return ')'; } "," { X; return ','; } {ALMOSTSTRING} { X; yylval.string = tqstrdup( yytext + 1 ); input(); /* discard the '"' */ return STRING; } [_a-zA-Z][_a-zA-Z0-9]* ; [_a-zA-Z][_a-zA-Z0-9]* ; [_a-zA-Z][_a-zA-Z0-9]* ; {STRING} { /* discard strings */ Z; } {STRING} { /* discard strings */ Z; } {STRING} { /* discard strings */ Z; } {ALMOSTSTRING} { /* discard strings */ Z; addExpressionString( yytext ); input(); /* discard the '"' */ } {ALMOSTSTRING} { X; addExpressionString( yytext ); input(); /* discard the '"' */ return STRING; } {ALMOSTSTRING} { X; yylval.string = tqstrdup( yytext + 1 ); input(); /* discard the '"' */ return STRING; } '.' { X; yylval.char_val = yytext[1]; return CHAR_VAL; } '\\a' { X; yylval.char_val = '\a'; return CHAR_VAL; } '\\b' { X; yylval.char_val = '\b'; return CHAR_VAL; } '\\f' { X; yylval.char_val = '\f'; return CHAR_VAL; } '\\n' { X; yylval.char_val = '\n'; return CHAR_VAL; } '\\r' { X; yylval.char_val = '\r'; return CHAR_VAL; } '\\t' { X; yylval.char_val = '\t'; return CHAR_VAL; } '\\v' { X; yylval.char_val = '\v'; return CHAR_VAL; } '\\\\' { X; yylval.char_val = '\\'; return CHAR_VAL; } '\\?' { X; yylval.char_val = '\?'; return CHAR_VAL; } '\\'' { X; yylval.char_val = '\''; return CHAR_VAL; } '\\\"' { X; yylval.char_val = '\"'; /* " */ return CHAR_VAL; } '\\0' { X; yylval.char_val = '\0'; return CHAR_VAL; } '\\[0-7]+' { X; yylval.char_val = (char)strtol( &yytext[1], 0, 8 ); return CHAR_VAL; } '\\x[0-9a-fA-F]+' { X; yylval.char_val = (char)strtol( &yytext[2], 0, 16 ); return CHAR_VAL; } '\\.' { X; yylval.char_val = ' '; return CHAR_VAL; } [0-9]+ { X; yylval.int_val = atoi(yytext); return INT_VAL; } [0-9]+\.[0-9]* { X; yylval.double_val = atof(yytext); return DOUBLE_VAL; } \.[0-9]+ { X; yylval.double_val = atof(yytext); return DOUBLE_VAL; } ^#define.*\\$ { /* skip multi-line macro-definitions */ int c, c1; input(); /* Discard the '\n'. */ do { c1=' '; while((c = linput()) != '\n' && c != 0) c1=c; if (c == 0) break; } while(c1=='\\'); unput(c); /* put back the '\n' or the EOF */ } ^[ \t]*#.* { /* preprocessor commands are skipped */} "//"[^\n]* { /* C++ comment */ TQCString s = yytext; if ( s.contains( "MOC_SKIP_BEGIN" ) ) { skipLevel++; if ( skipLevel == 1 ) { lastState = YYSTATE; BEGIN SKIP; } } else if ( s.contains( "MOC_SKIP_END" ) ) { if ( skipLevel == 0 ) { moc_warn(" MOC_SKIP_END without MOC_SKIP_BEGIN"); } else { skipLevel--; if ( skipLevel == 0 ) { BEGIN lastState; } } } } "/*" { /* C comment */ int c = ' '; do { if ( c!= '*' ) { while((c = linput()) != '*' && c != 0) ; } if (c == 0) break; } while(((c = linput())) != '/' && c != 0); if (c == 0) unput(c); } . { addExpressionChar( yytext[0] ); } [ \t\r\b\f]+ { /* spaces are important in template args, e.g. Foo */ addExpressionChar( yytext[0] ); } [ \t\r\b\f]+ ; . ; . ; . ; . { addExpressionChar( yytext[0] ); } . ; . { addExpressionChar( yytext[0] ); } . ; . ; . { X; return yytext[0]; } . { X; return ';'; } \n { lineNo++; } %% #endif // MOC_YACC_CODE