| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // Utilities for building JS ASTs at runtime. Contains a builder class | 5 // Utilities for building JS ASTs at runtime. Contains a builder class |
| 6 // and a parser that parses part of the language. | 6 // and a parser that parses part of the language. |
| 7 | 7 |
| 8 part of js; | 8 part of js; |
| 9 | 9 |
| 10 | 10 |
| (...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 String last = lastToken; | 709 String last = lastToken; |
| 710 if (acceptCategory(ALPHA)) { | 710 if (acceptCategory(ALPHA)) { |
| 711 if (last == "true") { | 711 if (last == "true") { |
| 712 return new LiteralBool(true); | 712 return new LiteralBool(true); |
| 713 } else if (last == "false") { | 713 } else if (last == "false") { |
| 714 return new LiteralBool(false); | 714 return new LiteralBool(false); |
| 715 } else if (last == "null") { | 715 } else if (last == "null") { |
| 716 return new LiteralNull(); | 716 return new LiteralNull(); |
| 717 } else if (last == "function") { | 717 } else if (last == "function") { |
| 718 return parseFunctionExpression(); | 718 return parseFunctionExpression(); |
| 719 } else if (last == "this") { |
| 720 return new This(); |
| 719 } else { | 721 } else { |
| 720 return new VariableUse(last); | 722 return new VariableUse(last); |
| 721 } | 723 } |
| 722 } else if (acceptCategory(LPAREN)) { | 724 } else if (acceptCategory(LPAREN)) { |
| 723 Expression expression = parseExpression(); | 725 Expression expression = parseExpression(); |
| 724 expectCategory(RPAREN); | 726 expectCategory(RPAREN); |
| 725 return expression; | 727 return expression; |
| 726 } else if (acceptCategory(STRING)) { | 728 } else if (acceptCategory(STRING)) { |
| 727 return new LiteralString(last); | 729 return new LiteralString(last); |
| 728 } else if (acceptCategory(NUMERIC)) { | 730 } else if (acceptCategory(NUMERIC)) { |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1109 if (acceptString('while')) return parseWhile(); | 1111 if (acceptString('while')) return parseWhile(); |
| 1110 | 1112 |
| 1111 if (acceptString('do')) return parseDo(); | 1113 if (acceptString('do')) return parseDo(); |
| 1112 | 1114 |
| 1113 if (acceptString('switch')) return parseSwitch(); | 1115 if (acceptString('switch')) return parseSwitch(); |
| 1114 | 1116 |
| 1115 if (lastToken == 'case') error("Case outside switch."); | 1117 if (lastToken == 'case') error("Case outside switch."); |
| 1116 | 1118 |
| 1117 if (lastToken == 'default') error("Default outside switch."); | 1119 if (lastToken == 'default') error("Default outside switch."); |
| 1118 | 1120 |
| 1121 if (lastToken == 'yield') return parseYield(); |
| 1122 |
| 1119 if (lastToken == 'with') { | 1123 if (lastToken == 'with') { |
| 1120 error('Not implemented in mini parser'); | 1124 error('Not implemented in mini parser'); |
| 1121 } | 1125 } |
| 1126 |
| 1122 } | 1127 } |
| 1123 | 1128 |
| 1124 bool checkForInterpolatedStatement = lastCategory == HASH; | 1129 bool checkForInterpolatedStatement = lastCategory == HASH; |
| 1125 | 1130 |
| 1126 Expression expression = parseExpression(); | 1131 Expression expression = parseExpression(); |
| 1127 | 1132 |
| 1128 if (expression is VariableUse && acceptCategory(COLON)) { | 1133 if (expression is VariableUse && acceptCategory(COLON)) { |
| 1129 return new LabeledStatement(expression.name, parseStatement()); | 1134 return new LabeledStatement(expression.name, parseStatement()); |
| 1130 } | 1135 } |
| 1131 | 1136 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1146 return new ExpressionStatement(expression); | 1151 return new ExpressionStatement(expression); |
| 1147 } | 1152 } |
| 1148 | 1153 |
| 1149 Statement parseReturn() { | 1154 Statement parseReturn() { |
| 1150 if (acceptSemicolon()) return new Return(); | 1155 if (acceptSemicolon()) return new Return(); |
| 1151 Expression expression = parseExpression(); | 1156 Expression expression = parseExpression(); |
| 1152 expectSemicolon(); | 1157 expectSemicolon(); |
| 1153 return new Return(expression); | 1158 return new Return(expression); |
| 1154 } | 1159 } |
| 1155 | 1160 |
| 1161 Statement parseYield() { |
| 1162 bool hasStar = acceptString('*'); |
| 1163 Expression expression = parseExpression(); |
| 1164 expectSemicolon(); |
| 1165 return new DartYield(expression, hasStar); |
| 1166 } |
| 1167 |
| 1156 Statement parseThrow() { | 1168 Statement parseThrow() { |
| 1157 if (skippedNewline) error('throw expression must be on same line'); | 1169 if (skippedNewline) error('throw expression must be on same line'); |
| 1158 Expression expression = parseExpression(); | 1170 Expression expression = parseExpression(); |
| 1159 expectSemicolon(); | 1171 expectSemicolon(); |
| 1160 return new Throw(expression); | 1172 return new Throw(expression); |
| 1161 } | 1173 } |
| 1162 | 1174 |
| 1163 Statement parseBreakOrContinue(constructor) { | 1175 Statement parseBreakOrContinue(constructor) { |
| 1164 var identifier = lastToken; | 1176 var identifier = lastToken; |
| 1165 if (!skippedNewline && acceptCategory(ALPHA)) { | 1177 if (!skippedNewline && acceptCategory(ALPHA)) { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1315 Catch parseCatch() { | 1327 Catch parseCatch() { |
| 1316 expectCategory(LPAREN); | 1328 expectCategory(LPAREN); |
| 1317 String identifier = lastToken; | 1329 String identifier = lastToken; |
| 1318 expectCategory(ALPHA); | 1330 expectCategory(ALPHA); |
| 1319 expectCategory(RPAREN); | 1331 expectCategory(RPAREN); |
| 1320 expectCategory(LBRACE); | 1332 expectCategory(LBRACE); |
| 1321 Block body = parseBlock(); | 1333 Block body = parseBlock(); |
| 1322 return new Catch(new VariableDeclaration(identifier), body); | 1334 return new Catch(new VariableDeclaration(identifier), body); |
| 1323 } | 1335 } |
| 1324 } | 1336 } |
| OLD | NEW |