summaryrefslogtreecommitdiffstats
path: root/buildtools/lib/parsers/autotools/autotools.ll
blob: 7e6ddf4f2d3fa1dd12376c8d888f62e81780802d (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
%{
/***************************************************************************
 *   Copyright (C) 2005 by Alexander Dymo                                  *
 *   [email protected]                                                    *
 *                                                                         *
 *   Copyright (c) 2005 by Matt Rogers                                     *
 *   [email protected]                                                         *
 *                                                                         *
 *   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  02111-1307, USA.             *
 ***************************************************************************/

#include <autotools_yacc.h>
#include <stdlib.h>

/**
@file autotools.ll
Autotools 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

%x list
%x funcargs
%x conditional

delim             [ \t]
ws                {delim}+
letter            [A-Za-z]
digit             [0-9]
id_simple         ({digit}|{letter}|\!|-|_|\*|\$|@)({letter}|{digit}|\||\!|-|_|\*|\$|\(|\.|\+|\-|\)|\/)*
id_list           [^\n]*\\{ws}*
id_args           [^\n]*\)
number            {digit}+
comment           #.*
comment_cont      {ws}*#.*\n
id_list_single    [^\n]*
cont              \\{ws}*\n
keywords          (if|else|endif|include)
rule              [\t]+[^\n]*

%%

<list,INITIAL>{ws}     {}
<list,INITIAL>{cont}   { BEGIN(list); return CONT; }
{keywords} {
	yylval.value = yytext;
	if ( yylval.value == "if" )
		return IF_KEYWORD;
	
	if ( yylval.value == "else" )
		return ELSE_KEYWORD;
	
	if ( yylval.value == "endif" )
		return ENDIF_KEYWORD;
	
	return KEYWORD;
}


{id_simple}            { yylval.value = yytext; return (ID_SIMPLE); }

<INITIAL>{rule} {
	yylval.value = yytext;
	return RULE;
}

<list>{id_list} {
	yylval.value = yytext;
	yylval.value = yylval.value.mid(0, yylval.value.findRev("\\"));
	unput('\\');
	BEGIN(INITIAL);
	return (ID_LIST); 
    }

<list>{comment_cont} { 
	yylval.value = yytext;
	BEGIN(list);
	return (LIST_COMMENT); 
    }

<list>{id_list_single} {
	yylval.value = yytext;
	BEGIN(INITIAL);
	return (ID_LIST_SINGLE); 
    }

<funcargs>{id_args} { 
	yylval.value = yytext;
	yylval.value = yylval.value.mid(0, yylval.value.length()-1);
	unput(')');
	BEGIN(INITIAL);
	return (ID_ARGS); 
    }

"="                      { BEGIN(list); yylval.value = yytext; return EQ; }
"+="                     { BEGIN(list); yylval.value = yytext; return PLUSEQ; }
"{"                      { return LCURLY; }
"}"                      { return RCURLY; }
":"                      { BEGIN(list); yylval.value = yytext; return COLON; }
<list,INITIAL>"\n"       { BEGIN(INITIAL); return NEWLINE; }
{comment}                { yylval.value = yytext; return (COMMENT); }

%%