OLD | NEW |
---|---|
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 analyzer.src.generated.parser; | 5 library analyzer.src.generated.parser; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 import "dart:math" as math; | 8 import "dart:math" as math; |
9 | 9 |
10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 0, (Parser target) => target.parseTypeArgumentList()), | 89 0, (Parser target) => target.parseTypeArgumentList()), |
90 'parseTypeName_0': | 90 'parseTypeName_0': |
91 new MethodTrampoline(0, (Parser target) => target.parseTypeName()), | 91 new MethodTrampoline(0, (Parser target) => target.parseTypeName()), |
92 'parseTypeParameter_0': | 92 'parseTypeParameter_0': |
93 new MethodTrampoline(0, (Parser target) => target.parseTypeParameter()), | 93 new MethodTrampoline(0, (Parser target) => target.parseTypeParameter()), |
94 'parseTypeParameterList_0': new MethodTrampoline( | 94 'parseTypeParameterList_0': new MethodTrampoline( |
95 0, (Parser target) => target.parseTypeParameterList()), | 95 0, (Parser target) => target.parseTypeParameterList()), |
96 'parseWithClause_0': | 96 'parseWithClause_0': |
97 new MethodTrampoline(0, (Parser target) => target.parseWithClause()), | 97 new MethodTrampoline(0, (Parser target) => target.parseWithClause()), |
98 'advance_0': new MethodTrampoline(0, (Parser target) => target._advance()), | 98 'advance_0': new MethodTrampoline(0, (Parser target) => target._advance()), |
99 'appendScalarValue_5': new MethodTrampoline( | 99 'appendCodePoint_5': new MethodTrampoline( |
100 5, | 100 5, |
101 (Parser target, arg0, arg1, arg2, arg3, arg4) => | 101 (Parser target, arg0, arg1, arg2, arg3, arg4) => |
102 target._appendScalarValue(arg0, arg1, arg2, arg3, arg4)), | 102 target._appendCodePoint(arg0, arg1, arg2, arg3, arg4)), |
103 'computeStringValue_3': new MethodTrampoline( | 103 'computeStringValue_3': new MethodTrampoline( |
104 3, | 104 3, |
105 (Parser target, arg0, arg1, arg2) => | 105 (Parser target, arg0, arg1, arg2) => |
106 target._computeStringValue(arg0, arg1, arg2)), | 106 target._computeStringValue(arg0, arg1, arg2)), |
107 'convertToFunctionDeclaration_1': new MethodTrampoline( | 107 'convertToFunctionDeclaration_1': new MethodTrampoline( |
108 1, (Parser target, arg0) => target._convertToFunctionDeclaration(arg0)), | 108 1, (Parser target, arg0) => target._convertToFunctionDeclaration(arg0)), |
109 'couldBeStartOfCompilationUnitMember_0': new MethodTrampoline( | 109 'couldBeStartOfCompilationUnitMember_0': new MethodTrampoline( |
110 0, (Parser target) => target._couldBeStartOfCompilationUnitMember()), | 110 0, (Parser target) => target._couldBeStartOfCompilationUnitMember()), |
111 'createSyntheticIdentifier_0': new MethodTrampoline( | 111 'createSyntheticIdentifier_0': new MethodTrampoline( |
112 0, (Parser target) => target._createSyntheticIdentifier()), | 112 0, (Parser target) => target._createSyntheticIdentifier()), |
(...skipping 1956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2069 } | 2069 } |
2070 | 2070 |
2071 /** | 2071 /** |
2072 * Advance to the next token in the token stream. | 2072 * Advance to the next token in the token stream. |
2073 */ | 2073 */ |
2074 void _advance() { | 2074 void _advance() { |
2075 _currentToken = _currentToken.next; | 2075 _currentToken = _currentToken.next; |
2076 } | 2076 } |
2077 | 2077 |
2078 /** | 2078 /** |
2079 * Append the character equivalent of the given [scalarValue] to the given | 2079 * Append the character equivalent of the given [codePoint] to the given |
2080 * [builder]. Use the [startIndex] and [endIndex] to report an error, and | 2080 * [builder]. Use the [startIndex] and [endIndex] to report an error, and |
2081 * don't append anything to the builder, if the scalar value is invalid. The | 2081 * don't append anything to the builder, if the code point is invalid. The |
2082 * [escapeSequence] is the escape sequence that was parsed to produce the | 2082 * [escapeSequence] is the escape sequence that was parsed to produce the |
2083 * scalar value (used for error reporting). | 2083 * code point (used for error reporting). |
2084 */ | 2084 */ |
2085 void _appendScalarValue(StringBuffer buffer, String escapeSequence, | 2085 void _appendCodePoint(StringBuffer buffer, String source, |
2086 int scalarValue, int startIndex, int endIndex) { | 2086 int codePoint, int startIndex, int endIndex) { |
2087 if (scalarValue < 0 || | 2087 if (codePoint < 0 || codePoint > Character.MAX_CODE_POINT) { |
2088 scalarValue > Character.MAX_CODE_POINT || | 2088 String escapeSequence = source.substring(startIndex, endIndex + 1); |
2089 (scalarValue >= 0xD800 && scalarValue <= 0xDFFF)) { | |
2090 _reportErrorForCurrentToken( | 2089 _reportErrorForCurrentToken( |
2091 ParserErrorCode.INVALID_CODE_POINT, [escapeSequence]); | 2090 ParserErrorCode.INVALID_CODE_POINT, [escapeSequence]); |
2092 return; | 2091 return; |
2093 } | 2092 } |
2094 if (scalarValue < Character.MAX_VALUE) { | 2093 if (codePoint < Character.MAX_VALUE) { |
2095 buffer.writeCharCode(scalarValue); | 2094 buffer.writeCharCode(codePoint); |
2096 } else { | 2095 } else { |
2097 buffer.write(Character.toChars(scalarValue)); | 2096 buffer.write(Character.toChars(codePoint)); |
2098 } | 2097 } |
2099 } | 2098 } |
2100 | 2099 |
2101 /** | 2100 /** |
2102 * Return the content of a string with the given literal representation. The | 2101 * Return the content of a string with the given literal representation. The |
2103 * [lexeme] is the literal representation of the string. The flag [isFirst] is | 2102 * [lexeme] is the literal representation of the string. The flag [isFirst] is |
2104 * `true` if this is the first token in a string literal. The flag [isLast] is | 2103 * `true` if this is the first token in a string literal. The flag [isLast] is |
2105 * `true` if this is the last token in a string literal. | 2104 * `true` if this is the last token in a string literal. |
2106 */ | 2105 */ |
2107 String _computeStringValue(String lexeme, bool isFirst, bool isLast) { | 2106 String _computeStringValue(String lexeme, bool isFirst, bool isLast) { |
(...skipping 5978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8086 // Illegal escape sequence: incomplete escape | 8085 // Illegal escape sequence: incomplete escape |
8087 _reportErrorForCurrentToken(ParserErrorCode.INVALID_UNICODE_ESCAPE); | 8086 _reportErrorForCurrentToken(ParserErrorCode.INVALID_UNICODE_ESCAPE); |
8088 return length; | 8087 return length; |
8089 } | 8088 } |
8090 currentChar = lexeme.codeUnitAt(currentIndex); | 8089 currentChar = lexeme.codeUnitAt(currentIndex); |
8091 } | 8090 } |
8092 if (digitCount < 1 || digitCount > 6) { | 8091 if (digitCount < 1 || digitCount > 6) { |
8093 // Illegal escape sequence: not enough or too many hex digits | 8092 // Illegal escape sequence: not enough or too many hex digits |
8094 _reportErrorForCurrentToken(ParserErrorCode.INVALID_UNICODE_ESCAPE); | 8093 _reportErrorForCurrentToken(ParserErrorCode.INVALID_UNICODE_ESCAPE); |
8095 } | 8094 } |
8096 _appendScalarValue(buffer, lexeme.substring(index, currentIndex + 1), | 8095 _appendCodePoint(buffer, lexeme, value, index, currentIndex); |
Lasse Reichstein Nielsen
2016/09/15 11:18:44
There was no need to create a new substring when y
floitsch
2016/09/15 15:09:19
Acknowledged.
| |
8097 value, index, currentIndex); | |
8098 return currentIndex + 1; | 8096 return currentIndex + 1; |
8099 } else { | 8097 } else { |
8100 if (currentIndex + 3 >= length) { | 8098 if (currentIndex + 3 >= length) { |
8101 // Illegal escape sequence: not enough hex digits | 8099 // Illegal escape sequence: not enough hex digits |
8102 _reportErrorForCurrentToken(ParserErrorCode.INVALID_UNICODE_ESCAPE); | 8100 _reportErrorForCurrentToken(ParserErrorCode.INVALID_UNICODE_ESCAPE); |
8103 return length; | 8101 return length; |
8104 } | 8102 } |
8105 int firstDigit = currentChar; | 8103 int firstDigit = currentChar; |
8106 int secondDigit = lexeme.codeUnitAt(currentIndex + 1); | 8104 int secondDigit = lexeme.codeUnitAt(currentIndex + 1); |
8107 int thirdDigit = lexeme.codeUnitAt(currentIndex + 2); | 8105 int thirdDigit = lexeme.codeUnitAt(currentIndex + 2); |
8108 int fourthDigit = lexeme.codeUnitAt(currentIndex + 3); | 8106 int fourthDigit = lexeme.codeUnitAt(currentIndex + 3); |
8109 if (!_isHexDigit(firstDigit) || | 8107 if (!_isHexDigit(firstDigit) || |
8110 !_isHexDigit(secondDigit) || | 8108 !_isHexDigit(secondDigit) || |
8111 !_isHexDigit(thirdDigit) || | 8109 !_isHexDigit(thirdDigit) || |
8112 !_isHexDigit(fourthDigit)) { | 8110 !_isHexDigit(fourthDigit)) { |
8113 // Illegal escape sequence: invalid hex digits | 8111 // Illegal escape sequence: invalid hex digits |
8114 _reportErrorForCurrentToken(ParserErrorCode.INVALID_UNICODE_ESCAPE); | 8112 _reportErrorForCurrentToken(ParserErrorCode.INVALID_UNICODE_ESCAPE); |
8115 } else { | 8113 } else { |
8116 _appendScalarValue( | 8114 _appendCodePoint( |
Lasse Reichstein Nielsen
2016/09/15 11:18:44
Retained the call to _appendCodePoint here, but it
floitsch
2016/09/15 15:09:19
Acknowledged.
| |
8117 buffer, | 8115 buffer, |
8118 lexeme.substring(index, currentIndex + 1), | 8116 lexeme, |
Lasse Reichstein Nielsen
2016/09/15 11:18:43
+1 here should have been +4.
| |
8119 (((((Character.digit(firstDigit, 16) << 4) + | 8117 (((((Character.digit(firstDigit, 16) << 4) + |
8120 Character.digit(secondDigit, 16)) << | 8118 Character.digit(secondDigit, 16)) << |
8121 4) + | 8119 4) + |
8122 Character.digit(thirdDigit, 16)) << | 8120 Character.digit(thirdDigit, 16)) << |
8123 4) + | 8121 4) + |
8124 Character.digit(fourthDigit, 16), | 8122 Character.digit(fourthDigit, 16), |
8125 index, | 8123 index, |
8126 currentIndex + 3); | 8124 currentIndex + 3); |
8127 } | 8125 } |
8128 return currentIndex + 4; | 8126 return currentIndex + 4; |
(...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9082 */ | 9080 */ |
9083 const ParserErrorCode(String name, String message, [String correction]) | 9081 const ParserErrorCode(String name, String message, [String correction]) |
9084 : super(name, message, correction); | 9082 : super(name, message, correction); |
9085 | 9083 |
9086 @override | 9084 @override |
9087 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; | 9085 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; |
9088 | 9086 |
9089 @override | 9087 @override |
9090 ErrorType get type => ErrorType.SYNTACTIC_ERROR; | 9088 ErrorType get type => ErrorType.SYNTACTIC_ERROR; |
9091 } | 9089 } |
OLD | NEW |