| 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 // TODO(jimhug): Error recovery needs major work! | 5 // TODO(jimhug): Error recovery needs major work! |
| 6 /** | 6 /** |
| 7 * A simple recursive descent parser for the dart language. | 7 * A simple recursive descent parser for the dart language. |
| 8 * | 8 * |
| 9 * This parser is designed to be more permissive than the official | 9 * This parser is designed to be more permissive than the official |
| 10 * Dart grammar. It is expected that many grammar errors would be | 10 * Dart grammar. It is expected that many grammar errors would be |
| (...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 var isTrue = !_maybeEat(TokenKind.NOT); | 841 var isTrue = !_maybeEat(TokenKind.NOT); |
| 842 var typeRef = type(); | 842 var typeRef = type(); |
| 843 x = new IsExpression(isTrue, x, typeRef, _makeSpan(x.span.start)); | 843 x = new IsExpression(isTrue, x, typeRef, _makeSpan(x.span.start)); |
| 844 continue; | 844 continue; |
| 845 } | 845 } |
| 846 // Using prec + 1 ensures that a - b - c will group correctly. | 846 // Using prec + 1 ensures that a - b - c will group correctly. |
| 847 // Using prec for ASSIGN ops ensures that a = b = c groups correctly. | 847 // Using prec for ASSIGN ops ensures that a = b = c groups correctly. |
| 848 var y = infixExpression(prec == 2 ? prec: prec+1); | 848 var y = infixExpression(prec == 2 ? prec: prec+1); |
| 849 if (op.kind == TokenKind.CONDITIONAL) { | 849 if (op.kind == TokenKind.CONDITIONAL) { |
| 850 _eat(TokenKind.COLON); | 850 _eat(TokenKind.COLON); |
| 851 var z = infixExpression(prec+1); | 851 // Using prec for so "a ? b : c ? d : e" groups correctly as |
| 852 // "a ? b : (c ? d : e)" |
| 853 var z = infixExpression(prec); |
| 852 x = new ConditionalExpression(x, y, z, _makeSpan(x.span.start)); | 854 x = new ConditionalExpression(x, y, z, _makeSpan(x.span.start)); |
| 853 } else { | 855 } else { |
| 854 x = new BinaryExpression(op, x, y, _makeSpan(x.span.start)); | 856 x = new BinaryExpression(op, x, y, _makeSpan(x.span.start)); |
| 855 } | 857 } |
| 856 } else { | 858 } else { |
| 857 break; | 859 break; |
| 858 } | 860 } |
| 859 } | 861 } |
| 860 return x; | 862 return x; |
| 861 } | 863 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 } | 956 } |
| 955 } | 957 } |
| 956 } | 958 } |
| 957 | 959 |
| 958 /** Checks if the given expression is a binary op of the given kind. */ | 960 /** Checks if the given expression is a binary op of the given kind. */ |
| 959 _isBin(expr, kind) { | 961 _isBin(expr, kind) { |
| 960 return expr is BinaryExpression && expr.op.kind == kind; | 962 return expr is BinaryExpression && expr.op.kind == kind; |
| 961 } | 963 } |
| 962 | 964 |
| 963 _boolTypeRef(SourceSpan span) { | 965 _boolTypeRef(SourceSpan span) { |
| 964 return new TypeReference(span, world.boolType); | 966 return new TypeReference(span, world.nonNullBool); |
| 965 } | 967 } |
| 966 | 968 |
| 967 _intTypeRef(SourceSpan span) { | 969 _intTypeRef(SourceSpan span) { |
| 968 return new TypeReference(span, world.intType); | 970 return new TypeReference(span, world.intType); |
| 969 } | 971 } |
| 970 | 972 |
| 971 _doubleTypeRef(SourceSpan span) { | 973 _doubleTypeRef(SourceSpan span) { |
| 972 return new TypeReference(span, world.doubleType); | 974 return new TypeReference(span, world.doubleType); |
| 973 } | 975 } |
| 974 | 976 |
| (...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1675 class IncompleteSourceException implements Exception { | 1677 class IncompleteSourceException implements Exception { |
| 1676 final Token token; | 1678 final Token token; |
| 1677 | 1679 |
| 1678 IncompleteSourceException(this.token); | 1680 IncompleteSourceException(this.token); |
| 1679 | 1681 |
| 1680 String toString() { | 1682 String toString() { |
| 1681 if (token.span == null) return 'Unexpected $token'; | 1683 if (token.span == null) return 'Unexpected $token'; |
| 1682 return token.span.toMessageString('Unexpected $token'); | 1684 return token.span.toMessageString('Unexpected $token'); |
| 1683 } | 1685 } |
| 1684 } | 1686 } |
| OLD | NEW |