aidl_language_l.ll 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. %{
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include "aidl_language.h"
  5. #include "aidl_language_y.h"
  6. #define YY_USER_ACTION yylloc->columns(yyleng);
  7. %}
  8. %option yylineno
  9. %option noyywrap
  10. %option nounput
  11. %option noinput
  12. %option reentrant
  13. %option bison-bridge
  14. %option bison-locations
  15. %x COPYING LONG_COMMENT
  16. identifier [_a-zA-Z][_a-zA-Z0-9]*
  17. whitespace ([ \t\r]+)
  18. intvalue [-+]?(0|[1-9][0-9]*)
  19. hexvalue 0[x|X][0-9a-fA-F]+
  20. floatvalue [-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?f?
  21. %%
  22. %{
  23. /* This happens at every call to yylex (every time we receive one token) */
  24. std::string extra_text;
  25. yylloc->step();
  26. %}
  27. \%\%\{ { extra_text += "/**"; BEGIN(COPYING); }
  28. <COPYING>\}\%\% { extra_text += "**/"; yylloc->step(); BEGIN(INITIAL); }
  29. <COPYING>.* { extra_text += yytext; }
  30. <COPYING>\n+ { extra_text += yytext; yylloc->lines(yyleng); }
  31. \/\* { extra_text += yytext; BEGIN(LONG_COMMENT); }
  32. <LONG_COMMENT>\*+\/ { extra_text += yytext; yylloc->step(); BEGIN(INITIAL); }
  33. <LONG_COMMENT>\*+ { extra_text += yytext; }
  34. <LONG_COMMENT>\n+ { extra_text += yytext; yylloc->lines(yyleng); }
  35. <LONG_COMMENT>[^*\n]+ { extra_text += yytext; }
  36. \"[^\"]*\" { yylval->token = new AidlToken(yytext, extra_text);
  37. return yy::parser::token::C_STR; }
  38. \/\/.*\n { extra_text += yytext; yylloc->lines(1); yylloc->step(); }
  39. \n+ { yylloc->lines(yyleng); yylloc->step(); }
  40. {whitespace} {}
  41. <<EOF>> { yyterminate(); }
  42. /* symbols */
  43. ; { return ';'; }
  44. \{ { return '{'; }
  45. \} { return '}'; }
  46. = { return '='; }
  47. , { return ','; }
  48. \. { return '.'; }
  49. \( { return '('; }
  50. \) { return ')'; }
  51. \[ { return '['; }
  52. \] { return ']'; }
  53. \< { return '<'; }
  54. \> { return '>'; }
  55. /* annotations */
  56. @{identifier} { yylval->token = new AidlToken(yytext + 1, extra_text);
  57. return yy::parser::token::ANNOTATION;
  58. }
  59. /* keywords */
  60. parcelable { yylval->token = new AidlToken("parcelable", extra_text);
  61. return yy::parser::token::PARCELABLE;
  62. }
  63. import { return yy::parser::token::IMPORT; }
  64. package { return yy::parser::token::PACKAGE; }
  65. in { return yy::parser::token::IN; }
  66. out { return yy::parser::token::OUT; }
  67. inout { return yy::parser::token::INOUT; }
  68. cpp_header { return yy::parser::token::CPP_HEADER; }
  69. const { return yy::parser::token::CONST; }
  70. true { return yy::parser::token::TRUE_LITERAL; }
  71. false { return yy::parser::token::FALSE_LITERAL; }
  72. interface { yylval->token = new AidlToken("interface", extra_text);
  73. return yy::parser::token::INTERFACE;
  74. }
  75. oneway { yylval->token = new AidlToken("oneway", extra_text);
  76. return yy::parser::token::ONEWAY;
  77. }
  78. /* scalars */
  79. {identifier} { yylval->token = new AidlToken(yytext, extra_text);
  80. return yy::parser::token::IDENTIFIER;
  81. }
  82. '.' { yylval->character = yytext[1];
  83. return yy::parser::token::CHARVALUE;
  84. }
  85. {intvalue} { yylval->token = new AidlToken(yytext, extra_text);
  86. return yy::parser::token::INTVALUE; }
  87. {floatvalue} { yylval->token = new AidlToken(yytext, extra_text);
  88. return yy::parser::token::FLOATVALUE; }
  89. {hexvalue} { yylval->token = new AidlToken(yytext, extra_text);
  90. return yy::parser::token::HEXVALUE; }
  91. /* lexical error! */
  92. . { return yy::parser::token::UNKNOWN; }
  93. %%
  94. // comment and whitespace handling
  95. // ================================================