| 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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 } | 229 } |
| 230 return left; | 230 return left; |
| 231 } | 231 } |
| 232 | 232 |
| 233 | 233 |
| 234 SetExpression parseSetAtomic() { | 234 SetExpression parseSetAtomic() { |
| 235 if (scanner.current == Token.LEFT_PAREN) { | 235 if (scanner.current == Token.LEFT_PAREN) { |
| 236 scanner.advance(); | 236 scanner.advance(); |
| 237 SetExpression value = parseSetExpression(); | 237 SetExpression value = parseSetExpression(); |
| 238 if (scanner.current != Token.RIGHT_PAREN) { | 238 if (scanner.current != Token.RIGHT_PAREN) { |
| 239 throw new RuntimeError("Missing right parenthesis in expression"); | 239 throw new FormatException("Missing right parenthesis in expression"); |
| 240 } | 240 } |
| 241 scanner.advance(); | 241 scanner.advance(); |
| 242 return value; | 242 return value; |
| 243 } | 243 } |
| 244 if (!new RegExp(r"^\w+$").hasMatch(scanner.current)) { | 244 if (!new RegExp(r"^\w+$").hasMatch(scanner.current)) { |
| 245 throw new RuntimeError( | 245 throw new FormatException( |
| 246 "Expected identifier in expression, got ${scanner.current}"); | 246 "Expected identifier in expression, got ${scanner.current}"); |
| 247 } | 247 } |
| 248 SetExpression value = new SetConstant(scanner.current); | 248 SetExpression value = new SetConstant(scanner.current); |
| 249 scanner.advance(); | 249 scanner.advance(); |
| 250 return value; | 250 return value; |
| 251 } | 251 } |
| 252 | 252 |
| 253 BooleanExpression parseBooleanExpression() => parseBooleanOr(); | 253 BooleanExpression parseBooleanExpression() => parseBooleanOr(); |
| 254 | 254 |
| 255 BooleanExpression parseBooleanOr() { | 255 BooleanExpression parseBooleanOr() { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 270 left = new BooleanOperation(Token.AND, left, right); | 270 left = new BooleanOperation(Token.AND, left, right); |
| 271 } | 271 } |
| 272 return left; | 272 return left; |
| 273 } | 273 } |
| 274 | 274 |
| 275 BooleanExpression parseBooleanAtomic() { | 275 BooleanExpression parseBooleanAtomic() { |
| 276 if (scanner.current == Token.LEFT_PAREN) { | 276 if (scanner.current == Token.LEFT_PAREN) { |
| 277 scanner.advance(); | 277 scanner.advance(); |
| 278 BooleanExpression value = parseBooleanExpression(); | 278 BooleanExpression value = parseBooleanExpression(); |
| 279 if (scanner.current != Token.RIGHT_PAREN) { | 279 if (scanner.current != Token.RIGHT_PAREN) { |
| 280 throw new RuntimeError("Missing right parenthesis in expression"); | 280 throw new FormatException("Missing right parenthesis in expression"); |
| 281 } | 281 } |
| 282 scanner.advance(); | 282 scanner.advance(); |
| 283 return value; | 283 return value; |
| 284 } | 284 } |
| 285 | 285 |
| 286 // The only atomic booleans are of the form $variable == value or the | 286 // The only atomic booleans are of the form $variable == value or the |
| 287 // form $variable. | 287 // form $variable. |
| 288 if (scanner.current != Token.DOLLAR_SYMBOL) { | 288 if (scanner.current != Token.DOLLAR_SYMBOL) { |
| 289 throw new RuntimeError( | 289 throw new FormatException( |
| 290 "Expected \$ in expression, got ${scanner.current}"); | 290 "Expected \$ in expression, got ${scanner.current}"); |
| 291 } | 291 } |
| 292 scanner.advance(); | 292 scanner.advance(); |
| 293 if (!new RegExp(r"^\w+$").hasMatch(scanner.current)) { | 293 if (!new RegExp(r"^\w+$").hasMatch(scanner.current)) { |
| 294 throw new RuntimeError( | 294 throw new FormatException( |
| 295 "Expected identifier in expression, got ${scanner.current}"); | 295 "Expected identifier in expression, got ${scanner.current}"); |
| 296 } | 296 } |
| 297 TermVariable left = new TermVariable(scanner.current); | 297 TermVariable left = new TermVariable(scanner.current); |
| 298 scanner.advance(); | 298 scanner.advance(); |
| 299 if (scanner.current == Token.EQUALS || | 299 if (scanner.current == Token.EQUALS || |
| 300 scanner.current == Token.NOT_EQUALS) { | 300 scanner.current == Token.NOT_EQUALS) { |
| 301 bool negate = scanner.current == Token.NOT_EQUALS; | 301 bool negate = scanner.current == Token.NOT_EQUALS; |
| 302 scanner.advance(); | 302 scanner.advance(); |
| 303 if (!new RegExp(r"^\w+$").hasMatch(scanner.current)) { | 303 if (!new RegExp(r"^\w+$").hasMatch(scanner.current)) { |
| 304 throw new RuntimeError( | 304 throw new FormatException( |
| 305 "Expected identifier in expression, got ${scanner.current}"); | 305 "Expected identifier in expression, got ${scanner.current}"); |
| 306 } | 306 } |
| 307 TermConstant right = new TermConstant(scanner.current); | 307 TermConstant right = new TermConstant(scanner.current); |
| 308 scanner.advance(); | 308 scanner.advance(); |
| 309 return new Comparison(left, right, negate); | 309 return new Comparison(left, right, negate); |
| 310 } else { | 310 } else { |
| 311 return new BooleanVariable(left); | 311 return new BooleanVariable(left); |
| 312 } | 312 } |
| 313 } | 313 } |
| 314 } | 314 } |
| 315 | 315 |
| OLD | NEW |