PageRenderTime 54ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/2.0.beta2/openslp/common/slp_filter_l.l

#
LEX | 189 lines | 114 code | 31 blank | 44 comment | 0 complexity | dc1c47f9005f234c3632a30293621454 MD5 | raw file
Possible License(s): BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-2.1
  1. /*-------------------------------------------------------------------------
  2. * Copyright (C) 2000-2005 Mike Day <ncmike@ncultra.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. *
  12. * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * Neither the name of Caldera Systems nor the names of its
  17. * contributors may be used to endorse or promote products derived
  18. * from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * `AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE CALDERA
  24. * SYSTEMS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  28. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *-------------------------------------------------------------------------*/
  32. /** Flex input file for LDAPv3 search filter.
  33. *
  34. * @file slp_filter_l.l
  35. * @date 04-21-2001
  36. * @author Matthew Peterson, Michael Day (md@soft-hackle.net),
  37. * John Calcote (jcalcote@novell.com)
  38. * @attention Please submit patches to http://www.openslp.org
  39. * @ingroup CommonCodeFilter
  40. */
  41. %{
  42. #undef YYLMAX
  43. #define YYLMAX 2048
  44. #define yymaxdepth slp_filter_maxdepth
  45. #define yyparse slp_filter_parse
  46. #define yylex slp_filter_lex
  47. #define yyerror slp_filter_error
  48. #define yylval slp_filter_lval
  49. #define yychar slp_filter_char
  50. #define yydebug slp_filter_debug
  51. #define yypact slp_filter_pact
  52. #define yyr1 slp_filter_r1
  53. #define yyr2 slp_filter_r2
  54. #define yydef slp_filter_def
  55. #define yychk slp_filter_chk
  56. #define yypgo slp_filter_pgo
  57. #define yyact slp_filter_act
  58. #define yyexca slp_filter_exca
  59. #define yyerrflag slp_filter_errflag
  60. #define yynerrs slp_filter_nerrs
  61. #define yyps slp_filter_ps
  62. #define yypv slp_filter_pv
  63. #define yys slp_filter_s
  64. #define yy_yys slp_filter_yys
  65. #define yystate slp_filter_state
  66. #define yytmp slp_filter_tmp
  67. #define yyv slp_filter_v
  68. #define yy_yyv slp_filter_yyv
  69. #define yyval slp_filter_val
  70. #define yylloc slp_filter_lloc
  71. #define yyreds slp_filter_reds
  72. #define yytoks slp_filter_toks
  73. #define yylhs slp_filter_yylhs
  74. #define yylen slp_filter_yylen
  75. #define yydefred slp_filter_yydefred
  76. #define yydgoto slp_filter_yydgoto
  77. #define yysindex slp_filter_yysindex
  78. #define yyrindex slp_filter_yyrindex
  79. #define yygindex slp_filter_yygindex
  80. #define yytable slp_filter_yytable
  81. #define yycheck slp_filter_yycheck
  82. #define yyname slp_filter_yyname
  83. #define yyrule slp_filter_yyrule
  84. #define YY_NO_UNPUT
  85. #include "slp_filter.h"
  86. #include "slp_filter_y.h"
  87. #include "slp_xmalloc.h"
  88. static char buf[2052];
  89. void slp_filter_error(char *, ...);
  90. void slp_filter_close_lexer(unsigned int handle);
  91. unsigned int slp_filter_init_lexer(const char *s);
  92. %}
  93. /* regex macros for the lexer */
  94. hexdigit [0-9a-fA-F]
  95. reserved [()\&|!=<>~\n] /* newline in reserved set for convinience */
  96. not_reserved [^()\&|!=<>~\n]
  97. /* special lexer states */
  98. %x QUOTED_STRING
  99. /* table size directives */
  100. %option noyywrap
  101. %%
  102. "\"" { BEGIN QUOTED_STRING; yyless(0); }
  103. <QUOTED_STRING>[^()\&|!=<>~\n]+ {
  104. BEGIN INITIAL;
  105. if(0 != (yylval.filter_string = xstrdup(yytext)))
  106. return(OPERAND) ;
  107. else
  108. return(0L) ;
  109. }
  110. [ \t\v\f]* { ; }
  111. "(" { yylval.filter_int = L_PAREN; return L_PAREN ; }
  112. ")" { yylval.filter_int = R_PAREN; return R_PAREN ; }
  113. "&" { yylval.filter_int = OP_AND; return OP_AND ; }
  114. "|" { yylval.filter_int = OP_OR; return OP_OR ; }
  115. "!" { yylval.filter_int = OP_NOT; return OP_NOT ; }
  116. "=" { yylval.filter_int = OP_EQU; return OP_EQU ; }
  117. ">=" { yylval.filter_int = OP_GT; return OP_GT ; }
  118. "<=" { yylval.filter_int = OP_LT; return OP_LT ; }
  119. "=*" { yylval.filter_int = OP_PRESENT; return OP_PRESENT ; }
  120. "~=" { yylval.filter_int = OP_APPROX; return OP_APPROX ; }
  121. [-+][0-9]+ |
  122. [-+]"0"[xX]{hexdigit}+ {
  123. yylval.filter_int = strtol(yytext, (char **) 0, 0) ;
  124. return VAL_INT;
  125. }
  126. [0-9]+ |
  127. "0"[xX]{hexdigit}+ {
  128. yylval.filter_int = strtoul(yytext, (char **) 0, 0);
  129. return VAL_INT;
  130. }
  131. [tT][rR][uU][eE] {
  132. yylval.filter_int = 1; return VAL_BOOL;
  133. }
  134. [fF][aA][lL][sS][eE] {
  135. yylval.filter_int = 0; return VAL_BOOL;
  136. }
  137. [^()\&|!=<>~ \t\v\f]+ {
  138. if(0 != (yylval.filter_string = xstrdup(yytext)))
  139. return(OPERAND) ;
  140. else
  141. return(0L) ;
  142. }
  143. %%
  144. void filter_close_lexer(unsigned int handle)
  145. {
  146. yy_delete_buffer((YY_BUFFER_STATE)handle);
  147. }
  148. unsigned int slp_filter_init_lexer(const char * s)
  149. {
  150. memset(&buf[0], 0x00, 2052);
  151. strncpy(&buf[0], s, 2048);
  152. return((uint)yy_scan_buffer(&buf[0], strlen(s) + 2));
  153. }
  154. void slp_filter_error(char *s, ...)
  155. {
  156. return;
  157. }
  158. /*=========================================================================*/