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 library fasta.parser.parser; | 5 library fasta.parser.parser; |
6 | 6 |
7 import '../fasta_codes.dart' show Code, Message, Template; | 7 import '../fasta_codes.dart' show Code, Message, Template; |
8 | 8 |
9 import '../fasta_codes.dart' as fasta; | 9 import '../fasta_codes.dart' as fasta; |
10 | 10 |
11 import '../scanner.dart' show ErrorToken, Token; | 11 import '../scanner.dart' show ErrorToken, Token; |
12 | 12 |
13 import '../scanner/recover.dart' show closeBraceFor, skipToEof; | 13 import '../scanner/recover.dart' show closeBraceFor, skipToEof; |
14 | 14 |
15 import '../../scanner/token.dart' | 15 import '../../scanner/token.dart' |
16 show | 16 show |
17 ASSIGNMENT_PRECEDENCE, | 17 ASSIGNMENT_PRECEDENCE, |
18 BeginToken, | 18 BeginToken, |
19 CASCADE_PRECEDENCE, | 19 CASCADE_PRECEDENCE, |
20 EQUALITY_PRECEDENCE, | 20 EQUALITY_PRECEDENCE, |
21 POSTFIX_PRECEDENCE, | 21 POSTFIX_PRECEDENCE, |
22 RELATIONAL_PRECEDENCE, | 22 RELATIONAL_PRECEDENCE, |
23 SyntheticStringToken, | |
24 SyntheticToken, | |
23 TokenType; | 25 TokenType; |
24 | 26 |
25 import '../scanner/token.dart' show isUserDefinableOperator; | 27 import '../scanner/token.dart' show isUserDefinableOperator; |
26 | 28 |
27 import '../scanner/token_constants.dart' | 29 import '../scanner/token_constants.dart' |
28 show | 30 show |
29 COMMA_TOKEN, | 31 COMMA_TOKEN, |
30 DOUBLE_TOKEN, | 32 DOUBLE_TOKEN, |
31 EOF_TOKEN, | 33 EOF_TOKEN, |
32 EQ_TOKEN, | 34 EQ_TOKEN, |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
349 } | 351 } |
350 listener.endDottedName(count, firstIdentifier); | 352 listener.endDottedName(count, firstIdentifier); |
351 return token; | 353 return token; |
352 } | 354 } |
353 | 355 |
354 /// export uri conditional-uris* combinator* ';' | 356 /// export uri conditional-uris* combinator* ';' |
355 Token parseExport(Token token) { | 357 Token parseExport(Token token) { |
356 Token exportKeyword = token; | 358 Token exportKeyword = token; |
357 listener.beginExport(exportKeyword); | 359 listener.beginExport(exportKeyword); |
358 assert(optional('export', token)); | 360 assert(optional('export', token)); |
359 token = parseLiteralStringOrRecoverExpression(token.next); | 361 token = ensureParseLiteralString(token.next); |
360 token = parseConditionalUris(token); | 362 token = parseConditionalUris(token); |
361 token = parseCombinators(token); | 363 token = parseCombinators(token); |
362 Token semicolon = token; | 364 Token semicolon = ensureSemicolon(token); |
363 token = expect(';', token); | |
364 listener.endExport(exportKeyword, semicolon); | 365 listener.endExport(exportKeyword, semicolon); |
365 return token; | 366 return semicolon.next; |
366 } | 367 } |
367 | 368 |
368 Token parseCombinators(Token token) { | 369 Token parseCombinators(Token token) { |
369 listener.beginCombinators(token); | 370 listener.beginCombinators(token); |
370 int count = 0; | 371 int count = 0; |
371 while (true) { | 372 while (true) { |
372 String value = token.stringValue; | 373 String value = token.stringValue; |
373 if (identical('hide', value)) { | 374 if (identical('hide', value)) { |
374 token = parseHide(token); | 375 token = parseHide(token); |
375 } else if (identical('show', value)) { | 376 } else if (identical('show', value)) { |
(...skipping 1539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1915 listener.beginInitializer(token); | 1916 listener.beginInitializer(token); |
1916 if (optional('assert', token)) { | 1917 if (optional('assert', token)) { |
1917 token = parseAssert(token, Assert.Initializer); | 1918 token = parseAssert(token, Assert.Initializer); |
1918 } else { | 1919 } else { |
1919 token = parseExpression(token); | 1920 token = parseExpression(token); |
1920 } | 1921 } |
1921 listener.endInitializer(token); | 1922 listener.endInitializer(token); |
1922 return token; | 1923 return token; |
1923 } | 1924 } |
1924 | 1925 |
1926 Token ensureParseLiteralString(Token token) { | |
1927 if (!identical(token.kind, STRING_TOKEN)) { | |
ahe
2017/08/21 12:51:37
Don't need to use identical on int.
danrubel
2017/08/21 14:51:02
Fair enough. I was just following what you already
| |
1928 reportRecoverableErrorWithToken(token, fasta.templateExpectedString); | |
1929 token = listener.rewriter.insertTokenBefore( | |
ahe
2017/08/21 12:51:37
Something is off here. If the parser does the rewr
danrubel
2017/08/21 14:51:02
Yeah. I had the parser holding onto the rewriter b
| |
1930 new SyntheticStringToken(TokenType.STRING, '""', token.charOffset, 0), | |
1931 token); | |
1932 } | |
1933 return parseLiteralString(token); | |
1934 } | |
1935 | |
1936 Token ensureSemicolon(Token token) { | |
1937 if (optional(';', token)) return token; | |
1938 reportRecoverableError( | |
1939 token, fasta.templateExpectedButGot.withArguments(';')); | |
1940 return listener.rewriter.insertTokenBefore( | |
1941 new SyntheticToken(TokenType.SEMICOLON, token.charOffset), token); | |
1942 } | |
1943 | |
1925 Token parseLiteralStringOrRecoverExpression(Token token) { | 1944 Token parseLiteralStringOrRecoverExpression(Token token) { |
1926 if (identical(token.kind, STRING_TOKEN)) { | 1945 if (identical(token.kind, STRING_TOKEN)) { |
1927 return parseLiteralString(token); | 1946 return parseLiteralString(token); |
1928 } else if (token is ErrorToken) { | 1947 } else if (token is ErrorToken) { |
1929 return reportErrorToken(token, false); | 1948 return reportErrorToken(token, false); |
1930 } else { | 1949 } else { |
1931 reportRecoverableErrorWithToken(token, fasta.templateExpectedString); | 1950 reportRecoverableErrorWithToken(token, fasta.templateExpectedString); |
1932 return parseRecoverExpression( | 1951 return parseRecoverExpression( |
1933 token, fasta.templateExpectedString.withArguments(token)); | 1952 token, fasta.templateExpectedString.withArguments(token)); |
1934 } | 1953 } |
(...skipping 2130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4065 } | 4084 } |
4066 | 4085 |
4067 Token reportUnexpectedToken(Token token) { | 4086 Token reportUnexpectedToken(Token token) { |
4068 return reportUnrecoverableErrorWithToken( | 4087 return reportUnrecoverableErrorWithToken( |
4069 token, fasta.templateUnexpectedToken); | 4088 token, fasta.templateUnexpectedToken); |
4070 } | 4089 } |
4071 } | 4090 } |
4072 | 4091 |
4073 // TODO(ahe): Remove when analyzer supports generalized function syntax. | 4092 // TODO(ahe): Remove when analyzer supports generalized function syntax. |
4074 typedef _MessageWithArgument<T> = Message Function(T); | 4093 typedef _MessageWithArgument<T> = Message Function(T); |
OLD | NEW |