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

Side by Side Diff: dart/lib/compiler/implementation/scanner/parser.dart

Issue 10933093: Revert "Parse new library syntax." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 3 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
OLDNEW
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 /** 5 /**
6 * An event generating parser of Dart programs. This parser expects 6 * An event generating parser of Dart programs. This parser expects
7 * all tokens in a linked list (aka a token stream). 7 * all tokens in a linked list (aka a token stream).
8 * 8 *
9 * The class [Scanner] is used to generate a token stream. See the 9 * The class [Scanner] is used to generate a token stream. See the
10 * file scanner.dart. 10 * file scanner.dart.
(...skipping 30 matching lines...) Expand all
41 token = parseMetadataStar(token); 41 token = parseMetadataStar(token);
42 final String value = token.stringValue; 42 final String value = token.stringValue;
43 if (value === 'interface') { 43 if (value === 'interface') {
44 return parseInterface(token); 44 return parseInterface(token);
45 } else if ((value === 'abstract') || (value === 'class')) { 45 } else if ((value === 'abstract') || (value === 'class')) {
46 return parseClass(token); 46 return parseClass(token);
47 } else if (value === 'typedef') { 47 } else if (value === 'typedef') {
48 return parseNamedFunctionAlias(token); 48 return parseNamedFunctionAlias(token);
49 } else if (value === '#') { 49 } else if (value === '#') {
50 return parseScriptTags(token); 50 return parseScriptTags(token);
51 } else if (value === 'library') {
52 return parseLibraryName(token);
53 } else if (value === 'import') {
54 return parseImport(token);
55 } else if (value === 'export') {
56 return parseExport(token);
57 } else { 51 } else {
58 return parseTopLevelMember(token); 52 return parseTopLevelMember(token);
59 } 53 }
60 } 54 }
61 55
62 /// library qualified ';'
63 Token parseLibraryName(Token token) {
64 Token libraryKeyword = token;
65 listener.beginLibraryName(libraryKeyword);
66 assert(optional('library', token));
67 token = parseIdentifier(token.next);
68 while (optional('.', token)) {
69 token = parseQualifiedRest(token);
70 }
71 Token semicolon = token;
72 token = expect(';', token);
73 listener.endLibraryName(libraryKeyword, semicolon);
74 return token;
75 }
76
77 /// import uri (as identifier)? combinator* ';'
78 Token parseImport(Token token) {
79 Token importKeyword = token;
80 listener.beginImport(importKeyword);
81 assert(optional('import', token));
82 token = parseLiteralStringOrRecoverExpression(token.next);
83 Token asKeyword;
84 if (optional('as', token)) {
85 asKeyword = token;
86 token = parseIdentifier(token.next);
87 }
88 token = parseCombinators(token);
89 Token semicolon = token;
90 token = expect(';', token);
91 listener.endImport(importKeyword, asKeyword, semicolon);
92 return token;
93 }
94
95 /// export uri combinator* ';'
96 Token parseExport(Token token) {
97 Token exportKeyword = token;
98 listener.beginExport(exportKeyword);
99 assert(optional('export', token));
100 token = parseLiteralStringOrRecoverExpression(token.next);
101 token = parseCombinators(token);
102 Token semicolon = token;
103 token = expect(';', token);
104 listener.endExport(exportKeyword, semicolon);
105 return token;
106 }
107
108 Token parseCombinators(Token token) {
109 listener.beginCombinators(token);
110 int count = 0;
111 while (true) {
112 String value = token.stringValue;
113 if ('hide' === value) {
114 token = parseHide(token);
115 } else if ('show' === value) {
116 token = parseShow(token);
117 } else {
118 listener.endCombinators(count);
119 return token;
120 }
121 count++;
122 }
123 }
124
125 /// hide identifierList
126 Token parseHide(Token token) {
127 Token hideKeyword = token;
128 listener.beginHide(hideKeyword);
129 assert(optional('hide', token));
130 token = parseIdentifierList(token.next);
131 listener.endHide(hideKeyword);
132 return token;
133 }
134
135 /// show identifierList
136 Token parseShow(Token token) {
137 Token showKeyword = token;
138 listener.beginShow(showKeyword);
139 assert(optional('show', token));
140 token = parseIdentifierList(token.next);
141 listener.endShow(showKeyword);
142 return token;
143 }
144
145 /// identifier (, identifier)*
146 Token parseIdentifierList(Token token) {
147 listener.beginIdentifierList(token);
148 token = parseIdentifier(token);
149 int count = 1;
150 while (optional(',', token)) {
151 token = parseIdentifier(token.next);
152 count++;
153 }
154 listener.endIdentifierList(count);
155 return token;
156 }
157
158 Token parseMetadataStar(Token token) { 56 Token parseMetadataStar(Token token) {
159 while (optional('@', token)) { 57 while (optional('@', token)) {
160 token = parseMetadata(token); 58 token = parseMetadata(token);
161 } 59 }
162 return token; 60 return token;
163 } 61 }
164 62
165 /** 63 /**
166 * Parse 64 * Parse
167 * [: '@' qualified (‘.’ identifier)? (arguments)? :] 65 * [: '@' qualified (‘.’ identifier)? (arguments)? :]
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 token = parseTypeVariablesOpt(token); 235 token = parseTypeVariablesOpt(token);
338 listener.endDefaultClause(defaultKeyword); 236 listener.endDefaultClause(defaultKeyword);
339 } else { 237 } else {
340 listener.handleNoDefaultClause(token); 238 listener.handleNoDefaultClause(token);
341 } 239 }
342 return token; 240 return token;
343 } 241 }
344 242
345 Token parseQualifiedRestOpt(Token token) { 243 Token parseQualifiedRestOpt(Token token) {
346 if (optional('.', token)) { 244 if (optional('.', token)) {
347 return parseQualifiedRest(token); 245 Token period = token;
348 } else { 246 token = parseIdentifier(token.next);
349 return token; 247 listener.handleQualified(period);
350 } 248 }
351 }
352
353 Token parseQualifiedRest(Token token) {
354 assert(optional('.', token));
355 Token period = token;
356 token = parseIdentifier(token.next);
357 listener.handleQualified(period);
358 return token; 249 return token;
359 } 250 }
360 251
361 bool isDefaultKeyword(Token token) { 252 bool isDefaultKeyword(Token token) {
362 String value = token.stringValue; 253 String value = token.stringValue;
363 if (value === 'default') return true; 254 if (value === 'default') return true;
364 if (value === 'factory') { 255 if (value === 'factory') {
365 listener.recoverableError("expected 'default'", token: token); 256 listener.recoverableError("expected 'default'", token: token);
366 return true; 257 return true;
367 } 258 }
(...skipping 1669 matching lines...) Expand 10 before | Expand all | Expand 10 after
2037 } 1928 }
2038 listener.handleContinueStatement(hasTarget, continueKeyword, token); 1929 listener.handleContinueStatement(hasTarget, continueKeyword, token);
2039 return expectSemicolon(token); 1930 return expectSemicolon(token);
2040 } 1931 }
2041 1932
2042 Token parseEmptyStatement(Token token) { 1933 Token parseEmptyStatement(Token token) {
2043 listener.handleEmptyStatement(token); 1934 listener.handleEmptyStatement(token);
2044 return expectSemicolon(token); 1935 return expectSemicolon(token);
2045 } 1936 }
2046 } 1937 }
OLDNEW
« no previous file with comments | « dart/lib/compiler/implementation/scanner/listener.dart ('k') | dart/lib/compiler/implementation/scanner/scanner_task.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698