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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 Tokenizer(String this.expression) | 49 Tokenizer(String this.expression) |
50 : tokens = new List<String>(); | 50 : tokens = new List<String>(); |
51 | 51 |
52 // Tokens are : "(", ")", "$", ",", "&&", "||", "==", and (maximal) \w+. | 52 // Tokens are : "(", ")", "$", ",", "&&", "||", "==", and (maximal) \w+. |
53 static final testRegexp = | 53 static final testRegexp = |
54 new RegExp(r"^([()$\w\s,]|(\&\&)|(\|\|)|(\=\=))+$"); | 54 new RegExp(r"^([()$\w\s,]|(\&\&)|(\|\|)|(\=\=))+$"); |
55 static final regexp = new RegExp(r"[()$,]|(\&\&)|(\|\|)|(\=\=)|\w+"); | 55 static final regexp = new RegExp(r"[()$,]|(\&\&)|(\|\|)|(\=\=)|\w+"); |
56 | 56 |
57 List<String> tokenize() { | 57 List<String> tokenize() { |
58 if (!testRegexp.hasMatch(expression)) { | 58 if (!testRegexp.hasMatch(expression)) { |
59 throw new ExpectException("Syntax error in '$expression'"); | 59 throw new FormatException("Syntax error in '$expression'"); |
60 } | 60 } |
61 for (Match match in regexp.allMatches(expression)) tokens.add(match[0]); | 61 for (Match match in regexp.allMatches(expression)) tokens.add(match[0]); |
62 return tokens; | 62 return tokens; |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 | 66 |
67 abstract class BooleanExpression { | 67 abstract class BooleanExpression { |
68 bool evaluate(Map<String, String> environment); | 68 bool evaluate(Map<String, String> environment); |
69 } | 69 } |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 } | 298 } |
299 TermConstant right = new TermConstant(scanner.current); | 299 TermConstant right = new TermConstant(scanner.current); |
300 scanner.advance(); | 300 scanner.advance(); |
301 return new Comparison(left, right); | 301 return new Comparison(left, right); |
302 } else { | 302 } else { |
303 return new BooleanVariable(left); | 303 return new BooleanVariable(left); |
304 } | 304 } |
305 } | 305 } |
306 } | 306 } |
307 | 307 |
OLD | NEW |