summaryrefslogtreecommitdiffstats
path: root/buildtools/lib/parsers/qmake/qmake.ll
blob: 9ed90e23d739ad54ecb2b9345f34cc0bb90176f6 (plain)
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
%{
/***************************************************************************
 *   Copyright (C) 2005 by Alexander Dymo                                  *
 *   adymo@tdevelop.org                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 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 General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
 ***************************************************************************/

#include <stdlib.h>

#define DONT_INCLUDE_FLEXLEXER

#include "qmake_lex.h"

/**
@file qmake.ll
QMake Lexer

There are 3 types of identifiers recognized by this lexer:
-id_simple: examples of such identifiers are qmake variables and scoped variables
at the left of the operator in assignments (like "SOURCES" in "SOURCES+=foo.cpp goo.cpp");
-id_list: those are "value list identifiers" at the right side in assignments
(like "foo.cpp goo.cpp" in "SOURCES+=foo.cpp goo.cpp");
-id_args: function arguments recognized as one identifier
(example: ""${QMAKE_FILE} is intended only for Windows!""
in "!win32-*:!wince-*:error("${QMAKE_FILE} is intended only for Windows!")" statements).
.

To recognize those identifiers two additional start conditions are used: list and funcargs.

@note "Not" operator (!) is recognized as a part of an identifier. Linefeeds passed to
the parser as NEWLINE tokens to preserve file structure but whitespaces are stripped
so no indentation is preserved by this lexer (and parser).

To debug this lexer, put the line below into the next flex file section.
%option debug
*/
%}

%option noyywrap
%option yylineno
%option c++
%option yyclass="QMake::Lexer"

%x vallist
%x funcargs

delim             [ \t]
ws                {delim}+
newline           (\n|\r|\r\n)
quote             "\""
var_value         [^#\r\n\t ]*[^\r\n\t \\]
quoted_var_value  {quote}({var_value}|[\t ])({var_value}|[\t ])*{quote}
letter            [A-Za-z]
digit             [0-9]
id_simple         ({digit}|{letter}|\!|-|_|\*|\$)({letter}|{digit}|\||\!|-|_|\*|\$|\.|\+)*
id_args           [^\r\n]*\)
number            {digit}+
comment           #[^\r\n]*{newline}
comment_cont      (\\{ws}*#[^\r\n]*{newline}|#[^\r\n]*\\{newline})
cont              \\{ws}*{newline}

%%
<vallist><<EOF>> {
    BEGIN(INITIAL);
    return Parser::token::token::ENDOFFILE;
}
<INITIAL>{ws} {}

<vallist>{ws} {
    mylval->value = QString::fromLocal8Bit( YYText(), YYLeng() );
    return Parser::token::token::LIST_WS;
}

<vallist,INITIAL>{cont} {
    BEGIN(vallist);
    mylval->value = QString::fromLocal8Bit( YYText(), YYLeng() );
    return Parser::token::token::CONT;
}

<vallist,INITIAL>{comment_cont} {
    BEGIN(vallist);
    mylval->value = QString::fromLocal8Bit( YYText(), YYLeng() );
    return Parser::token::token::COMMENT_CONT;
}

{id_simple} {
    mylval->value = QString::fromLocal8Bit( YYText(), YYLeng() );
    return (Parser::token::token::ID_SIMPLE);
}

<funcargs>{id_args} {
    mylval->value = QString::fromLocal8Bit( YYText(), YYLeng() );
    mylval->value = mylval->value.mid(0, mylval->value.length()-1);
    unput(')');
    BEGIN(INITIAL);
    return (Parser::token::token::ID_ARGS);
    }

<vallist>{var_value} {
    BEGIN(vallist);
    mylval->value = QString::fromLocal8Bit( YYText(), YYLeng() );
    return Parser::token::token::VARIABLE_VALUE;
}

<vallist>{quoted_var_value} {
    BEGIN(vallist);
    mylval->value = QString::fromLocal8Bit( YYText(), YYLeng() );
    return Parser::token::token::QUOTED_VARIABLE_VALUE;
}

"=" {
    BEGIN(vallist);
    mylval->value = QString::fromLocal8Bit( YYText(), YYLeng() );
    return Parser::token::token::EQ;
}

"+=" {
    BEGIN(vallist);
    mylval->value = QString::fromLocal8Bit( YYText(), YYLeng() );
    return Parser::token::token::PLUSEQ;
}

"-=" {
    BEGIN(vallist);
    mylval->value = QString::fromLocal8Bit( YYText(), YYLeng() );
    return Parser::token::token::MINUSEQ;
}

"*=" {
    BEGIN(vallist);
    mylval->value = QString::fromLocal8Bit( YYText(), YYLeng() );
    return Parser::token::token::STAREQ;
}

"~=" {
    BEGIN(vallist);
    mylval->value = QString::fromLocal8Bit( YYText(), YYLeng() );
    return Parser::token::token::TILDEEQ;
}

"{" {
    return Parser::token::token::LCURLY;
}

":"{delim}*"{" {
    return Parser::token::token::LCURLY;
}

"}" {
    return Parser::token::token::RCURLY;
}

"(" {
    BEGIN(funcargs);
    return Parser::token::token::LBRACE;
}

<funcargs,INITIAL>")" {
    BEGIN(INITIAL);
    return Parser::token::token::RBRACE;
}

":" {
    mylval->value = QString::fromLocal8Bit( YYText(), YYLeng() );
    return Parser::token::token::COLON;
}


<vallist>{ws}{newline} {
    BEGIN(INITIAL);
    mylval->value = QString::fromLocal8Bit( YYText(), YYLeng() );
    setLineEndingFromString( mylval->value );
    return Parser::token::token::NEWLINE;
}

<vallist,INITIAL>{newline} {
    BEGIN(INITIAL);
    mylval->value = QString::fromLocal8Bit( YYText(), YYLeng() );
    setLineEndingFromString( mylval->value );
    return Parser::token::token::NEWLINE;
}

<vallist,INITIAL>{comment} {
    BEGIN(INITIAL);
    mylval->value = QString::fromLocal8Bit( YYText(), YYLeng() );
    return (Parser::token::token::COMMENT);
}

%%
namespace QMake
{
    Lexer::Lexer( std::istream* argin, std::ostream* argout )
        : yyFlexLexer(argin, argout), mylval(0), m_lineEnding(None)
    {
    }

    int Lexer::yylex( QMake::Parser::semantic_type* yylval )
    {
        mylval = yylval;
        return yylex();
    }

    void Lexer::setLineEndingFromString( const QString& str )
    {
        if( str.endsWith("\r\n") && m_lineEnding == None )
            m_lineEnding = Windows;
        else if ( str.endsWith("\r") && m_lineEnding == None )
            m_lineEnding = MacOS;
        else if ( m_lineEnding == None )
            m_lineEnding = Unix;
    }

    Lexer::LineEnding Lexer::lineending()
    {
        return m_lineEnding;
    }
}

int QMakelex( QMake::Parser::semantic_type* yylval, QMake::Lexer* lexer)
{
    return lexer->yylex( yylval );
}