Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

glcpp-lex.l 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. %{
  2. /*
  3. * Copyright © 2010 Intel Corporation
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. */
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include "glcpp.h"
  27. #include "glcpp-parse.h"
  28. %}
  29. %option reentrant noyywrap
  30. %option extra-type="glcpp_parser_t *"
  31. SPACE [[:space:]]
  32. NONSPACE [^[:space:]]
  33. NEWLINE [\n]
  34. HSPACE [ \t]
  35. HASH ^{HSPACE}*#{HSPACE}*
  36. IDENTIFIER [_a-zA-Z][_a-zA-Z0-9]*
  37. PUNCTUATION [][(){}.&*~!/%<>^|;,=+-]
  38. OTHER [^][(){}.&*~!/%<>^|;,=#[:space:]+-]+
  39. DECIMAL_INTEGER [1-9][0-9]*[uU]?
  40. OCTAL_INTEGER 0[0-7]*[uU]?
  41. HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
  42. %%
  43. /* Single-line comments */
  44. "//"[^\n]+\n {
  45. return NEWLINE;
  46. }
  47. /* Multi-line comments */
  48. [/][*]([^*]*[*]+[^/])*[^*]*[*]*[/] {
  49. if (yyextra->space_tokens)
  50. return SPACE;
  51. }
  52. {HASH}if/.*\n {
  53. yyextra->lexing_if = 1;
  54. yyextra->space_tokens = 0;
  55. return HASH_IF;
  56. }
  57. {HASH}elif/.*\n {
  58. yyextra->lexing_if = 1;
  59. yyextra->space_tokens = 0;
  60. return HASH_ELIF;
  61. }
  62. {HASH}else/.*\n {
  63. yyextra->space_tokens = 0;
  64. return HASH_ELSE;
  65. }
  66. {HASH}endif/.*\n {
  67. yyextra->space_tokens = 0;
  68. return HASH_ENDIF;
  69. }
  70. /* When skipping (due to an #if 0 or similar) consume anything
  71. * up to a newline. We do this less priroty than any
  72. * #if-related directive (#if, #elif, #else, #endif), but with
  73. * more priority than any other directive or token to avoid
  74. * any side-effects from skipped content.
  75. *
  76. * We use the lexing_if flag to avoid skipping any part of an
  77. * if conditional expression. */
  78. [^\n]+/\n {
  79. if (yyextra->lexing_if ||
  80. yyextra->skip_stack == NULL ||
  81. yyextra->skip_stack->type == SKIP_NO_SKIP)
  82. {
  83. REJECT;
  84. }
  85. }
  86. {HASH}define{HSPACE}+/{IDENTIFIER}"(" {
  87. yyextra->space_tokens = 0;
  88. return HASH_DEFINE_FUNC;
  89. }
  90. {HASH}define {
  91. yyextra->space_tokens = 0;
  92. return HASH_DEFINE_OBJ;
  93. }
  94. {HASH}undef {
  95. yyextra->space_tokens = 0;
  96. return HASH_UNDEF;
  97. }
  98. {HASH} {
  99. yyextra->space_tokens = 0;
  100. return HASH;
  101. }
  102. {DECIMAL_INTEGER} {
  103. yylval.str = xtalloc_strdup (yyextra, yytext);
  104. return INTEGER_STRING;
  105. }
  106. {OCTAL_INTEGER} {
  107. yylval.str = xtalloc_strdup (yyextra, yytext);
  108. return INTEGER_STRING;
  109. }
  110. {HEXADECIMAL_INTEGER} {
  111. yylval.str = xtalloc_strdup (yyextra, yytext);
  112. return INTEGER_STRING;
  113. }
  114. "<<" {
  115. return LEFT_SHIFT;
  116. }
  117. ">>" {
  118. return RIGHT_SHIFT;
  119. }
  120. "<=" {
  121. return LESS_OR_EQUAL;
  122. }
  123. ">=" {
  124. return GREATER_OR_EQUAL;
  125. }
  126. "==" {
  127. return EQUAL;
  128. }
  129. "!=" {
  130. return NOT_EQUAL;
  131. }
  132. "&&" {
  133. return AND;
  134. }
  135. "||" {
  136. return OR;
  137. }
  138. "##" {
  139. return PASTE;
  140. }
  141. "defined" {
  142. return DEFINED;
  143. }
  144. {IDENTIFIER} {
  145. yylval.str = xtalloc_strdup (yyextra, yytext);
  146. return IDENTIFIER;
  147. }
  148. {PUNCTUATION} {
  149. return yytext[0];
  150. }
  151. {OTHER}+ {
  152. yylval.str = xtalloc_strdup (yyextra, yytext);
  153. return OTHER;
  154. }
  155. {HSPACE}+ {
  156. if (yyextra->space_tokens) {
  157. return SPACE;
  158. }
  159. }
  160. \n {
  161. yyextra->lexing_if = 0;
  162. return NEWLINE;
  163. }
  164. %%