/[pdpsoft]/trunk/grid-mw-security/ees/src/eval_man/pdl_lex.l
ViewVC logotype

Contents of /trunk/grid-mw-security/ees/src/eval_man/pdl_lex.l

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1069 - (show annotations) (download)
Mon Nov 9 13:34:12 2009 UTC (12 years, 2 months ago) by aramv
File size: 4792 byte(s)
Added logic to clean up parser memory when using older versions of (f)lex
1 %{
2 #include "pdl.h"
3 #include "pdl_yacc.h"
4 #include "eef_log.h"
5 #include <string.h>
6 unsigned int lineno = 1;
7
8 /*static int no_valid_rule=0;*/
9 %}
10
11 ws [\t ]+
12 nl \n
13 term [a-zA-Z_.0-9]+
14 label {term}:
15 trans "->"
16 comment #.*\n
17 tokens [\~=\|]
18 pvar "path"
19 path \.*\/[^\/ \t\n]*
20 pdlstr \"[^\"\n]*[\"\n]
21
22
23 %x linecom path pathcom mq
24 %%
25
26 {ws} ;
27 {pvar} { return PVAR; }
28 {term} { if ((yylval.record = (record_t*)malloc(sizeof(record_t))))
29 if (((yylval.record)->string = (char*) strdup(yytext))) {
30 (yylval.record)->lineno = lineno;
31 return TERM;
32 }
33 eef_log(LOG_ERR, "out of memory.");
34 return 0;
35 }
36 {label} { yytext[yyleng-1] = '\0'; /* remove trailing ':' */
37
38 /* Check if this policy rule is allowed or not. */
39 if (allowed_policy_rule(yytext)) {
40 allow_rules(TRUE);
41 } else {
42 /* This label should not be added, however normal parsing
43 * must continue. */
44 allow_rules(FALSE);
45 }
46 if ((yylval.record = (record_t*)malloc(sizeof(record_t))))
47 if (((yylval.record)->string = (char *) strdup(yytext))) {
48 (yylval.record)->lineno = lineno;
49 return LABEL;
50 }
51 eef_log(LOG_ERR, "out of memory.");
52 return 0;
53 }
54 {path} { if ((yylval.record = (record_t *)malloc(sizeof(record_t))))
55 if (((yylval.record)->string = strdup(yytext))) {
56 (yylval.record)->lineno = lineno;
57 BEGIN path;
58 return PATH;
59 }
60 eef_log(LOG_ERR, "out of memory.");
61 return 0;
62 }
63 <path>{path} { if ((yylval.record = (record_t *)malloc(sizeof(record_t))))
64 if (((yylval.record)->string = strdup(yytext))) {
65 (yylval.record)->lineno = lineno;
66 return PATH;
67 }
68 eef_log(LOG_ERR, "out of memory.");
69 return 0;
70 }
71 <path># { BEGIN pathcom; }
72 <path>[ \t]* ;
73 <path>\n { BEGIN INITIAL; yyless(0); return '\n'; }
74 <path>. { eef_log(LOG_ERR, "unrecognized tokens in path name."); }
75 <pathcom>. ;
76 <pathcom>\n { BEGIN INITIAL; yyless(0); return '\n'; }
77 {nl} { ++lineno; }
78 {tokens} { return yytext[0]; }
79 {trans} { return TRANS; }
80 {comment} { ++lineno; BEGIN INITIAL ; }
81 {pdlstr} { if ((yylval.record = (record_t*)malloc(sizeof(record_t)))) {
82 if (yytext[yyleng-2] == '\\') {
83 if (((yylval.record)->string = strdup(yytext+1))) {
84 (yylval.record)->string[yyleng-2] = '\0';
85 (yylval.record)->string[yyleng-3] = '\"';
86 (yylval.record)->lineno = lineno;
87 yyless(yyleng-1); /* make the next string start with " */
88 BEGIN mq;
89 return STRING;
90 }
91 } else {
92 if (yytext[yyleng-1] == '\"') {
93 if (((yylval.record)->string = strdup(yytext+1))) {
94 (yylval.record)->string[yyleng-2] = '\0';
95 (yylval.record)->lineno = lineno;
96 return STRING;
97 }
98 }
99 }
100 eef_log(LOG_ERR, "out of memory.");
101 return 0;
102 } else
103 eef_log(LOG_ERR, "string contains a newline.");
104 }
105 <mq>{pdlstr} { if ((yylval.record = (record_t*)malloc(sizeof(record_t)))) {
106 if (yytext[yyleng-2] == '\\') {
107 if (((yylval.record)->string = strdup(yytext+1))) {
108 (yylval.record)->string[yyleng-2] = '\0';
109 (yylval.record)->string[yyleng-3] = '\"';
110 (yylval.record)->lineno = lineno;
111 yyless(yyleng-1); /* make the next string start with " */
112 BEGIN INITIAL;
113 return STRING;
114 }
115 } else {
116 eef_log(LOG_ERR, "Unballanced quotes.");
117 return 0;
118 }
119 }
120 eef_log(LOG_ERR, "out of memory.");
121 return 0;
122 }
123 . { eef_log(LOG_WARNING, "unrecoginzed token '%c'.", yytext[0]);
124 return yytext[0];
125 }
126 %%
127
128 #if HAVE_FLEX
129
130 void delete_lex_buffer(void)
131 {
132 yy_delete_buffer(YY_CURRENT_BUFFER);
133 yy_init = 1;
134 }
135
136 #endif

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28