OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 package com.google.dart.compiler.parser; | 5 package com.google.dart.compiler.parser; |
6 | 6 |
7 import com.google.common.annotations.VisibleForTesting; | 7 import com.google.common.annotations.VisibleForTesting; |
8 import com.google.common.io.CharStreams; | 8 import com.google.common.io.CharStreams; |
9 import com.google.dart.compiler.DartCompilationError; | 9 import com.google.dart.compiler.DartCompilationError; |
10 import com.google.dart.compiler.DartCompilerListener; | 10 import com.google.dart.compiler.DartCompilerListener; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 /** | 119 /** |
120 * Determines the maximum number of errors before terminating the parser. See | 120 * Determines the maximum number of errors before terminating the parser. See |
121 * {@link #reportError(com.google.dart.compiler.parser.DartScanner.Position, E
rrorCode, | 121 * {@link #reportError(com.google.dart.compiler.parser.DartScanner.Position, E
rrorCode, |
122 * Object...)}. | 122 * Object...)}. |
123 */ | 123 */ |
124 final int MAX_DEFAULT_ERRORS = 100; | 124 final int MAX_DEFAULT_ERRORS = 100; |
125 | 125 |
126 // Pseudo-keywords that should also be valid identifiers. | 126 // Pseudo-keywords that should also be valid identifiers. |
127 private static final String ABSTRACT_KEYWORD = "abstract"; | 127 private static final String ABSTRACT_KEYWORD = "abstract"; |
128 private static final String ASSERT_KEYWORD = "assert"; | 128 private static final String ASSERT_KEYWORD = "assert"; |
| 129 private static final String CALL_KEYWORD = "call"; |
129 private static final String EXTENDS_KEYWORD = "extends"; | 130 private static final String EXTENDS_KEYWORD = "extends"; |
130 private static final String FACTORY_KEYWORD = "factory"; // TODO(zundel): remo
ve | 131 private static final String FACTORY_KEYWORD = "factory"; // TODO(zundel): remo
ve |
131 private static final String GETTER_KEYWORD = "get"; | 132 private static final String GETTER_KEYWORD = "get"; |
132 private static final String IMPLEMENTS_KEYWORD = "implements"; | 133 private static final String IMPLEMENTS_KEYWORD = "implements"; |
133 private static final String INTERFACE_KEYWORD = "interface"; | 134 private static final String INTERFACE_KEYWORD = "interface"; |
134 private static final String NATIVE_KEYWORD = "native"; | 135 private static final String NATIVE_KEYWORD = "native"; |
135 private static final String NEGATE_KEYWORD = "negate"; | 136 private static final String NEGATE_KEYWORD = "negate"; |
136 private static final String OPERATOR_KEYWORD = "operator"; | 137 private static final String OPERATOR_KEYWORD = "operator"; |
137 private static final String PREFIX_KEYWORD = "prefix"; | 138 private static final String PREFIX_KEYWORD = "prefix"; |
138 private static final String SETTER_KEYWORD = "set"; | 139 private static final String SETTER_KEYWORD = "set"; |
139 private static final String STATIC_KEYWORD = "static"; | 140 private static final String STATIC_KEYWORD = "static"; |
140 private static final String TYPEDEF_KEYWORD = "typedef"; | 141 private static final String TYPEDEF_KEYWORD = "typedef"; |
141 | 142 |
| 143 |
142 public static final String[] PSEUDO_KEYWORDS = { | 144 public static final String[] PSEUDO_KEYWORDS = { |
143 ABSTRACT_KEYWORD, | 145 ABSTRACT_KEYWORD, |
144 ASSERT_KEYWORD, | 146 ASSERT_KEYWORD, |
| 147 CALL_KEYWORD, |
145 EXTENDS_KEYWORD, | 148 EXTENDS_KEYWORD, |
146 FACTORY_KEYWORD, | 149 FACTORY_KEYWORD, |
147 GETTER_KEYWORD, | 150 GETTER_KEYWORD, |
148 IMPLEMENTS_KEYWORD, | 151 IMPLEMENTS_KEYWORD, |
149 INTERFACE_KEYWORD, | 152 INTERFACE_KEYWORD, |
150 NEGATE_KEYWORD, | 153 NEGATE_KEYWORD, |
151 NATIVE_KEYWORD, | 154 NATIVE_KEYWORD, |
152 OPERATOR_KEYWORD, | 155 OPERATOR_KEYWORD, |
153 PREFIX_KEYWORD, | 156 PREFIX_KEYWORD, |
154 SETTER_KEYWORD, | 157 SETTER_KEYWORD, |
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 * : GET | 838 * : GET |
836 * | SET | 839 * | SET |
837 * ; | 840 * ; |
838 * | 841 * |
839 * operator | 842 * operator |
840 * : unaryOperator | 843 * : unaryOperator |
841 * | binaryOperator | 844 * | binaryOperator |
842 * | '[' ']' { "[]".equals($text) }? | 845 * | '[' ']' { "[]".equals($text) }? |
843 * | '[' ']' '=' { "[]=".equals($text) }? | 846 * | '[' ']' '=' { "[]=".equals($text) }? |
844 * | NEGATE | 847 * | NEGATE |
| 848 * | CALL |
845 * ; | 849 * ; |
846 * </pre> | 850 * </pre> |
847 * | 851 * |
848 * @param allowStatic true if the static modifier is allowed | 852 * @param allowStatic true if the static modifier is allowed |
849 * @return a {@link DartNode} representing the grammar fragment above | 853 * @return a {@link DartNode} representing the grammar fragment above |
850 */ | 854 */ |
851 private DartNode parseFieldOrMethod(boolean allowStatic) { | 855 private DartNode parseFieldOrMethod(boolean allowStatic) { |
852 beginClassMember(); | 856 beginClassMember(); |
853 Modifiers modifiers = Modifiers.NONE; | 857 Modifiers modifiers = Modifiers.NONE; |
854 if (optionalPseudoKeyword(STATIC_KEYWORD)) { | 858 if (optionalPseudoKeyword(STATIC_KEYWORD)) { |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 } else if (operation == Token.INDEX) { | 1093 } else if (operation == Token.INDEX) { |
1090 arity = 1; | 1094 arity = 1; |
1091 } else { | 1095 } else { |
1092 assert operation.isUnaryOperator(); | 1096 assert operation.isUnaryOperator(); |
1093 arity = 0; | 1097 arity = 0; |
1094 } | 1098 } |
1095 } else if (operation == Token.IDENTIFIER | 1099 } else if (operation == Token.IDENTIFIER |
1096 && ctx.getTokenString().equals(NEGATE_KEYWORD)) { | 1100 && ctx.getTokenString().equals(NEGATE_KEYWORD)) { |
1097 name = done(new DartIdentifier(NEGATE_KEYWORD)); | 1101 name = done(new DartIdentifier(NEGATE_KEYWORD)); |
1098 arity = 0; | 1102 arity = 0; |
| 1103 } else if (operation == Token.IDENTIFIER |
| 1104 && ctx.getTokenString().equals(CALL_KEYWORD)) { |
| 1105 name = done(new DartIdentifier(CALL_KEYWORD)); |
1099 } else { | 1106 } else { |
1100 reportUnexpectedToken(position(), Token.COMMENT, operation); | 1107 reportUnexpectedToken(position(), Token.COMMENT, operation); |
1101 done(null); | 1108 done(null); |
1102 } | 1109 } |
1103 } else { | 1110 } else { |
1104 beginMethodName(); | 1111 beginMethodName(); |
1105 // Check for getters and setters. | 1112 // Check for getters and setters. |
1106 if (optionalPseudoKeyword(GETTER_KEYWORD)) { | 1113 if (optionalPseudoKeyword(GETTER_KEYWORD)) { |
1107 name = parseIdentifier(); | 1114 name = parseIdentifier(); |
1108 modifiers = modifiers.makeGetter(); | 1115 modifiers = modifiers.makeGetter(); |
(...skipping 2713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3822 } | 3829 } |
3823 | 3830 |
3824 private void reportError(DartNode node, ErrorCode errorCode, Object... argumen
ts) { | 3831 private void reportError(DartNode node, ErrorCode errorCode, Object... argumen
ts) { |
3825 reportError(new DartCompilationError(node, errorCode, arguments)); | 3832 reportError(new DartCompilationError(node, errorCode, arguments)); |
3826 } | 3833 } |
3827 | 3834 |
3828 private boolean currentlyParsingToplevel() { | 3835 private boolean currentlyParsingToplevel() { |
3829 return !(isParsingInterface || isTopLevelAbstract || isParsingClass); | 3836 return !(isParsingInterface || isTopLevelAbstract || isParsingClass); |
3830 } | 3837 } |
3831 } | 3838 } |
OLD | NEW |