| 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 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1244 _afterParens[saved] = _peekToken; | 1244 _afterParens[saved] = _peekToken; |
| 1245 return; | 1245 return; |
| 1246 } else if (kind == TokenKind.LPAREN) { | 1246 } else if (kind == TokenKind.LPAREN) { |
| 1247 // Scan anything inside these nested parenthesis | 1247 // Scan anything inside these nested parenthesis |
| 1248 _lookaheadAfterParens(tokens); | 1248 _lookaheadAfterParens(tokens); |
| 1249 } | 1249 } |
| 1250 } | 1250 } |
| 1251 } | 1251 } |
| 1252 | 1252 |
| 1253 _typeAsIdentifier(type) { | 1253 _typeAsIdentifier(type) { |
| 1254 if (type.name.name == 'void') { |
| 1255 _errorExpected('identifer, but found "${type.name.name}"'); |
| 1256 } |
| 1257 |
| 1254 // TODO(jimhug): lots of errors to check for | 1258 // TODO(jimhug): lots of errors to check for |
| 1255 return type.name; | 1259 return type.name; |
| 1256 } | 1260 } |
| 1257 | 1261 |
| 1258 _specialIdentifier(bool includeOperators) { | 1262 _specialIdentifier(bool includeOperators) { |
| 1259 int start = _peekToken.start; | 1263 int start = _peekToken.start; |
| 1260 String name; | 1264 String name; |
| 1261 | 1265 |
| 1262 switch (_peek()) { | 1266 switch (_peek()) { |
| 1263 case TokenKind.ELLIPSIS: | 1267 case TokenKind.ELLIPSIS: |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1648 * [FunctionDefinition]. | 1652 * [FunctionDefinition]. |
| 1649 */ | 1653 */ |
| 1650 _makeFunction(expr, formals, body) { | 1654 _makeFunction(expr, formals, body) { |
| 1651 var name, type; | 1655 var name, type; |
| 1652 if (expr is VarExpression) { | 1656 if (expr is VarExpression) { |
| 1653 name = expr.name; | 1657 name = expr.name; |
| 1654 type = null; | 1658 type = null; |
| 1655 } else if (expr is DeclaredIdentifier) { | 1659 } else if (expr is DeclaredIdentifier) { |
| 1656 name = expr.name; | 1660 name = expr.name; |
| 1657 type = expr.type; | 1661 type = expr.type; |
| 1662 if (name == null) { |
| 1663 _error('expected name and type', expr.span); |
| 1664 } |
| 1658 } else { | 1665 } else { |
| 1659 _error('bad function body', expr.span); | 1666 _error('bad function body', expr.span); |
| 1660 } | 1667 } |
| 1661 var span = new SourceSpan(expr.span.file, expr.span.start, body.span.end); | 1668 var span = new SourceSpan(expr.span.file, expr.span.start, body.span.end); |
| 1662 var func = new FunctionDefinition(null, type, name, formals, null, null, | 1669 var func = new FunctionDefinition(null, type, name, formals, null, null, |
| 1663 body, span); | 1670 body, span); |
| 1664 return new LambdaExpression(func, func.span); | 1671 return new LambdaExpression(func, func.span); |
| 1665 } | 1672 } |
| 1666 | 1673 |
| 1667 /** Converts an expression to a [DeclaredIdentifier]. */ | 1674 /** Converts an expression to a [DeclaredIdentifier]. */ |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1712 int _pos = 0; | 1719 int _pos = 0; |
| 1713 next() { | 1720 next() { |
| 1714 var token = tokens[_pos]; | 1721 var token = tokens[_pos]; |
| 1715 ++_pos; | 1722 ++_pos; |
| 1716 if (_pos == tokens.length) { | 1723 if (_pos == tokens.length) { |
| 1717 parser.tokenizer = previousTokenizer; | 1724 parser.tokenizer = previousTokenizer; |
| 1718 } | 1725 } |
| 1719 return token; | 1726 return token; |
| 1720 } | 1727 } |
| 1721 } | 1728 } |
| OLD | NEW |