| 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 part of scanner; | 5 part of scanner; |
| 6 | 6 |
| 7 const bool VERBOSE = false; | 7 const bool VERBOSE = false; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * A parser event listener that does nothing except throw exceptions | 10 * A parser event listener that does nothing except throw exceptions |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 throw new ParserError("$message @ ${token.charOffset}"); | 598 throw new ParserError("$message @ ${token.charOffset}"); |
| 599 } | 599 } |
| 600 } | 600 } |
| 601 | 601 |
| 602 class ParserError { | 602 class ParserError { |
| 603 final String reason; | 603 final String reason; |
| 604 ParserError(this.reason); | 604 ParserError(this.reason); |
| 605 toString() => reason; | 605 toString() => reason; |
| 606 } | 606 } |
| 607 | 607 |
| 608 typedef int IdGenerator(); |
| 609 |
| 608 /** | 610 /** |
| 609 * A parser event listener designed to work with [PartialParser]. It | 611 * A parser event listener designed to work with [PartialParser]. It |
| 610 * builds elements representing the top-level declarations found in | 612 * builds elements representing the top-level declarations found in |
| 611 * the parsed compilation unit and records them in | 613 * the parsed compilation unit and records them in |
| 612 * [compilationUnitElement]. | 614 * [compilationUnitElement]. |
| 613 */ | 615 */ |
| 614 class ElementListener extends Listener { | 616 class ElementListener extends Listener { |
| 615 Function idGenerator; | 617 final IdGenerator idGenerator; |
| 616 final DiagnosticListener listener; | 618 final DiagnosticListener listener; |
| 617 final CompilationUnitElement compilationUnitElement; | 619 final CompilationUnitElement compilationUnitElement; |
| 618 final StringValidator stringValidator; | 620 final StringValidator stringValidator; |
| 619 Link<StringQuoting> interpolationScope; | 621 Link<StringQuoting> interpolationScope; |
| 620 | 622 |
| 621 Link<Node> nodes = const Link<Node>(); | 623 Link<Node> nodes = const Link<Node>(); |
| 622 | 624 |
| 623 Link<MetadataAnnotation> metadata = const Link<MetadataAnnotation>(); | 625 Link<MetadataAnnotation> metadata = const Link<MetadataAnnotation>(); |
| 624 | 626 |
| 625 ElementListener(DiagnosticListener listener, | 627 ElementListener(DiagnosticListener listener, |
| 626 CompilationUnitElement this.compilationUnitElement, | 628 this.compilationUnitElement, |
| 627 int idGenerator()) | 629 this.idGenerator) |
| 628 : this.listener = listener, | 630 : this.listener = listener, |
| 629 this.idGenerator = idGenerator, | |
| 630 stringValidator = new StringValidator(listener), | 631 stringValidator = new StringValidator(listener), |
| 631 interpolationScope = const Link<StringQuoting>(); | 632 interpolationScope = const Link<StringQuoting>(); |
| 632 | 633 |
| 633 void pushQuoting(StringQuoting quoting) { | 634 void pushQuoting(StringQuoting quoting) { |
| 634 interpolationScope = interpolationScope.prepend(quoting); | 635 interpolationScope = interpolationScope.prepend(quoting); |
| 635 } | 636 } |
| 636 | 637 |
| 637 StringQuoting popQuoting() { | 638 StringQuoting popQuoting() { |
| 638 StringQuoting result = interpolationScope.head; | 639 StringQuoting result = interpolationScope.head; |
| 639 interpolationScope = interpolationScope.tail; | 640 interpolationScope = interpolationScope.tail; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 // TODO(ahe): Record the defaultClause. | 785 // TODO(ahe): Record the defaultClause. |
| 785 Node defaultClause = popNode(); | 786 Node defaultClause = popNode(); |
| 786 NodeList supertypes = | 787 NodeList supertypes = |
| 787 makeNodeList(supertypeCount, extendsKeyword, null, ","); | 788 makeNodeList(supertypeCount, extendsKeyword, null, ","); |
| 788 NodeList typeParameters = popNode(); | 789 NodeList typeParameters = popNode(); |
| 789 Identifier name = popNode(); | 790 Identifier name = popNode(); |
| 790 int id = idGenerator(); | 791 int id = idGenerator(); |
| 791 pushElement(new PartialClassElement( | 792 pushElement(new PartialClassElement( |
| 792 name.source, interfaceKeyword, endToken, compilationUnitElement, id)); | 793 name.source, interfaceKeyword, endToken, compilationUnitElement, id)); |
| 793 rejectBuiltInIdentifier(name); | 794 rejectBuiltInIdentifier(name); |
| 795 listener.onDeprecatedFeature(interfaceKeyword, 'interface declarations'); |
| 794 } | 796 } |
| 795 | 797 |
| 796 void endFunctionTypeAlias(Token typedefKeyword, Token endToken) { | 798 void endFunctionTypeAlias(Token typedefKeyword, Token endToken) { |
| 797 NodeList typeVariables = popNode(); // TOOD(karlklose): do not throw away. | 799 NodeList typeVariables = popNode(); // TOOD(karlklose): do not throw away. |
| 798 Identifier name = popNode(); | 800 Identifier name = popNode(); |
| 799 TypeAnnotation returnType = popNode(); | 801 TypeAnnotation returnType = popNode(); |
| 800 pushElement(new PartialTypedefElement(name.source, compilationUnitElement, | 802 pushElement(new PartialTypedefElement(name.source, compilationUnitElement, |
| 801 typedefKeyword)); | 803 typedefKeyword)); |
| 802 rejectBuiltInIdentifier(name); | 804 rejectBuiltInIdentifier(name); |
| 803 } | 805 } |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 998 element.addMetadata(link.head); | 1000 element.addMetadata(link.head); |
| 999 } | 1001 } |
| 1000 metadata = const Link<MetadataAnnotation>(); | 1002 metadata = const Link<MetadataAnnotation>(); |
| 1001 compilationUnitElement.addMember(element, listener); | 1003 compilationUnitElement.addMember(element, listener); |
| 1002 } | 1004 } |
| 1003 | 1005 |
| 1004 void pushMetadata(MetadataAnnotation annotation) { | 1006 void pushMetadata(MetadataAnnotation annotation) { |
| 1005 metadata = metadata.prepend(annotation); | 1007 metadata = metadata.prepend(annotation); |
| 1006 } | 1008 } |
| 1007 | 1009 |
| 1010 // TODO(ahe): Remove this method. |
| 1008 void addScriptTag(ScriptTag tag) { | 1011 void addScriptTag(ScriptTag tag) { |
| 1009 // TODO(ahe): Remove this method. | 1012 listener.onDeprecatedFeature(tag, '# tags'); |
| 1010 addLibraryTag(tag.toLibraryTag()); | 1013 addLibraryTag(tag.toLibraryTag()); |
| 1011 } | 1014 } |
| 1012 | 1015 |
| 1013 void addLibraryTag(LibraryTag tag) { | 1016 void addLibraryTag(LibraryTag tag) { |
| 1014 if (!allowLibraryTags()) { | 1017 if (!allowLibraryTags()) { |
| 1015 recoverableError('library tags not allowed here', node: tag); | 1018 recoverableError('library tags not allowed here', node: tag); |
| 1016 } | 1019 } |
| 1017 compilationUnitElement.getImplementationLibrary().addTag(tag, listener); | 1020 compilationUnitElement.getImplementationLibrary().addTag(tag, listener); |
| 1018 } | 1021 } |
| 1019 | 1022 |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1331 String tokenString = token.stringValue; | 1334 String tokenString = token.stringValue; |
| 1332 if (identical(tokenString, '.') || identical(tokenString, '..')) { | 1335 if (identical(tokenString, '.') || identical(tokenString, '..')) { |
| 1333 if (argument is !Send) internalError(node: argument); | 1336 if (argument is !Send) internalError(node: argument); |
| 1334 if (argument.asSend().receiver != null) internalError(node: argument); | 1337 if (argument.asSend().receiver != null) internalError(node: argument); |
| 1335 if (argument is SendSet) internalError(node: argument); | 1338 if (argument is SendSet) internalError(node: argument); |
| 1336 pushNode(argument.asSend().copyWithReceiver(receiver)); | 1339 pushNode(argument.asSend().copyWithReceiver(receiver)); |
| 1337 } else { | 1340 } else { |
| 1338 NodeList arguments = new NodeList.singleton(argument); | 1341 NodeList arguments = new NodeList.singleton(argument); |
| 1339 pushNode(new Send(receiver, new Operator(token), arguments)); | 1342 pushNode(new Send(receiver, new Operator(token), arguments)); |
| 1340 } | 1343 } |
| 1344 if (identical(tokenString, '===') || identical(tokenString, '!==')) { |
| 1345 listener.onDeprecatedFeature(token, tokenString); |
| 1346 } |
| 1341 } | 1347 } |
| 1342 | 1348 |
| 1343 void beginCascade(Token token) { | 1349 void beginCascade(Token token) { |
| 1344 pushNode(new CascadeReceiver(popNode(), token)); | 1350 pushNode(new CascadeReceiver(popNode(), token)); |
| 1345 } | 1351 } |
| 1346 | 1352 |
| 1347 void endCascade() { | 1353 void endCascade() { |
| 1348 pushNode(new Cascade(popNode())); | 1354 pushNode(new Cascade(popNode())); |
| 1349 } | 1355 } |
| 1350 | 1356 |
| (...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1939 | 1945 |
| 1940 Node parse(DiagnosticListener diagnosticListener, | 1946 Node parse(DiagnosticListener diagnosticListener, |
| 1941 CompilationUnitElement element, | 1947 CompilationUnitElement element, |
| 1942 doParse(Parser parser)) { | 1948 doParse(Parser parser)) { |
| 1943 NodeListener listener = new NodeListener(diagnosticListener, element); | 1949 NodeListener listener = new NodeListener(diagnosticListener, element); |
| 1944 doParse(new Parser(listener)); | 1950 doParse(new Parser(listener)); |
| 1945 Node node = listener.popNode(); | 1951 Node node = listener.popNode(); |
| 1946 assert(listener.nodes.isEmpty); | 1952 assert(listener.nodes.isEmpty); |
| 1947 return node; | 1953 return node; |
| 1948 } | 1954 } |
| OLD | NEW |