BPredicate.l 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * @file BPredicate.l
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * @section DESCRIPTION
  23. *
  24. * {@link BPredicate} lexer file.
  25. */
  26. %{
  27. #include <string.h>
  28. #include <stdlib.h>
  29. #include <predicate/LexMemoryBufferInput.h>
  30. #include <predicate/BPredicate_internal.h>
  31. #include <generated/bison_BPredicate.h>
  32. #define YY_EXTRA_TYPE LexMemoryBufferInput *
  33. #define YY_INPUT(buffer, res, max_size) \
  34. int bytes_read = LexMemoryBufferInput_Read(yyget_extra(yyscanner), buffer, max_size); \
  35. res = (bytes_read == 0 ? YY_NULL : bytes_read);
  36. %}
  37. %option reentrant stack noyywrap bison-bridge bison-locations
  38. %%
  39. \( return SPAR;
  40. \) return EPAR;
  41. , return COMMA;
  42. AND return AND;
  43. OR return OR;
  44. NOT return NOT;
  45. true return CONSTANT_TRUE;
  46. false return CONSTANT_FALSE;
  47. [a-zA-Z0-9_]+ {
  48. int l = strlen(yytext);
  49. char *p = malloc(l + 1);
  50. if (p) {
  51. memcpy(p, yytext, l);
  52. p[l] = '\0';
  53. }
  54. yylval->text = p;
  55. return NAME;
  56. }
  57. \"[^\"]*\" {
  58. int l = strlen(yytext);
  59. char *p = malloc(l - 1);
  60. if (p) {
  61. memcpy(p, yytext + 1, l - 2);
  62. p[l - 2] = '\0';
  63. }
  64. yylval->text = p;
  65. return STRING;
  66. }
  67. [ \t\n]+ ;
  68. . LexMemoryBufferInput_SetError(yyget_extra(yyscanner)); return 0; // remember failure and report EOF
  69. %%