PageRenderTime 55ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/OpenSLP_1-1-5/openslp/common/slp_filter_l.l

#
LEX | 168 lines | 114 code | 28 blank | 26 comment | 0 complexity | df8205588ef06ce7436af1a493e75fea MD5 | raw file
Possible License(s): BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-2.1
  1. /*******************************************************************
  2. * Description: encode/decode LDAP filters
  3. *
  4. * Originated: 04-21-2001
  5. * Original Author: Mike Day - md@soft-hackle.net
  6. *
  7. * Copyright (C) Michael Day, 2001
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *******************************************************************/
  23. %{
  24. #undef YYLMAX
  25. #define YYLMAX 2048
  26. #define yymaxdepth slp_filter_maxdepth
  27. #define yyparse slp_filter_parse
  28. #define yylex slp_filter_lex
  29. #define yyerror slp_filter_error
  30. #define yylval slp_filter_lval
  31. #define yychar slp_filter_char
  32. #define yydebug slp_filter_debug
  33. #define yypact slp_filter_pact
  34. #define yyr1 slp_filter_r1
  35. #define yyr2 slp_filter_r2
  36. #define yydef slp_filter_def
  37. #define yychk slp_filter_chk
  38. #define yypgo slp_filter_pgo
  39. #define yyact slp_filter_act
  40. #define yyexca slp_filter_exca
  41. #define yyerrflag slp_filter_errflag
  42. #define yynerrs slp_filter_nerrs
  43. #define yyps slp_filter_ps
  44. #define yypv slp_filter_pv
  45. #define yys slp_filter_s
  46. #define yy_yys slp_filter_yys
  47. #define yystate slp_filter_state
  48. #define yytmp slp_filter_tmp
  49. #define yyv slp_filter_v
  50. #define yy_yyv slp_filter_yyv
  51. #define yyval slp_filter_val
  52. #define yylloc slp_filter_lloc
  53. #define yyreds slp_filter_reds
  54. #define yytoks slp_filter_toks
  55. #define yylhs slp_filter_yylhs
  56. #define yylen slp_filter_yylen
  57. #define yydefred slp_filter_yydefred
  58. #define yydgoto slp_filter_yydgoto
  59. #define yysindex slp_filter_yysindex
  60. #define yyrindex slp_filter_yyrindex
  61. #define yygindex slp_filter_yygindex
  62. #define yytable slp_filter_yytable
  63. #define yycheck slp_filter_yycheck
  64. #define yyname slp_filter_yyname
  65. #define yyrule slp_filter_yyrule
  66. #define YY_NO_UNPUT
  67. #include "slp_filter.h"
  68. #include "slp_filter_y.h"
  69. #include "slp_xmalloc.h"
  70. static char buf[2052];
  71. void slp_filter_error(char *, ...);
  72. void slp_filter_close_lexer(unsigned int handle);
  73. unsigned int slp_filter_init_lexer(const char *s);
  74. %}
  75. /* regex macros for the lexer */
  76. hexdigit [0-9a-fA-F]
  77. reserved [()\&|!=<>~\n] /* newline in reserved set for convinience */
  78. not_reserved [^()\&|!=<>~\n]
  79. /* special lexer states */
  80. %x QUOTED_STRING
  81. /* table size directives */
  82. %option noyywrap
  83. %%
  84. "\"" { BEGIN QUOTED_STRING; yyless(0); }
  85. <QUOTED_STRING>[^()\&|!=<>~\n]+ {
  86. BEGIN INITIAL;
  87. if(NULL != (yylval.filter_string = xstrdup(yytext)))
  88. return(OPERAND) ;
  89. else
  90. return(0L) ;
  91. }
  92. [ \t\v\f]* { ; }
  93. "(" { yylval.filter_int = L_PAREN; return L_PAREN ; }
  94. ")" { yylval.filter_int = R_PAREN; return R_PAREN ; }
  95. "&" { yylval.filter_int = OP_AND; return OP_AND ; }
  96. "|" { yylval.filter_int = OP_OR; return OP_OR ; }
  97. "!" { yylval.filter_int = OP_NOT; return OP_NOT ; }
  98. "=" { yylval.filter_int = OP_EQU; return OP_EQU ; }
  99. ">=" { yylval.filter_int = OP_GT; return OP_GT ; }
  100. "<=" { yylval.filter_int = OP_LT; return OP_LT ; }
  101. "=*" { yylval.filter_int = OP_PRESENT; return OP_PRESENT ; }
  102. "~=" { yylval.filter_int = OP_APPROX; return OP_APPROX ; }
  103. [-+][0-9]+ |
  104. [-+]"0"[xX]{hexdigit}+ {
  105. yylval.filter_int = strtol(yytext, (char **) 0, 0) ;
  106. return VAL_INT;
  107. }
  108. [0-9]+ |
  109. "0"[xX]{hexdigit}+ {
  110. yylval.filter_int = strtoul(yytext, (char **) 0, 0);
  111. return VAL_INT;
  112. }
  113. [tT][rR][uU][eE] {
  114. yylval.filter_int = 1; return VAL_BOOL;
  115. }
  116. [fF][aA][lL][sS][eE] {
  117. yylval.filter_int = 0; return VAL_BOOL;
  118. }
  119. [^()\&|!=<>~ \t\v\f]+ {
  120. if(NULL != (yylval.filter_string = xstrdup(yytext)))
  121. return(OPERAND) ;
  122. else
  123. return(0L) ;
  124. }
  125. %%
  126. void filter_close_lexer(unsigned int handle)
  127. {
  128. yy_delete_buffer((YY_BUFFER_STATE)handle);
  129. }
  130. unsigned int slp_filter_init_lexer(const char *s)
  131. {
  132. memset(&buf[0], 0x00, 2052);
  133. strncpy(&buf[0], s, 2048);
  134. return((uint)yy_scan_buffer(&buf[0], strlen(s) + 2));
  135. }
  136. void slp_filter_error(char *s, ...)
  137. {
  138. return;
  139. }