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

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

Issue 1044383002: improve parser recovery when top level function is missing parameters (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 5 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library engine.parser_test; 5 library engine.parser_test;
6 6
7 import 'package:analyzer/src/generated/ast.dart'; 7 import 'package:analyzer/src/generated/ast.dart';
8 import 'package:analyzer/src/generated/element.dart'; 8 import 'package:analyzer/src/generated/element.dart';
9 import 'package:analyzer/src/generated/engine.dart'; 9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/error.dart'; 10 import 'package:analyzer/src/generated/error.dart';
(...skipping 1177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 ParserTestCase.parseCompilationUnit( 1188 ParserTestCase.parseCompilationUnit(
1189 "void f(final x()) {}", [ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR]); 1189 "void f(final x()) {}", [ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR]);
1190 } 1190 }
1191 1191
1192 void test_functionTypedParameter_var() { 1192 void test_functionTypedParameter_var() {
1193 ParserTestCase.parseCompilationUnit( 1193 ParserTestCase.parseCompilationUnit(
1194 "void f(var x()) {}", [ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR]); 1194 "void f(var x()) {}", [ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR]);
1195 } 1195 }
1196 1196
1197 void test_getterInFunction_block_noReturnType() { 1197 void test_getterInFunction_block_noReturnType() {
1198 ParserTestCase.parseStatement( 1198 FunctionDeclarationStatement statement = ParserTestCase.parseStatement(
1199 "get x { return _x; }", [ParserErrorCode.GETTER_IN_FUNCTION]); 1199 "get x { return _x; }", [ParserErrorCode.GETTER_IN_FUNCTION]);
1200 expect(statement.functionDeclaration.functionExpression.parameters, isNull);
1200 } 1201 }
1201 1202
1202 void test_getterInFunction_block_returnType() { 1203 void test_getterInFunction_block_returnType() {
1203 ParserTestCase.parseStatement( 1204 ParserTestCase.parseStatement(
1204 "int get x { return _x; }", [ParserErrorCode.GETTER_IN_FUNCTION]); 1205 "int get x { return _x; }", [ParserErrorCode.GETTER_IN_FUNCTION]);
1205 } 1206 }
1206 1207
1207 void test_getterInFunction_expression_noReturnType() { 1208 void test_getterInFunction_expression_noReturnType() {
1208 ParserTestCase.parseStatement( 1209 ParserTestCase.parseStatement(
1209 "get x => _x;", [ParserErrorCode.GETTER_IN_FUNCTION]); 1210 "get x => _x;", [ParserErrorCode.GETTER_IN_FUNCTION]);
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1478 ParserTestCase.parseCompilationUnit( 1479 ParserTestCase.parseCompilationUnit(
1479 "int f { return x;}", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); 1480 "int f { return x;}", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]);
1480 } 1481 }
1481 1482
1482 void test_missingFunctionParameters_topLevel_nonVoid_expression() { 1483 void test_missingFunctionParameters_topLevel_nonVoid_expression() {
1483 ParserTestCase.parseCompilationUnit( 1484 ParserTestCase.parseCompilationUnit(
1484 "int f => x;", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); 1485 "int f => x;", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]);
1485 } 1486 }
1486 1487
1487 void test_missingFunctionParameters_topLevel_void_block() { 1488 void test_missingFunctionParameters_topLevel_void_block() {
1488 ParserTestCase.parseCompilationUnit( 1489 CompilationUnit unit = ParserTestCase.parseCompilationUnit(
1489 "void f { return x;}", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); 1490 "void f { return x;}", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]);
1491 FunctionDeclaration funct = unit.declarations[0];
1492 expect(funct.functionExpression.parameters, hasLength(0));
1490 } 1493 }
1491 1494
1492 void test_missingFunctionParameters_topLevel_void_expression() { 1495 void test_missingFunctionParameters_topLevel_void_expression() {
1493 ParserTestCase.parseCompilationUnit( 1496 CompilationUnit unit = ParserTestCase.parseCompilationUnit(
1494 "void f => x;", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); 1497 "void f => x;", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]);
1498 FunctionDeclaration funct = unit.declarations[0];
1499 expect(funct.functionExpression.parameters, hasLength(0));
1495 } 1500 }
1496 1501
1497 void test_missingIdentifier_afterOperator() { 1502 void test_missingIdentifier_afterOperator() {
1498 parse4("parseMultiplicativeExpression", "1 *", 1503 parse4("parseMultiplicativeExpression", "1 *",
1499 [ParserErrorCode.MISSING_IDENTIFIER]); 1504 [ParserErrorCode.MISSING_IDENTIFIER]);
1500 } 1505 }
1501 1506
1502 void test_missingIdentifier_beforeClosingCurly() { 1507 void test_missingIdentifier_beforeClosingCurly() {
1503 parse3("parseClassMember", <Object>["C"], "int}", [ 1508 parse3("parseClassMember", <Object>["C"], "int}", [
1504 ParserErrorCode.MISSING_IDENTIFIER, 1509 ParserErrorCode.MISSING_IDENTIFIER,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1547 parse3("parseClassMember", <Object>["C"], "int +() {}", 1552 parse3("parseClassMember", <Object>["C"], "int +() {}",
1548 [ParserErrorCode.MISSING_KEYWORD_OPERATOR]); 1553 [ParserErrorCode.MISSING_KEYWORD_OPERATOR]);
1549 } 1554 }
1550 1555
1551 void test_missingKeywordOperator_parseClassMember_afterVoid() { 1556 void test_missingKeywordOperator_parseClassMember_afterVoid() {
1552 parse3("parseClassMember", <Object>["C"], "void +() {}", 1557 parse3("parseClassMember", <Object>["C"], "void +() {}",
1553 [ParserErrorCode.MISSING_KEYWORD_OPERATOR]); 1558 [ParserErrorCode.MISSING_KEYWORD_OPERATOR]);
1554 } 1559 }
1555 1560
1556 void test_missingMethodParameters_void_block() { 1561 void test_missingMethodParameters_void_block() {
1557 parse3("parseClassMember", <Object>["C"], "void m {} }", 1562 MethodDeclaration method = parse3("parseClassMember",
1563 <Object>["C"], "void m {} }",
1558 [ParserErrorCode.MISSING_METHOD_PARAMETERS]); 1564 [ParserErrorCode.MISSING_METHOD_PARAMETERS]);
1565 expect(method.parameters, hasLength(0));
1559 } 1566 }
1560 1567
1561 void test_missingMethodParameters_void_expression() { 1568 void test_missingMethodParameters_void_expression() {
1562 parse3("parseClassMember", <Object>["C"], "void m => null; }", 1569 parse3("parseClassMember", <Object>["C"], "void m => null; }",
1563 [ParserErrorCode.MISSING_METHOD_PARAMETERS]); 1570 [ParserErrorCode.MISSING_METHOD_PARAMETERS]);
1564 } 1571 }
1565 1572
1566 void test_missingNameInLibraryDirective() { 1573 void test_missingNameInLibraryDirective() {
1567 CompilationUnit unit = ParserTestCase.parseCompilationUnit( 1574 CompilationUnit unit = ParserTestCase.parseCompilationUnit(
1568 "library;", [ParserErrorCode.MISSING_NAME_IN_LIBRARY_DIRECTIVE]); 1575 "library;", [ParserErrorCode.MISSING_NAME_IN_LIBRARY_DIRECTIVE]);
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1850 1857
1851 void test_switchHasMultipleDefaultCases_repeated() { 1858 void test_switchHasMultipleDefaultCases_repeated() {
1852 parse4("parseSwitchStatement", 1859 parse4("parseSwitchStatement",
1853 "switch (a) {default: return 0; default: return 1; default: return 2;}", 1860 "switch (a) {default: return 0; default: return 1; default: return 2;}",
1854 [ 1861 [
1855 ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES, 1862 ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES,
1856 ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES 1863 ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES
1857 ]); 1864 ]);
1858 } 1865 }
1859 1866
1867 void test_topLevel_getter() {
1868 FunctionDeclaration funct = parse3("parseCompilationUnitMember",
1869 <Object>[emptyCommentAndMetadata()],
1870 "get x => 7;");
1871 expect(funct.functionExpression.parameters, isNull);
1872 }
1873
1860 void test_topLevelOperator_withoutType() { 1874 void test_topLevelOperator_withoutType() {
1861 parse3("parseCompilationUnitMember", <Object>[emptyCommentAndMetadata()], 1875 parse3("parseCompilationUnitMember", <Object>[emptyCommentAndMetadata()],
1862 "operator +(bool x, bool y) => x | y;", 1876 "operator +(bool x, bool y) => x | y;",
1863 [ParserErrorCode.TOP_LEVEL_OPERATOR]); 1877 [ParserErrorCode.TOP_LEVEL_OPERATOR]);
1864 } 1878 }
1865 1879
1866 void test_topLevelOperator_withType() { 1880 void test_topLevelOperator_withType() {
1867 parse3("parseCompilationUnitMember", <Object>[emptyCommentAndMetadata()], 1881 parse3("parseCompilationUnitMember", <Object>[emptyCommentAndMetadata()],
1868 "bool operator +(bool x, bool y) => x | y;", 1882 "bool operator +(bool x, bool y) => x | y;",
1869 [ParserErrorCode.TOP_LEVEL_OPERATOR]); 1883 [ParserErrorCode.TOP_LEVEL_OPERATOR]);
(...skipping 3557 matching lines...) Expand 10 before | Expand all | Expand 10 after
5427 MethodDeclaration method = 5441 MethodDeclaration method =
5428 parse("parseClassMember", <Object>["C"], "void get g {}"); 5442 parse("parseClassMember", <Object>["C"], "void get g {}");
5429 expect(method.documentationComment, isNull); 5443 expect(method.documentationComment, isNull);
5430 expect(method.externalKeyword, isNull); 5444 expect(method.externalKeyword, isNull);
5431 expect(method.modifierKeyword, isNull); 5445 expect(method.modifierKeyword, isNull);
5432 expect(method.propertyKeyword, isNotNull); 5446 expect(method.propertyKeyword, isNotNull);
5433 expect(method.returnType, isNotNull); 5447 expect(method.returnType, isNotNull);
5434 expect(method.name, isNotNull); 5448 expect(method.name, isNotNull);
5435 expect(method.operatorKeyword, isNull); 5449 expect(method.operatorKeyword, isNull);
5436 expect(method.body, isNotNull); 5450 expect(method.body, isNotNull);
5451 expect(method.parameters, isNull);
5437 } 5452 }
5438 5453
5439 void test_parseClassMember_method_external() { 5454 void test_parseClassMember_method_external() {
5440 MethodDeclaration method = 5455 MethodDeclaration method =
5441 parse("parseClassMember", <Object>["C"], "external m();"); 5456 parse("parseClassMember", <Object>["C"], "external m();");
5442 expect(method.body, isNotNull); 5457 expect(method.body, isNotNull);
5443 expect(method.documentationComment, isNull); 5458 expect(method.documentationComment, isNull);
5444 expect(method.externalKeyword, isNotNull); 5459 expect(method.externalKeyword, isNotNull);
5445 expect(method.modifierKeyword, isNull); 5460 expect(method.modifierKeyword, isNull);
5446 expect(method.name, isNotNull); 5461 expect(method.name, isNotNull);
(...skipping 4573 matching lines...) Expand 10 before | Expand all | Expand 10 after
10020 new Scanner(null, new CharSequenceReader(source), listener); 10035 new Scanner(null, new CharSequenceReader(source), listener);
10021 Token tokenStream = scanner.tokenize(); 10036 Token tokenStream = scanner.tokenize();
10022 // 10037 //
10023 // Parse the source. 10038 // Parse the source.
10024 // 10039 //
10025 Parser parser = new Parser(null, listener); 10040 Parser parser = new Parser(null, listener);
10026 return invokeParserMethodImpl( 10041 return invokeParserMethodImpl(
10027 parser, methodName, <Object>[tokenStream], tokenStream) as Token; 10042 parser, methodName, <Object>[tokenStream], tokenStream) as Token;
10028 } 10043 }
10029 } 10044 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698