Chromium Code Reviews| 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 /** | 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 Loading... | |
| 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); | |
|
Lasse Reichstein Nielsen
2012/09/14 09:36:09
Are we not supporting "part"?
ahe
2012/09/14 12:13:53
Not yet.
| |
| 51 } else { | 57 } else { |
| 52 return parseTopLevelMember(token); | 58 return parseTopLevelMember(token); |
| 53 } | 59 } |
| 54 } | 60 } |
| 55 | 61 |
| 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 listener.popNode(); // TODO(ahe): Hack. | |
|
Johnni Winther
2012/09/14 09:18:22
Why not just pop the node in endExport and discard
ahe
2012/09/14 12:13:53
I missed that. I was not supposed to upload the CL
| |
| 102 token = parseCombinators(token); | |
| 103 Token semicolon = token; | |
| 104 token = expect(';', token); | |
| 105 listener.endExport(exportKeyword, semicolon); | |
| 106 return token; | |
| 107 } | |
| 108 | |
| 109 Token parseCombinators(Token token) { | |
| 110 listener.beginCombinators(token); | |
| 111 int count = 0; | |
| 112 while (true) { | |
| 113 String value = token.stringValue; | |
| 114 if ('hide' === value) { | |
|
Lasse Reichstein Nielsen
2012/09/14 09:36:09
Why not (value === 'hide')?
ahe
2012/09/14 12:13:53
Because I felt like it.
| |
| 115 token = parseHide(token); | |
| 116 } else if ('show' === value) { | |
| 117 token = parseShow(token); | |
| 118 } else { | |
| 119 listener.endCombinators(count); | |
| 120 return token; | |
| 121 } | |
| 122 count++; | |
| 123 } | |
| 124 } | |
| 125 | |
| 126 /// hide identifierList | |
|
Lasse Reichstein Nielsen
2012/09/14 09:36:09
Make comment sentence. (Capitalized start, full st
ahe
2012/09/14 12:13:53
This is a doc comment that makes sense in this pla
| |
| 127 Token parseHide(Token token) { | |
| 128 Token hideKeyword = token; | |
| 129 listener.beginHide(hideKeyword); | |
| 130 assert(optional('hide', token)); | |
| 131 token = parseIdentifierList(token.next); | |
| 132 listener.endHide(hideKeyword); | |
| 133 return token; | |
| 134 } | |
| 135 | |
| 136 /// show identifierList | |
| 137 Token parseShow(Token token) { | |
| 138 Token showKeyword = token; | |
| 139 listener.beginShow(showKeyword); | |
| 140 assert(optional('show', token)); | |
| 141 token = parseIdentifierList(token.next); | |
| 142 listener.endShow(showKeyword); | |
| 143 return token; | |
| 144 } | |
| 145 | |
| 146 /// identifier (, identifier)* | |
| 147 Token parseIdentifierList(Token token) { | |
| 148 listener.beginIdentifierList(token); | |
| 149 int count = 0; | |
| 150 do { | |
| 151 token = parseIdentifier(token); | |
| 152 count++; | |
| 153 } while (optional(',', token)); | |
|
Johnni Winther
2012/09/14 09:18:22
If this is true token should also be updated to to
Lasse Reichstein Nielsen
2012/09/14 09:36:09
Missing token = token.next after recognizing ','.
ahe
2012/09/14 12:13:53
This is what I had originally. I should have stuck
| |
| 154 listener.endIdentifierList(count); | |
| 155 return token; | |
| 156 } | |
| 157 | |
| 56 Token parseMetadataStar(Token token) { | 158 Token parseMetadataStar(Token token) { |
| 57 while (optional('@', token)) { | 159 while (optional('@', token)) { |
| 58 token = parseMetadata(token); | 160 token = parseMetadata(token); |
| 59 } | 161 } |
| 60 return token; | 162 return token; |
| 61 } | 163 } |
| 62 | 164 |
| 63 /** | 165 /** |
| 64 * Parse | 166 * Parse |
| 65 * [: '@' qualified (‘.’ identifier)? (arguments)? :] | 167 * [: '@' qualified (‘.’ identifier)? (arguments)? :] |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 token = parseTypeVariablesOpt(token); | 337 token = parseTypeVariablesOpt(token); |
| 236 listener.endDefaultClause(defaultKeyword); | 338 listener.endDefaultClause(defaultKeyword); |
| 237 } else { | 339 } else { |
| 238 listener.handleNoDefaultClause(token); | 340 listener.handleNoDefaultClause(token); |
| 239 } | 341 } |
| 240 return token; | 342 return token; |
| 241 } | 343 } |
| 242 | 344 |
| 243 Token parseQualifiedRestOpt(Token token) { | 345 Token parseQualifiedRestOpt(Token token) { |
| 244 if (optional('.', token)) { | 346 if (optional('.', token)) { |
| 245 Token period = token; | 347 return parseQualifiedRest(token); |
| 246 token = parseIdentifier(token.next); | 348 } else { |
| 247 listener.handleQualified(period); | 349 return token; |
| 248 } | 350 } |
| 351 } | |
| 352 | |
| 353 Token parseQualifiedRest(Token token) { | |
| 354 assert(optional('.', token)); | |
| 355 Token period = token; | |
| 356 token = parseIdentifier(token.next); | |
| 357 listener.handleQualified(period); | |
| 249 return token; | 358 return token; |
| 250 } | 359 } |
| 251 | 360 |
| 252 bool isDefaultKeyword(Token token) { | 361 bool isDefaultKeyword(Token token) { |
| 253 String value = token.stringValue; | 362 String value = token.stringValue; |
| 254 if (value === 'default') return true; | 363 if (value === 'default') return true; |
| 255 if (value === 'factory') { | 364 if (value === 'factory') { |
| 256 listener.recoverableError("expected 'default'", token: token); | 365 listener.recoverableError("expected 'default'", token: token); |
| 257 return true; | 366 return true; |
| 258 } | 367 } |
| (...skipping 1669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1928 } | 2037 } |
| 1929 listener.handleContinueStatement(hasTarget, continueKeyword, token); | 2038 listener.handleContinueStatement(hasTarget, continueKeyword, token); |
| 1930 return expectSemicolon(token); | 2039 return expectSemicolon(token); |
| 1931 } | 2040 } |
| 1932 | 2041 |
| 1933 Token parseEmptyStatement(Token token) { | 2042 Token parseEmptyStatement(Token token) { |
| 1934 listener.handleEmptyStatement(token); | 2043 listener.handleEmptyStatement(token); |
| 1935 return expectSemicolon(token); | 2044 return expectSemicolon(token); |
| 1936 } | 2045 } |
| 1937 } | 2046 } |
| OLD | NEW |