OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library status_expression; | 5 library status_expression; |
6 | 6 |
7 /** | 7 /** |
8 * Parse and evaluate expressions in a .status file for Dart and V8. | 8 * Parse and evaluate expressions in a .status file for Dart and V8. |
9 * There are set expressions and Boolean expressions in a .status file. | 9 * There are set expressions and Boolean expressions in a .status file. |
10 * The grammar is: | 10 * The grammar is: |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 left = new SetUnion(left, right); | 222 left = new SetUnion(left, right); |
223 } | 223 } |
224 return left; | 224 return left; |
225 } | 225 } |
226 | 226 |
227 | 227 |
228 SetExpression parseSetAtomic() { | 228 SetExpression parseSetAtomic() { |
229 if (scanner.current == Token.LEFT_PAREN) { | 229 if (scanner.current == Token.LEFT_PAREN) { |
230 scanner.advance(); | 230 scanner.advance(); |
231 SetExpression value = parseSetExpression(); | 231 SetExpression value = parseSetExpression(); |
232 if (scanner.current != Token.RIGHT_PAREN) { | 232 Expect.equals(scanner.current, Token.RIGHT_PAREN, |
233 throw new RuntimeError("Missing right parenthesis in expression"); | 233 "Missing right parenthesis in expression"); |
234 } | |
235 scanner.advance(); | 234 scanner.advance(); |
236 return value; | 235 return value; |
237 } | 236 } |
238 if (!new RegExp(r"^\w+$").hasMatch(scanner.current)) { | 237 Expect.isTrue(new RegExp(r"^\w+$").hasMatch(scanner.current), |
239 throw new RuntimeError( | 238 "Expected identifier in expression, got ${scanner.current}"); |
240 "Expected identifier in expression, got ${scanner.current}"); | |
241 } | |
242 SetExpression value = new SetConstant(scanner.current); | 239 SetExpression value = new SetConstant(scanner.current); |
243 scanner.advance(); | 240 scanner.advance(); |
244 return value; | 241 return value; |
245 } | 242 } |
246 | 243 |
247 BooleanExpression parseBooleanExpression() => parseBooleanOr(); | 244 BooleanExpression parseBooleanExpression() => parseBooleanOr(); |
248 | 245 |
249 BooleanExpression parseBooleanOr() { | 246 BooleanExpression parseBooleanOr() { |
250 BooleanExpression left = parseBooleanAnd(); | 247 BooleanExpression left = parseBooleanAnd(); |
251 while (scanner.hasMore() && scanner.current == Token.OR) { | 248 while (scanner.hasMore() && scanner.current == Token.OR) { |
(...skipping 11 matching lines...) Expand all Loading... |
263 BooleanExpression right = parseBooleanAtomic(); | 260 BooleanExpression right = parseBooleanAtomic(); |
264 left = new BooleanOperation(Token.AND, left, right); | 261 left = new BooleanOperation(Token.AND, left, right); |
265 } | 262 } |
266 return left; | 263 return left; |
267 } | 264 } |
268 | 265 |
269 BooleanExpression parseBooleanAtomic() { | 266 BooleanExpression parseBooleanAtomic() { |
270 if (scanner.current == Token.LEFT_PAREN) { | 267 if (scanner.current == Token.LEFT_PAREN) { |
271 scanner.advance(); | 268 scanner.advance(); |
272 BooleanExpression value = parseBooleanExpression(); | 269 BooleanExpression value = parseBooleanExpression(); |
273 if (scanner.current != Token.RIGHT_PAREN) { | 270 Expect.equals(scanner.current, Token.RIGHT_PAREN, |
274 throw new RuntimeError("Missing right parenthesis in expression"); | 271 "Missing right parenthesis in expression"); |
275 } | |
276 scanner.advance(); | 272 scanner.advance(); |
277 return value; | 273 return value; |
278 } | 274 } |
279 | 275 |
280 // The only atomic booleans are of the form $variable == value or the | 276 // The only atomic booleans are of the form $variable == value or the |
281 // form $variable. | 277 // form $variable. |
282 if (scanner.current != Token.DOLLAR_SYMBOL) { | 278 Expect.equals(scanner.current, Token.DOLLAR_SYMBOL, |
283 throw new RuntimeError( | 279 "Expected \$ in expression, got ${scanner.current}"); |
284 "Expected \$ in expression, got ${scanner.current}"); | |
285 } | |
286 scanner.advance(); | 280 scanner.advance(); |
287 if (!new RegExp(r"^\w+$").hasMatch(scanner.current)) { | 281 Expect.isTrue(new RegExp(r"^\w+$").hasMatch(scanner.current), |
288 throw new RuntimeError( | 282 "Expected identifier in expression, got ${scanner.current}"); |
289 "Expected identifier in expression, got ${scanner.current}"); | |
290 } | |
291 TermVariable left = new TermVariable(scanner.current); | 283 TermVariable left = new TermVariable(scanner.current); |
292 scanner.advance(); | 284 scanner.advance(); |
293 if (scanner.current == Token.EQUALS) { | 285 if (scanner.current == Token.EQUALS) { |
294 scanner.advance(); | 286 scanner.advance(); |
295 if (!new RegExp(r"^\w+$").hasMatch(scanner.current)) { | 287 Expect.isTrue(new RegExp(r"^\w+$").hasMatch(scanner.current), |
296 throw new RuntimeError( | 288 "Expected identifier in expression, got ${scanner.current}"); |
297 "Expected identifier in expression, got ${scanner.current}"); | |
298 } | |
299 TermConstant right = new TermConstant(scanner.current); | 289 TermConstant right = new TermConstant(scanner.current); |
300 scanner.advance(); | 290 scanner.advance(); |
301 return new Comparison(left, right); | 291 return new Comparison(left, right); |
302 } else { | 292 } else { |
303 return new BooleanVariable(left); | 293 return new BooleanVariable(left); |
304 } | 294 } |
305 } | 295 } |
306 } | 296 } |
307 | 297 |
OLD | NEW |