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