| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #library("status_file_parser"); |
| 6 |
| 7 |
| 8 #import("status_expression.dart"); |
| 9 |
| 10 final RegExp StripComment = const RegExp("^[^#]*"); |
| 11 final RegExp HeaderPattern = const RegExp(@"\[([^\]]+)\]"); |
| 12 final RegExp RulePattern = const RegExp(@"\s*([^: ]*)\s*:(.*)"); |
| 13 final RegExp PrefixPattern = const RegExp(@"^\s*prefix\s+([\w\_\.\-\/]+)\s*$"); |
| 14 |
| 15 // TODO(whesse): Implement configuration_info library that contains data |
| 16 // structures for test configuration, including Section. |
| 17 class Section { |
| 18 BooleanExpression condition; |
| 19 |
| 20 Section.always() : condition = null; |
| 21 Section(this.condition); |
| 22 } |
| 23 |
| 24 |
| 25 // Helper method to be able to run the test from the runtime |
| 26 // directory, or the top directory. |
| 27 String getFilename(String path) => |
| 28 new File(path).existsSync() ? path : '../$path'; |
| 29 |
| 30 |
| 31 void ReadConfigurationInto(path, sections) { |
| 32 File file = new File(getFilename(path)); |
| 33 Expect.isTrue(file.existsSync()); // TODO(whesse): Handle missing file. |
| 34 FileInputStream file_stream = file.openInputStream(); |
| 35 StringInputStream lines = new StringInputStream(file_stream); |
| 36 |
| 37 Section current = new Section.always(); |
| 38 sections.add(current); |
| 39 String prefix = ""; |
| 40 |
| 41 String line; |
| 42 while ((line = lines.readLine()) != null) { |
| 43 Match match = StripComment.firstMatch(line); |
| 44 line = (match == null) ? "" : match[0]; |
| 45 line = line.trim(); |
| 46 if (line == "") continue; |
| 47 |
| 48 match = HeaderPattern.firstMatch(line); |
| 49 if (match != null) { |
| 50 String condition_string = match[1].trim(); |
| 51 List<String> tokens = new Tokenizer(condition_string).tokenize(); |
| 52 ExpressionParser parser = new ExpressionParser(new Scanner(tokens)); |
| 53 current = new Section(parser.parseBooleanExpression()); |
| 54 sections.add(current); |
| 55 continue; |
| 56 } |
| 57 |
| 58 match = RulePattern.firstMatch(line); |
| 59 if (match != null) { |
| 60 String path = prefix + match[1].trim(); |
| 61 String expression_string = match[2].trim(); |
| 62 List<String> tokens = new Tokenizer(expression_string).tokenize(); |
| 63 SetExpression expression = |
| 64 new ExpressionParser(new Scanner(tokens)).parseSetExpression(); |
| 65 // TODO(whesse): Save rule in configuration data structure. |
| 66 continue; |
| 67 } |
| 68 |
| 69 match = PrefixPattern.firstMatch(line); |
| 70 if (match != null) { |
| 71 prefix = match[1]; |
| 72 continue; |
| 73 } |
| 74 |
| 75 print("unmatched line: $line"); |
| 76 } |
| 77 |
| 78 file_stream.close(); |
| 79 } |
| 80 |
| OLD | NEW |