bitbakeparser.y 5.7 KB

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