252d87792f67c4f6ff7d3f2419d300689832b2cd
[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_IMMEDIATE STRING(v).
74         { e_immediate ( lex, s.string(), v.string() );
75           e_export( lex, s.string() );
76           s.release_this(); v.release_this(); }
77 statement ::= EXPORT variable(s) OP_COND STRING(v).
78         { e_cond( lex, s.string(), v.string() );
79           s.release_this(); v.release_this(); }
80
81 statement ::= variable(s) OP_ASSIGN STRING(v).
82         { e_assign( lex, s.string(), v.string() );
83           s.release_this(); v.release_this(); }
84 statement ::= variable(s) OP_PREPEND STRING(v).
85         { e_prepend( lex, s.string(), v.string() );
86           s.release_this(); v.release_this(); }
87 statement ::= variable(s) OP_APPEND STRING(v).
88         { e_append( lex, s.string() , v.string() );
89           s.release_this(); v.release_this(); }
90 statement ::= variable(s) OP_IMMEDIATE STRING(v).
91         { e_immediate( lex, s.string(), v.string() );
92           s.release_this(); v.release_this(); }
93 statement ::= variable(s) OP_COND STRING(v).
94         { e_cond( lex, s.string(), v.string() );
95           s.release_this(); v.release_this(); }
96
97 task ::= TSYMBOL(t) BEFORE TSYMBOL(b) AFTER  TSYMBOL(a).
98         { e_addtask( lex, t.string(), b.string(), a.string() );
99           t.release_this(); b.release_this(); a.release_this(); }
100 task ::= TSYMBOL(t) AFTER  TSYMBOL(a) BEFORE TSYMBOL(b).
101         { e_addtask( lex, t.string(), b.string(), a.string());
102           t.release_this(); a.release_this(); b.release_this(); }
103 task ::= TSYMBOL(t).
104         { e_addtask( lex, t.string(), NULL, NULL);
105           t.release_this();}
106 task ::= TSYMBOL(t) BEFORE TSYMBOL(b).
107         { e_addtask( lex, t.string(), b.string(), NULL);
108           t.release_this(); b.release_this(); }
109 task ::= TSYMBOL(t) AFTER  TSYMBOL(a).
110         { e_addtask( lex, t.string(), NULL, a.string());
111           t.release_this(); a.release_this(); }
112 tasks ::= tasks task.
113 tasks ::= task.
114 statement ::= ADDTASK tasks.
115
116 statement ::= ADDHANDLER SYMBOL(s).
117         { e_addhandler( lex, s.string()); s.release_this (); }
118
119 func ::= FSYMBOL(f). { e_export_func( lex, f.string()); f.release_this(); }
120 funcs ::= funcs func.
121 funcs ::= func.
122 statement ::= EXPORT_FUNC funcs.
123
124 inherit ::= ISYMBOL(i). { e_inherit( lex, i.string() ); i.release_this (); }
125 inherits ::= inherits inherit.
126 inherits ::= inherit.
127 statement ::= INHERIT inherits.
128
129 statement ::= INCLUDE ISYMBOL(i).
130         { e_include( lex, i.string() ); i.release_this(); }
131
132 statement ::= REQUIRE ISYMBOL(i).
133         { e_require( lex, i.string() ); i.release_this(); }
134
135 proc_body(r) ::= proc_body(l) PROC_BODY(b).
136         { /* concatenate body lines */
137           r.assignString( token_t::concatString(l.string(), b.string()) );
138           l.release_this ();
139           b.release_this ();
140         }
141 proc_body(b) ::= . { b.assignString(0); }
142 statement ::= variable(p) PROC_OPEN proc_body(b) PROC_CLOSE.
143         { e_proc( lex, p.string(), b.string() );
144           p.release_this(); b.release_this(); }
145 statement ::= PYTHON SYMBOL(p) PROC_OPEN proc_body(b) PROC_CLOSE.
146         { e_proc_python ( lex, p.string(), b.string() );
147           p.release_this(); b.release_this(); }
148 statement ::= PYTHON PROC_OPEN proc_body(b) PROC_CLOSE.
149         { e_proc_python( lex, NULL, b.string());
150           b.release_this (); }
151
152 statement ::= FAKEROOT SYMBOL(p) PROC_OPEN proc_body(b) PROC_CLOSE.
153         { e_proc_fakeroot( lex, p.string(), b.string() );
154           p.release_this (); b.release_this (); }
155
156 def_body(r) ::= def_body(l) DEF_BODY(b).
157         { /* concatenate body lines */
158           r.assignString( token_t::concatString(l.string(), b.string()) );
159           l.release_this (); b.release_this ();
160         }
161 def_body(b) ::= . { b.assignString( 0 ); }
162 statement ::= SYMBOL(p) DEF_ARGS(a) def_body(b).
163         { e_def( lex, p.string(), a.string(), b.string());
164           p.release_this(); a.release_this(); b.release_this(); }
165