Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Side by Side Diff: pkg/analyzer/test/generated/parser_fasta_test.dart

Issue 2993833002: fasta listener assert enclosing event (Closed)
Patch Set: update comment Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/test/generated/parser_fasta_listener.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 import 'package:analyzer/dart/ast/ast.dart'; 5 import 'package:analyzer/dart/ast/ast.dart';
6 import 'package:analyzer/dart/ast/token.dart' as analyzer; 6 import 'package:analyzer/dart/ast/token.dart' as analyzer;
7 import 'package:analyzer/error/error.dart'; 7 import 'package:analyzer/error/error.dart';
8 import 'package:analyzer/error/listener.dart' show ErrorReporter; 8 import 'package:analyzer/error/listener.dart' show ErrorReporter;
9 import 'package:analyzer/src/dart/scanner/scanner.dart'; 9 import 'package:analyzer/src/dart/scanner/scanner.dart';
10 import 'package:analyzer/src/fasta/ast_builder.dart'; 10 import 'package:analyzer/src/fasta/ast_builder.dart';
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 token, 460 token,
461 inFunctionType 461 inFunctionType
462 ? fasta.MemberKind.GeneralizedFunctionType 462 ? fasta.MemberKind.GeneralizedFunctionType
463 : fasta.MemberKind.NonStaticMethod); 463 : fasta.MemberKind.NonStaticMethod);
464 }, 464 },
465 errorCodes) as FormalParameterList; 465 errorCodes) as FormalParameterList;
466 } 466 }
467 467
468 @override 468 @override
469 CompilationUnitMember parseFullCompilationUnitMember() { 469 CompilationUnitMember parseFullCompilationUnitMember() {
470 return _parserProxy._run((parser) => parser.parseTopLevelDeclaration); 470 return _parserProxy.parseTopLevelDeclaration();
471 } 471 }
472 472
473 @override 473 @override
474 Directive parseFullDirective() { 474 Directive parseFullDirective() {
475 return _parserProxy._run((parser) => parser.parseTopLevelDeclaration); 475 return _parserProxy.parseTopLevelDeclaration();
476 } 476 }
477 477
478 @override 478 @override
479 FunctionExpression parseFunctionExpression(String code) { 479 FunctionExpression parseFunctionExpression(String code) {
480 return _parseExpression(code); 480 return _parseExpression(code);
481 } 481 }
482 482
483 @override 483 @override
484 InstanceCreationExpression parseInstanceCreationExpression( 484 InstanceCreationExpression parseInstanceCreationExpression(
485 String code, analyzer.Token newToken) { 485 String code, analyzer.Token newToken) {
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 * The builder which creates the analyzer AST data structures expected by the 785 * The builder which creates the analyzer AST data structures expected by the
786 * analyzer parser tests. 786 * analyzer parser tests.
787 */ 787 */
788 final AstBuilder _astBuilder; 788 final AstBuilder _astBuilder;
789 789
790 /** 790 /**
791 * The error listener to which scanner and parser errors will be reported. 791 * The error listener to which scanner and parser errors will be reported.
792 */ 792 */
793 final GatheringErrorListener _errorListener; 793 final GatheringErrorListener _errorListener;
794 794
795 final ForwardingTestListener _eventListener;
796
795 /** 797 /**
796 * Creates a [ParserProxy] which is prepared to begin parsing at the given 798 * Creates a [ParserProxy] which is prepared to begin parsing at the given
797 * Fasta token. 799 * Fasta token.
798 */ 800 */
799 factory ParserProxy(analyzer.Token startingToken, 801 factory ParserProxy(analyzer.Token startingToken,
800 {bool enableGenericMethodComments: false}) { 802 {bool enableGenericMethodComments: false}) {
801 var library = new KernelLibraryBuilderProxy(); 803 var library = new KernelLibraryBuilderProxy();
802 var member = new BuilderProxy(); 804 var member = new BuilderProxy();
803 var scope = new ScopeProxy(); 805 var scope = new ScopeProxy();
804 TestSource source = new TestSource(); 806 TestSource source = new TestSource();
805 var errorListener = new GatheringErrorListener(); 807 var errorListener = new GatheringErrorListener();
806 var errorReporter = new ErrorReporter(errorListener, source); 808 var errorReporter = new ErrorReporter(errorListener, source);
807 var astBuilder = 809 var astBuilder =
808 new AstBuilder(errorReporter, library, member, scope, true); 810 new AstBuilder(errorReporter, library, member, scope, true);
809 astBuilder.parseGenericMethodComments = enableGenericMethodComments; 811 astBuilder.parseGenericMethodComments = enableGenericMethodComments;
810 var fastaParser = new fasta.Parser(new ForwardingTestListener(astBuilder)); 812 var eventListener = new ForwardingTestListener(astBuilder);
813 var fastaParser = new fasta.Parser(eventListener);
811 astBuilder.parser = fastaParser; 814 astBuilder.parser = fastaParser;
812 return new ParserProxy._( 815 return new ParserProxy._(
813 startingToken, fastaParser, astBuilder, errorListener); 816 startingToken, fastaParser, astBuilder, errorListener, eventListener);
814 } 817 }
815 818
816 ParserProxy._(this._currentFastaToken, this._fastaParser, this._astBuilder, 819 ParserProxy._(this._currentFastaToken, this._fastaParser, this._astBuilder,
817 this._errorListener); 820 this._errorListener, this._eventListener);
818 821
819 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 822 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
820 823
821 @override 824 @override
822 ClassMember parseClassMember(String className) { 825 ClassMember parseClassMember(String className) {
823 _astBuilder.className = className; 826 _astBuilder.className = className;
827 _eventListener.begin('CompilationUnit');
824 var result = _run((parser) => parser.parseMember) as ClassMember; 828 var result = _run((parser) => parser.parseMember) as ClassMember;
829 _eventListener.end('CompilationUnit');
825 _astBuilder.className = null; 830 _astBuilder.className = null;
826 return result; 831 return result;
827 } 832 }
828 833
829 @override 834 @override
830 CompilationUnit parseCompilationUnit2() { 835 CompilationUnit parseCompilationUnit2() {
831 return _run((parser) => parser.parseUnit) as CompilationUnit; 836 var result = _run((parser) => parser.parseUnit) as CompilationUnit;
837 _eventListener.expectEmpty();
838 return result;
839 }
840
841 AnnotatedNode parseTopLevelDeclaration() {
842 _eventListener.begin('CompilationUnit');
843 var result = _run((parser) => parser.parseTopLevelDeclaration);
844 _eventListener.end('CompilationUnit');
845 return result;
832 } 846 }
833 847
834 /** 848 /**
835 * Runs a single parser function, and returns the result as an analyzer AST. 849 * Runs a single parser function, and returns the result as an analyzer AST.
836 */ 850 */
837 Object _run(ParseFunction getParseFunction(fasta.Parser parser)) { 851 Object _run(ParseFunction getParseFunction(fasta.Parser parser)) {
838 var parseFunction = getParseFunction(_fastaParser); 852 var parseFunction = getParseFunction(_fastaParser);
839 _currentFastaToken = parseFunction(_currentFastaToken); 853 _currentFastaToken = parseFunction(_currentFastaToken);
840 expect(_currentFastaToken.isEof, isTrue); 854 expect(_currentFastaToken.isEof, isTrue);
841 expect(_astBuilder.stack, hasLength(1)); 855 expect(_astBuilder.stack, hasLength(1));
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 assertNoErrors(); 1024 assertNoErrors();
1011 } 1025 }
1012 1026
1013 @failingTest 1027 @failingTest
1014 void test_parseCompilationUnitMember_abstractAsPrefix2() { 1028 void test_parseCompilationUnitMember_abstractAsPrefix2() {
1015 // TODO(danrubel): should not be generating an error 1029 // TODO(danrubel): should not be generating an error
1016 super.test_parseCompilationUnitMember_abstractAsPrefix(); 1030 super.test_parseCompilationUnitMember_abstractAsPrefix();
1017 assertNoErrors(); 1031 assertNoErrors();
1018 } 1032 }
1019 } 1033 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/parser_fasta_listener.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698