| 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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 _recover = false; | 243 _recover = false; |
| 244 } | 244 } |
| 245 | 245 |
| 246 /////////////////////////////////////////////////////////////////// | 246 /////////////////////////////////////////////////////////////////// |
| 247 // Definition productions | 247 // Definition productions |
| 248 /////////////////////////////////////////////////////////////////// | 248 /////////////////////////////////////////////////////////////////// |
| 249 | 249 |
| 250 classDefinition(int kind) { | 250 classDefinition(int kind) { |
| 251 int start = _peekToken.start; | 251 int start = _peekToken.start; |
| 252 _eat(kind); | 252 _eat(kind); |
| 253 var name = identifier(); | 253 var name = identifierForType(); |
| 254 | 254 |
| 255 var typeParams = null; | 255 var typeParams = null; |
| 256 if (_peekKind(TokenKind.LT)) { | 256 if (_peekKind(TokenKind.LT)) { |
| 257 typeParams = typeParameters(); | 257 typeParams = typeParameters(); |
| 258 } | 258 } |
| 259 | 259 |
| 260 var _extends = null; | 260 var _extends = null; |
| 261 if (_maybeEat(TokenKind.EXTENDS)) { | 261 if (_maybeEat(TokenKind.EXTENDS)) { |
| 262 _extends = typeList(); | 262 _extends = typeList(); |
| 263 } | 263 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 _eat(TokenKind.TYPEDEF); | 314 _eat(TokenKind.TYPEDEF); |
| 315 | 315 |
| 316 var di = declaredIdentifier(false); | 316 var di = declaredIdentifier(false); |
| 317 var typeParams = null; | 317 var typeParams = null; |
| 318 if (_peekKind(TokenKind.LT)) { | 318 if (_peekKind(TokenKind.LT)) { |
| 319 typeParams = typeParameters(); | 319 typeParams = typeParameters(); |
| 320 } | 320 } |
| 321 var formals = formalParameterList(); | 321 var formals = formalParameterList(); |
| 322 _eatSemicolon(); | 322 _eatSemicolon(); |
| 323 | 323 |
| 324 // TODO(jimhug): Validate that di.name is not a pseudo-keyword |
| 324 var func = new FunctionDefinition(null, di.type, di.name, formals, | 325 var func = new FunctionDefinition(null, di.type, di.name, formals, |
| 325 null, null, null, _makeSpan(start)); | 326 null, null, null, _makeSpan(start)); |
| 326 | 327 |
| 327 return new FunctionTypeDefinition(func, typeParams, _makeSpan(start)); | 328 return new FunctionTypeDefinition(func, typeParams, _makeSpan(start)); |
| 328 } | 329 } |
| 329 | 330 |
| 330 initializers() { | 331 initializers() { |
| 331 _inhibitLambda = true; | 332 _inhibitLambda = true; |
| 332 var ret = []; | 333 var ret = []; |
| 333 do { | 334 do { |
| (...skipping 1275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1609 formals.add(formalParameter(inOptionalBlock)); | 1610 formals.add(formalParameter(inOptionalBlock)); |
| 1610 } | 1611 } |
| 1611 if (inOptionalBlock) { | 1612 if (inOptionalBlock) { |
| 1612 _eat(TokenKind.RBRACK); | 1613 _eat(TokenKind.RBRACK); |
| 1613 } | 1614 } |
| 1614 _eat(TokenKind.RPAREN); | 1615 _eat(TokenKind.RPAREN); |
| 1615 } | 1616 } |
| 1616 return formals; | 1617 return formals; |
| 1617 } | 1618 } |
| 1618 | 1619 |
| 1620 // Type names are not allowed to use pseudo keywords |
| 1621 identifierForType() { |
| 1622 var tok = _next(); |
| 1623 if (!_isIdentifier(tok.kind)) { |
| 1624 _error('expected identifier, but found $tok', tok.span); |
| 1625 } |
| 1626 if (tok.kind !== TokenKind.IDENTIFIER && tok.kind != TokenKind.NATIVE) { |
| 1627 _error('$tok may not be used as a type name', tok.span); |
| 1628 } |
| 1629 return new Identifier(tok.text, _makeSpan(tok.start)); |
| 1630 } |
| 1631 |
| 1619 identifier() { | 1632 identifier() { |
| 1620 var tok = _next(); | 1633 var tok = _next(); |
| 1621 if (!_isIdentifier(tok.kind)) { | 1634 if (!_isIdentifier(tok.kind)) { |
| 1622 _error('expected identifier, but found $tok', tok.span); | 1635 _error('expected identifier, but found $tok', tok.span); |
| 1623 } | 1636 } |
| 1624 | 1637 |
| 1625 return new Identifier(tok.text, _makeSpan(tok.start)); | 1638 return new Identifier(tok.text, _makeSpan(tok.start)); |
| 1626 } | 1639 } |
| 1627 | 1640 |
| 1628 /////////////////////////////////////////////////////////////////// | 1641 /////////////////////////////////////////////////////////////////// |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1699 int _pos = 0; | 1712 int _pos = 0; |
| 1700 next() { | 1713 next() { |
| 1701 var token = tokens[_pos]; | 1714 var token = tokens[_pos]; |
| 1702 ++_pos; | 1715 ++_pos; |
| 1703 if (_pos == tokens.length) { | 1716 if (_pos == tokens.length) { |
| 1704 parser.tokenizer = previousTokenizer; | 1717 parser.tokenizer = previousTokenizer; |
| 1705 } | 1718 } |
| 1706 return token; | 1719 return token; |
| 1707 } | 1720 } |
| 1708 } | 1721 } |
| OLD | NEW |