Chromium Code Reviews| Index: dart/lib/compiler/implementation/scanner/parser.dart |
| diff --git a/dart/lib/compiler/implementation/scanner/parser.dart b/dart/lib/compiler/implementation/scanner/parser.dart |
| index 8f31c7b262d377287e0392099684deca7e82bd46..25f1bb386e654ea58ee13f0e0b6ad4ab3799c5a8 100644 |
| --- a/dart/lib/compiler/implementation/scanner/parser.dart |
| +++ b/dart/lib/compiler/implementation/scanner/parser.dart |
| @@ -48,11 +48,113 @@ class Parser { |
| return parseNamedFunctionAlias(token); |
| } else if (value === '#') { |
| return parseScriptTags(token); |
| + } else if (value === 'library') { |
| + return parseLibraryName(token); |
| + } else if (value === 'import') { |
| + return parseImport(token); |
| + } else if (value === 'export') { |
| + 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.
|
| } else { |
| return parseTopLevelMember(token); |
| } |
| } |
| + /// library qualified ';' |
| + Token parseLibraryName(Token token) { |
| + Token libraryKeyword = token; |
| + listener.beginLibraryName(libraryKeyword); |
| + assert(optional('library', token)); |
| + token = parseIdentifier(token.next); |
| + while (optional('.', token)) { |
| + token = parseQualifiedRest(token); |
| + } |
| + Token semicolon = token; |
| + token = expect(';', token); |
| + listener.endLibraryName(libraryKeyword, semicolon); |
| + return token; |
| + } |
| + |
| + /// import uri (as identifier)? combinator* ';' |
| + Token parseImport(Token token) { |
| + Token importKeyword = token; |
| + listener.beginImport(importKeyword); |
| + assert(optional('import', token)); |
| + token = parseLiteralStringOrRecoverExpression(token.next); |
| + Token asKeyword; |
| + if (optional('as', token)) { |
| + asKeyword = token; |
| + token = parseIdentifier(token.next); |
| + } |
| + token = parseCombinators(token); |
| + Token semicolon = token; |
| + token = expect(';', token); |
| + listener.endImport(importKeyword, asKeyword, semicolon); |
| + return token; |
| + } |
| + |
| + /// export uri combinator* ';' |
| + Token parseExport(Token token) { |
| + Token exportKeyword = token; |
| + listener.beginExport(exportKeyword); |
| + assert(optional('export', token)); |
| + token = parseLiteralStringOrRecoverExpression(token.next); |
| + 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
|
| + token = parseCombinators(token); |
| + Token semicolon = token; |
| + token = expect(';', token); |
| + listener.endExport(exportKeyword, semicolon); |
| + return token; |
| + } |
| + |
| + Token parseCombinators(Token token) { |
| + listener.beginCombinators(token); |
| + int count = 0; |
| + while (true) { |
| + String value = token.stringValue; |
| + 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.
|
| + token = parseHide(token); |
| + } else if ('show' === value) { |
| + token = parseShow(token); |
| + } else { |
| + listener.endCombinators(count); |
| + return token; |
| + } |
| + count++; |
| + } |
| + } |
| + |
| + /// 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
|
| + Token parseHide(Token token) { |
| + Token hideKeyword = token; |
| + listener.beginHide(hideKeyword); |
| + assert(optional('hide', token)); |
| + token = parseIdentifierList(token.next); |
| + listener.endHide(hideKeyword); |
| + return token; |
| + } |
| + |
| + /// show identifierList |
| + Token parseShow(Token token) { |
| + Token showKeyword = token; |
| + listener.beginShow(showKeyword); |
| + assert(optional('show', token)); |
| + token = parseIdentifierList(token.next); |
| + listener.endShow(showKeyword); |
| + return token; |
| + } |
| + |
| + /// identifier (, identifier)* |
| + Token parseIdentifierList(Token token) { |
| + listener.beginIdentifierList(token); |
| + int count = 0; |
| + do { |
| + token = parseIdentifier(token); |
| + count++; |
| + } 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
|
| + listener.endIdentifierList(count); |
| + return token; |
| + } |
| + |
| Token parseMetadataStar(Token token) { |
| while (optional('@', token)) { |
| token = parseMetadata(token); |
| @@ -242,10 +344,17 @@ class Parser { |
| Token parseQualifiedRestOpt(Token token) { |
| if (optional('.', token)) { |
| - Token period = token; |
| - token = parseIdentifier(token.next); |
| - listener.handleQualified(period); |
| + return parseQualifiedRest(token); |
| + } else { |
| + return token; |
| } |
| + } |
| + |
| + Token parseQualifiedRest(Token token) { |
| + assert(optional('.', token)); |
| + Token period = token; |
| + token = parseIdentifier(token.next); |
| + listener.handleQualified(period); |
| return token; |
| } |