#
source:
trunk/third/bonobo-activation/server/activation-context-query-parser.y
@
18311

Revision 18311, 4.9 KB checked in by ghudson, 22 years ago (diff) |
---|

Line | |
---|---|

1 | /* |

2 | * oafd: OAF CORBA dameon. |

3 | * |

4 | * Copyright (C) 1999, 2000 Red Hat, Inc. |

5 | * Copyright (C) 1999, 2000 Eazel, Inc. |

6 | * |

7 | * This library is free software; you can redistribute it and/or |

8 | * modify it under the terms of the GNU General Public License as |

9 | * published by the Free Software Foundation; either version 2 of the |

10 | * License, or (at your option) any later version. |

11 | * |

12 | * This library is distributed in the hope that it will be useful, |

13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |

14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |

15 | * General Public License for more details. |

16 | * |

17 | * You should have received a copy of the GNU General Public License |

18 | * along with this library; if not, write to the Free Software |

19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |

20 | * |

21 | * Authors: Elliot Lee <sopwith@redhat.com>, |

22 | * |

23 | */ |

24 | |

25 | %{ |

26 | #include "activation-context-query.h" |

27 | |

28 | #include <glib.h> |

29 | #include <stdlib.h> |

30 | |

31 | void yyerror(char *s); |

32 | int yylex (); |

33 | int yyparse (void); |

34 | void initFlex (const char *s); |

35 | |

36 | static QueryExpr *parsed_expression; |

37 | %} |

38 | |

39 | %union |

40 | { |

41 | char *val_string; |

42 | char **val_stringv; |

43 | gdouble val_number; |

44 | gboolean val_boolean; |

45 | QueryExpr *qexp; |

46 | GSList *elist; |

47 | int val_enum; |

48 | } |

49 | |

50 | %token P_CONST_STRING P_CONST_NUMBER P_CONST_BOOLEAN P_CONST_ID |

51 | %token LPAREN RPAREN |

52 | %token LBRACKET RBRACKET |

53 | %right P_NOT P_NEGATE |

54 | %token P_DOLLAR |

55 | %left P_MULTIPLY P_DIVIDE |

56 | %left P_ADD P_SUBTRACT |

57 | %token P_EQ P_NEQ P_LEQ P_GEQ P_LT P_GT |

58 | %left P_OR P_AND P_XOR |

59 | %token COMMA PERIOD |

60 | %token PARSE_ERROR |

61 | |

62 | %type <val_string> P_CONST_STRING |

63 | %type <val_number> P_CONST_NUMBER |

64 | %type <val_boolean> P_CONST_BOOLEAN |

65 | %type <val_string> P_CONST_ID |

66 | %type <qexp> expr |

67 | %type <qexp> expr_binop |

68 | %type <qexp> expr_unop |

69 | %type <qexp> expr_constant |

70 | %type <qexp> expr_variable |

71 | %type <qexp> expr_function |

72 | %type <qexp> expr_id |

73 | %type <elist> exprlist |

74 | %type <qexp> expr_sub |

75 | %type <val_stringv> expr_stringv |

76 | %type <elist> stringlist |

77 | %type <qexp> expr_obvious |

78 | %type <val_enum> binop |

79 | |

80 | %% |

81 | |

82 | whole_expression: expr { parsed_expression = $1; }; |

83 | |

84 | expr: expr_binop |

85 | | expr_obvious; |

86 | |

87 | exprlist: expr { $$ = g_slist_prepend(NULL, $1); } |

88 | | expr COMMA exprlist { $$ = g_slist_prepend($3, $1); }; |

89 | |

90 | expr_obvious: expr_unop | expr_sub | expr_constant | expr_variable | expr_function | expr_id; |

91 | |

92 | expr_sub: LPAREN expr RPAREN { $$ = $2; }; |

93 | |

94 | binop: P_MULTIPLY { $$ = P_MULTIPLY; } |

95 | | P_DIVIDE { $$ = P_DIVIDE; } |

96 | | P_SUBTRACT { $$ = P_SUBTRACT; } |

97 | | P_ADD { $$ = P_ADD; } |

98 | | P_EQ { $$ = P_EQ; } |

99 | | P_NEQ { $$ = P_NEQ; } |

100 | | P_LEQ { $$ = P_LEQ; } |

101 | | P_GEQ { $$ = P_GEQ; } |

102 | | P_GT { $$ = P_GT; } |

103 | | P_LT { $$ = P_LT; } |

104 | | P_OR { $$ = P_OR; } |

105 | | P_AND { $$ = P_AND; } |

106 | | P_XOR { $$ = P_XOR; }; |

107 | |

108 | expr_binop: expr_obvious binop expr { $$ = qexp_binop_new ($1, $2, $3); }; |

109 | |

110 | expr_unop: P_NOT expr_obvious { $$ = qexp_unop_new (P_NOT, $2); } |

111 | | P_SUBTRACT expr_obvious %prec P_NEGATE { $$ = qexp_unop_new (P_NEGATE, $2); }; |

112 | |

113 | expr_constant: P_CONST_STRING { |

114 | QueryExprConst qctmp; |

115 | qctmp.type = CONST_STRING; |

116 | qctmp.u.v_string = $1; |

117 | $$ = qexp_constant_new (qctmp); |

118 | } |

119 | | P_CONST_NUMBER { |

120 | QueryExprConst qctmp; |

121 | qctmp.type = CONST_NUMBER; |

122 | qctmp.u.v_number = $1; |

123 | $$ = qexp_constant_new (qctmp); |

124 | } |

125 | | P_CONST_BOOLEAN { |

126 | QueryExprConst qctmp; |

127 | qctmp.type = CONST_BOOLEAN; |

128 | qctmp.u.v_boolean = $1; |

129 | $$ = qexp_constant_new (qctmp); |

130 | } |

131 | | expr_stringv { |

132 | QueryExprConst qctmp; |

133 | qctmp.type = CONST_STRINGV; |

134 | qctmp.u.v_stringv = $1; |

135 | $$ = qexp_constant_new (qctmp); |

136 | }; |

137 | |

138 | expr_stringv: LBRACKET stringlist RBRACKET { |

139 | char **new_stringv; |

140 | int i, n; |

141 | GSList *cur; |

142 | |

143 | n = g_slist_length($2); |

144 | new_stringv = g_new (char *, n + 1); |

145 | for (cur = $2, i = 0; i < n; i++, cur = cur->next) { |

146 | new_stringv[i] = cur->data; |

147 | } |

148 | new_stringv[i] = NULL; |

149 | |

150 | g_slist_free ($2); |

151 | |

152 | $$ = new_stringv; |

153 | }; |

154 | |

155 | stringlist: P_CONST_STRING { $$ = g_slist_prepend (NULL, $1); } |

156 | | stringlist COMMA P_CONST_STRING { $$ = g_slist_append ($1, $3); }; |

157 | |

158 | expr_variable: P_DOLLAR P_CONST_ID { $$ = qexp_variable_new ($2); }; |

159 | |

160 | expr_function: P_CONST_ID LPAREN exprlist RPAREN { $$ = qexp_function_new ($1, $3); } |

161 | | P_CONST_ID LPAREN RPAREN { $$ = qexp_function_new ($1, NULL); } |

162 | | P_CONST_ID PERIOD P_CONST_ID LPAREN exprlist RPAREN { |

163 | $$ = qexp_function_new($3, g_slist_prepend ($5, qexp_id_new ($1))); } |

164 | | P_CONST_ID PERIOD P_CONST_ID LPAREN RPAREN { |

165 | $$ = qexp_function_new($3, g_slist_prepend (NULL, qexp_id_new ($1))); }; |

166 | |

167 | expr_id: P_CONST_ID { $$ = qexp_id_new ($1); }; |

168 | |

169 | %% |

170 | |

171 | static GString *parse_errors = NULL; |

172 | |

173 | void yyerror (char *s) |

174 | { |

175 | g_string_append (parse_errors, s); |

176 | g_string_append_c (parse_errors, '\n'); |

177 | } |

178 | |

179 | const char *qexp_parse (const char *_code, |

180 | QueryExpr **retme) |

181 | { |

182 | parsed_expression = NULL; |

183 | |

184 | g_assert (retme); |

185 | |

186 | if (!parse_errors) |

187 | parse_errors = g_string_new (NULL); |

188 | else |

189 | g_string_truncate (parse_errors, 0); |

190 | |

191 | initFlex (_code); |

192 | yyparse(); |

193 | |

194 | *retme = parsed_expression; |

195 | |

196 | if (parse_errors->len) |

197 | return parse_errors->str; |

198 | else |

199 | return NULL; |

200 | } |

**Note:**See TracBrowser for help on using the repository browser.