c18e53543b74eb0bf4e3cd4b3eef2b2718db58d0
[vuplus_bitbake] / lib / bb / parse / parse_c / bitbakeparser.y
1 /* bbp.lemon 
2
3    written by Marc Singer
4    6 January 2005
5
6    This program is free software; you can redistribute it and/or
7    modify it under the terms of the GNU General Public License as
8    published by the Free Software Foundation; either version 2 of the
9    License, or (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful, but
12    WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19    USA.
20
21    DESCRIPTION
22    -----------
23
24    lemon parser specification file for a BitBake input file parser.
25
26    Most of the interesting shenanigans are done in the lexer.  The
27    BitBake grammar is not regular.  In order to emit tokens that
28    the parser can properly interpret in LALR fashion, the lexer
29    manages the interpretation state.  This is why there are ISYMBOLs,
30    SYMBOLS, and TSYMBOLS.
31
32    This parser was developed by reading the limited available
33    documentation for BitBake and by analyzing the available BB files.
34    There is no assertion of correctness to be made about this parser.
35
36 */
37
38 %token_type {token_t}
39 %name bbparse
40 %token_prefix   T_
41 %extra_argument  {lex_t* lex}
42
43 %include {
44 #include "token.h"
45 #include "lexer.h"
46 #include "python_output.h"
47 }
48
49
50 %token_destructor { $$.release_this (); }
51
52 %syntax_error     { e_parse_error( lex ); }
53
54 program ::= statements.
55
56 statements ::= statements statement.
57 statements ::= .
58
59 variable(r) ::= SYMBOL(s).
60         { r.assignString( (char*)s.string() );
61           s.assignString( 0 );
62           s.release_this(); }
63 variable(r) ::= VARIABLE(v).
64         {
65           r.assignString( (char*)v.string() );
66           v.assignString( 0 );
67           v.release_this(); }
68
69 statement ::= EXPORT variable(s) OP_ASSIGN STRING(v).
70         { e_assign( lex, s.string(), v.string() );
71           e_export( lex, s.string() );
72           s.release_this(); v.release_this(); }
73 statement ::= EXPORT variable(s) OP_PREDOT STRING(v).
74         { e_precat( lex, s.string(), v.string() );
75           e_export( lex, s.string() );
76           s.release_this(); v.release_this(); }
77 statement ::= EXPORT variable(s) OP_POSTDOT STRING(v).
78         { e_postcat( lex, s.string(), v.string() );
79           e_export( lex, s.string() );
80           s.release_this(); v.release_this(); }
81 statement ::= EXPORT variable(s) OP_IMMEDIATE STRING(v).
82         { e_immediate ( lex, s.string(), v.string() );
83           e_export( lex, s.string() );
84           s.release_this(); v.release_this(); }
85 statement ::= EXPORT variable(s) OP_COND STRING(v).
86         { e_cond( lex, s.string(), v.string() );
87           s.release_this(); v.release_this(); }
88
89 statement ::= variable(s) OP_ASSIGN STRING(v).
90         { e_assign( lex, s.string(), v.string() );
91           s.release_this(); v.release_this(); }
92 statement ::= variable(s) OP_PREDOT STRING(v).
93         { e_precat( lex, s.string(), v.string() );
94           s.release_this(); v.release_this(); }
95 statement ::= variable(s) OP_POSTDOT STRING(v).
96         { e_postcat( lex, s.string(), v.string() );
97           s.release_this(); v.release_this(); }
98 statement ::= variable(s) OP_PREPEND STRING(v).
99         { e_prepend( lex, s.string(), v.string() );
100           s.release_this(); v.release_this(); }
101 statement ::= variable(s) OP_APPEND STRING(v).
102         { e_append( lex, s.string() , v.string() );
103           s.release_this(); v.release_this(); }
104 statement ::= variable(s) OP_IMMEDIATE STRING(v).
105         { e_immediate( lex, s.string(), v.string() );
106           s.release_this(); v.release_this(); }
107 statement ::= variable(s) OP_COND STRING(v).
108         { e_cond( lex, s.string(), v.string() );
109           s.release_this(); v.release_this(); }
110
111 task ::= TSYMBOL(t) BEFORE TSYMBOL(b) AFTER  TSYMBOL(a).
112         { e_addtask( lex, t.string(), b.string(), a.string() );
113           t.release_this(); b.release_this(); a.release_this(); }
114 task ::= TSYMBOL(t) AFTER  TSYMBOL(a) BEFORE TSYMBOL(b).
115         { e_addtask( lex, t.string(), b.string(), a.string());
116           t.release_this(); a.release_this(); b.release_this(); }
117 task ::= TSYMBOL(t).
118         { e_addtask( lex, t.string(), NULL, NULL);
119           t.release_this();}
120 task ::= TSYMBOL(t) BEFORE TSYMBOL(b).
121         { e_addtask( lex, t.string(), b.string(), NULL);
122           t.release_this(); b.release_this(); }
123 task ::= TSYMBOL(t) AFTER  TSYMBOL(a).
124         { e_addtask( lex, t.string(), NULL, a.string());
125           t.release_this(); a.release_this(); }
126 tasks ::= tasks task.
127 tasks ::= task.
128 statement ::= ADDTASK tasks.
129
130 statement ::= ADDHANDLER SYMBOL(s).
131         { e_addhandler( lex, s.string()); s.release_this (); }
132
133 func ::= FSYMBOL(f). { e_export_func( lex, f.string()); f.release_this(); }
134 funcs ::= funcs func.
135 funcs ::= func.
136 statement ::= EXPORT_FUNC funcs.
137
138 inherit ::= ISYMBOL(i). { e_inherit( lex, i.string() ); i.release_this (); }
139 inherits ::= inherits inherit.
140 inherits ::= inherit.
141 statement ::= INHERIT inherits.
142
143 statement ::= INCLUDE ISYMBOL(i).
144         { e_include( lex, i.string() ); i.release_this(); }
145
146 statement ::= REQUIRE ISYMBOL(i).
147         { e_require( lex, i.string() ); i.release_this(); }
148
149 proc_body(r) ::= proc_body(l) PROC_BODY(b).
150         { /* concatenate body lines */
151           r.assignString( token_t::concatString(l.string(), b.string()) );
152           l.release_this ();
153           b.release_this ();
154         }
155 proc_body(b) ::= . { b.assignString(0); }
156 statement ::= variable(p) PROC_OPEN proc_body(b) PROC_CLOSE.
157         { e_proc( lex, p.string(), b.string() );
158           p.release_this(); b.release_this(); }
159 statement ::= PYTHON SYMBOL(p) PROC_OPEN proc_body(b) PROC_CLOSE.
160         { e_proc_python ( lex, p.string(), b.string() );
161           p.release_this(); b.release_this(); }
162 statement ::= PYTHON PROC_OPEN proc_body(b) PROC_CLOSE.
163         { e_proc_python( lex, NULL, b.string());
164           b.release_this (); }
165
166 statement ::= FAKEROOT SYMBOL(p) PROC_OPEN proc_body(b) PROC_CLOSE.
167         { e_proc_fakeroot( lex, p.string(), b.string() );
168           p.release_this (); b.release_this (); }
169
170 def_body(r) ::= def_body(l) DEF_BODY(b).
171         { /* concatenate body lines */
172           r.assignString( token_t::concatString(l.string(), b.string()) );
173           l.release_this (); b.release_this ();
174         }
175 def_body(b) ::= . { b.assignString( 0 ); }
176 statement ::= SYMBOL(p) DEF_ARGS(a) def_body(b).
177         { e_def( lex, p.string(), a.string(), b.string());
178           p.release_this(); a.release_this(); b.release_this(); }
179