| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 dart_style.src.dart_formatter; | 5 library dart_style.src.dart_formatter; |
| 6 | 6 |
| 7 import 'dart:math' as math; | 7 import 'dart:math' as math; |
| 8 | 8 |
| 9 import 'package:analyzer/analyzer.dart'; | 9 import 'package:analyzer/analyzer.dart'; |
| 10 import 'package:analyzer/src/generated/parser.dart'; | 10 import 'package:analyzer/src/generated/parser.dart'; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 } else { | 94 } else { |
| 95 lineEnding = "\n"; | 95 lineEnding = "\n"; |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 | 98 |
| 99 errorListener.throwIfErrors(); | 99 errorListener.throwIfErrors(); |
| 100 | 100 |
| 101 // Parse it. | 101 // Parse it. |
| 102 var parser = new Parser(stringSource, errorListener); | 102 var parser = new Parser(stringSource, errorListener); |
| 103 | 103 |
| 104 parser.parseConditionalDirectives = true; |
| 105 |
| 104 var node; | 106 var node; |
| 105 if (source.isCompilationUnit) { | 107 if (source.isCompilationUnit) { |
| 106 node = parser.parseCompilationUnit(startToken); | 108 node = parser.parseCompilationUnit(startToken); |
| 107 } else { | 109 } else { |
| 108 node = parser.parseStatement(startToken); | 110 node = parser.parseStatement(startToken); |
| 109 | 111 |
| 110 // Make sure we consumed all of the source. | 112 // Make sure we consumed all of the source. |
| 111 var token = node.endToken.next; | 113 var token = node.endToken.next; |
| 112 if (token.type != TokenType.EOF) { | 114 if (token.type != TokenType.EOF) { |
| 113 var error = new AnalysisError( | 115 var error = new AnalysisError( |
| 114 stringSource, | 116 stringSource, |
| 115 token.offset, | 117 token.offset, |
| 116 math.max(token.length, 1), | 118 math.max(token.length, 1), |
| 117 ParserErrorCode.UNEXPECTED_TOKEN, | 119 ParserErrorCode.UNEXPECTED_TOKEN, |
| 118 [token.lexeme]); | 120 [token.lexeme]); |
| 119 | 121 |
| 120 throw new FormatterException([error]); | 122 throw new FormatterException([error]); |
| 121 } | 123 } |
| 122 } | 124 } |
| 123 | 125 |
| 124 errorListener.throwIfErrors(); | 126 errorListener.throwIfErrors(); |
| 125 | 127 |
| 126 // Format it. | 128 // Format it. |
| 127 var visitor = new SourceVisitor(this, lineInfo, source); | 129 var visitor = new SourceVisitor(this, lineInfo, source); |
| 128 return visitor.run(node); | 130 return visitor.run(node); |
| 129 } | 131 } |
| 130 } | 132 } |
| OLD | NEW |