1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
/*
Copyright (C) 2010 George Kiagiadakis <kiagiadakis.george@gmail.com>
Copyright (C) 2010 Collabora Ltd.
@author George Kiagiadakis <george.kiagiadakis@collabora.co.uk>
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
%{
#include "yystype.h"
#include "generator.h"
#define YY_DECL int yylex(CodeGen *codegen)
void yyerror(CodeGen *codegen, const char *msg);
%}
%option noyywrap
%option yylineno
%option stack
id [a-zA-Z][a-zA-Z_0-9]*
%x REGISTER_TYPE
%x REGISTER_WRAPPER
%x ENUM
%x ENUM_EAT_ASSIGNMENT
%x INSTRUCTION
%x LINE_COMMENT
%x C_STYLE_COMMENT
%x NAMESPACE
%x CLASS
%x EAT_TEMPLATE
%x MACRO
%%
<REGISTER_TYPE,REGISTER_WRAPPER,ENUM,INSTRUCTION>{id} { yylval.Id = new QByteArray(yytext); return IDENTIFIER; }
Q[A-Z]+_REGISTER_TYPE\( { yy_push_state(REGISTER_TYPE); return REGISTER_TYPE_BEGIN; }
<REGISTER_TYPE>{
:: { return SCOPE_RESOLUTION_OPERATOR; }
\) { yy_pop_state(); return REGISTER_TYPE_END; }
[[:space:]]*
. { yyerror(codegen, "Syntax error in QGLIB_REGISTER_TYPE"); }
}
Q[A-Z]+_WRAPPER\( { yy_push_state(REGISTER_WRAPPER); return REGISTER_WRAPPER_BEGIN; }
Q[A-Z]+_WRAPPER_DIFFERENT_C_CLASS\( { yy_push_state(REGISTER_WRAPPER); return REGISTER_WRAPPER_BEGIN; }
Q[A-Z]+_WRAPPER_FAKE_SUBCLASS\( { yy_push_state(REGISTER_WRAPPER); return REGISTER_WRAPPER_SUBCLASS_BEGIN; }
<REGISTER_WRAPPER>{
, { return COMMA; }
\) { yy_pop_state(); return REGISTER_WRAPPER_END; }
[[:space:]]*
. { yyerror(codegen, "Syntax error in wrapper definition"); }
}
[[:space:]]enum { yy_push_state(ENUM); return ENUM_KEYWORD; }
<ENUM>{
\{ { return LEFT_BRACE; }
\} { return RIGHT_BRACE; }
, { return COMMA; }
= { yy_push_state(ENUM_EAT_ASSIGNMENT); }
; { yy_pop_state(); return SEMICOLON; }
[[:space:]]*
. { yyerror(codegen, "Syntax error in enum definition"); }
}
<ENUM_EAT_ASSIGNMENT>{
, { unput(','); yy_pop_state(); }
\} { unput('}'); yy_pop_state(); }
\n
.
}
<*>\/\/ { yy_push_state(LINE_COMMENT); }
<LINE_COMMENT>{
\n { yy_pop_state(); }
codegen: { yy_push_state(INSTRUCTION); return INSTRUCTIONS_BEGIN; }
.
}
<INSTRUCTION>{
\n { unput('\n'); yy_pop_state(); return INSTRUCTIONS_END; }
= { return INSTRUCTIONS_ASSIGN_OPERATOR; }
, { return INSTRUCTIONS_SEPARATOR; }
[[:space:]]
. { yyerror(codegen, "Syntax error in instruction comment"); }
}
<*>\/\* { yy_push_state(C_STYLE_COMMENT); }
<C_STYLE_COMMENT>{
\*\/ { yy_pop_state(); }
\n
.
}
[[:space:]]namespace { yy_push_state(NAMESPACE); return NAMESPACE_KEYWORD; }
<NAMESPACE>{
{id} { yylval.Id = new QByteArray(yytext); yy_pop_state(); return IDENTIFIER; }
[[:space:]]*
. { yyerror(codegen, "Expected identifier after namespace keyword"); }
}
[[:space:]]class { yy_push_state(CLASS); return CLASS_KEYWORD; }
<CLASS>{
[A-Z]+_EXPORT
{id} { yylval.Id = new QByteArray(yytext); yy_pop_state(); return IDENTIFIER; }
[[:space:]]*
. { yyerror(codegen, "Expected identifier after class keyword"); }
}
template[[:space:]]*\< { yy_push_state(EAT_TEMPLATE); }
<EAT_TEMPLATE>{
\< { yy_push_state(EAT_TEMPLATE); };
\> { yy_pop_state(); }
\n
.
}
/* Eats only one-line defines. Used to eat the #define QGLIB_REGISTER_TYPE(T),
which would be a syntax error for codegen otherwise. */
#define { yy_push_state(MACRO); }
<MACRO>{
\n { yy_pop_state(); }
.
}
<*><<EOF>> { return EOF; }
\n
.
%%
|