View | Details | Raw Unified | Return to bug 326346
Collapse All | Expand All

(-)src/org/eclipse/wst/jsdt/internal/codeassist/complete/CompletionScanner.java (-2 / +1 lines)
Lines 490-497 Link Here
490
									this.currentCharacter = this.source[this.currentPosition++];
490
									this.currentCharacter = this.source[this.currentPosition++];
491
								}
491
								}
492
								// we need to compute the escape character in a separate buffer
492
								// we need to compute the escape character in a separate buffer
493
								scanEscapeCharacter();
493
								if (scanEscapeCharacter() && this.withoutUnicodePtr != 0) {
494
								if (this.withoutUnicodePtr != 0) {
495
									unicodeStore();
494
									unicodeStore();
496
								}
495
								}
497
							}
496
							}
(-)src/org/eclipse/wst/jsdt/internal/compiler/parser/Scanner.java (-5 / +18 lines)
Lines 1490-1497 Link Here
1490
									this.currentCharacter = this.source[this.currentPosition++];
1490
									this.currentCharacter = this.source[this.currentPosition++];
1491
								}
1491
								}
1492
								// we need to compute the escape character in a separate buffer
1492
								// we need to compute the escape character in a separate buffer
1493
								scanEscapeCharacter();
1493
								if (scanEscapeCharacter() && this.withoutUnicodePtr != 0) {
1494
								if (this.withoutUnicodePtr != 0) {
1495
									unicodeStore();
1494
									unicodeStore();
1496
								}
1495
								}
1497
							}
1496
							}
Lines 2723-2729 Link Here
2723
	this.currentNonWhitespaceToken=currentNonWSToken;
2722
	this.currentNonWhitespaceToken=currentNonWSToken;
2724
}
2723
}
2725
2724
2726
public final void scanEscapeCharacter() throws InvalidInputException {
2725
	
2726
2727
/**	
2728
 * Processes an escaped character sequence on the current source position.
2729
 * @return Whether a character was produced. Thus, false in case of a string line continuation.
2730
 * @throws InvalidInputException
2731
 */
2732
public final boolean scanEscapeCharacter() throws InvalidInputException {
2727
	// the string with "\\u" is a legal string of two chars \ and u
2733
	// the string with "\\u" is a legal string of two chars \ and u
2728
	//thus we use a direct access to the source (for regular cases).
2734
	//thus we use a direct access to the source (for regular cases).
2729
	switch (this.currentCharacter) {
2735
	switch (this.currentCharacter) {
Lines 2751-2756 Link Here
2751
		case '\\' :
2757
		case '\\' :
2752
			this.currentCharacter = '\\';
2758
			this.currentCharacter = '\\';
2753
			break;
2759
			break;
2760
		case '\r':
2761
			if (this.source[this.currentPosition] == '\n')
2762
				this.currentPosition++;
2763
		case '\n':
2764
		case '\u2029':
2765
		case '\u2028':
2766
			return false;
2754
		case 'x' :
2767
		case 'x' :
2755
			int digit1 = ScannerHelper.digit(this.source[this.currentPosition], 16);
2768
			int digit1 = ScannerHelper.digit(this.source[this.currentPosition], 16);
2756
			int digit2 = ScannerHelper.digit(this.source[this.currentPosition + 1], 16);
2769
			int digit2 = ScannerHelper.digit(this.source[this.currentPosition + 1], 16);
Lines 2801-2806 Link Here
2801
			// in JavaScript when a backslash followed by character, the
2814
			// in JavaScript when a backslash followed by character, the
2802
			// backslash is ignored.
2815
			// backslash is ignored.
2803
	}
2816
	}
2817
	return true;
2804
}
2818
}
2805
2819
2806
public int scanIdentifierOrKeywordWithBoundCheck() {
2820
public int scanIdentifierOrKeywordWithBoundCheck() {
Lines 4375-4382 Link Here
4375
					this.currentCharacter = this.source[this.currentPosition++];
4389
					this.currentCharacter = this.source[this.currentPosition++];
4376
				}
4390
				}
4377
				// we need to compute the escape character in a separate buffer
4391
				// we need to compute the escape character in a separate buffer
4378
				scanEscapeCharacter();
4392
				if (scanEscapeCharacter() && this.withoutUnicodePtr != 0) {
4379
				if (this.withoutUnicodePtr != 0) {
4380
					unicodeStore();
4393
					unicodeStore();
4381
				}
4394
				}
4382
			}
4395
			}
(-)src/org/eclipse/wst/jsdt/internal/compiler/problem/messages.properties (-1 / +1 lines)
Lines 200-206 Link Here
200
256 = Invalid unicode
200
256 = Invalid unicode
201
257 = Invalid float literal number
201
257 = Invalid float literal number
202
258 = Null source string
202
258 = Null source string
203
259 = String literal is not properly closed by a double-quote
203
259 = String literal is not properly closed by a matching quote
204
260 = Unexpected end of comment
204
260 = Unexpected end of comment
205
261 = Non-externalized string literal; it should be followed by //$NON-NLS-<n>$
205
261 = Non-externalized string literal; it should be followed by //$NON-NLS-<n>$
206
262 = Invalid digit (valid ones are 0..9)
206
262 = Invalid digit (valid ones are 0..9)
(-)src/org/eclipse/wst/jsdt/internal/core/util/PublicScanner.java (-5 / +16 lines)
Lines 1376-1383 Link Here
1376
									this.currentCharacter = this.source[this.currentPosition++];
1376
									this.currentCharacter = this.source[this.currentPosition++];
1377
								}
1377
								}
1378
								// we need to compute the escape character in a separate buffer
1378
								// we need to compute the escape character in a separate buffer
1379
								scanEscapeCharacter();
1379
								if (scanEscapeCharacter() && this.withoutUnicodePtr != 0) {
1380
								if (this.withoutUnicodePtr != 0) {
1381
									unicodeStore();
1380
									unicodeStore();
1382
								}
1381
								}
1383
							}
1382
							}
Lines 2517-2523 Link Here
2517
	this.foundTaskCount = 0;
2516
	this.foundTaskCount = 0;
2518
}
2517
}
2519
2518
2520
public final void scanEscapeCharacter() throws InvalidInputException {
2519
/**
2520
 * Processes an escaped character sequence on the current source position.
2521
 * @return Whether a character was produced. Thus, false in case of a string line continuation.
2522
 * @throws InvalidInputException
2523
 */
2524
public final boolean scanEscapeCharacter() throws InvalidInputException {
2521
	// the string with "\\u" is a legal string of two chars \ and u
2525
	// the string with "\\u" is a legal string of two chars \ and u
2522
	//thus we use a direct access to the source (for regular cases).
2526
	//thus we use a direct access to the source (for regular cases).
2523
	switch (this.currentCharacter) {
2527
	switch (this.currentCharacter) {
Lines 2545-2550 Link Here
2545
		case '\\' :
2549
		case '\\' :
2546
			this.currentCharacter = '\\';
2550
			this.currentCharacter = '\\';
2547
			break;
2551
			break;
2552
		case '\r':
2553
			if (this.source[this.currentPosition] == '\n')
2554
				this.currentPosition++;
2555
		case '\n':
2556
		case '\u2029':
2557
		case '\u2028':
2558
			return false;
2548
		case 'x' :
2559
		case 'x' :
2549
			int digit1 = ScannerHelper.digit(this.source[this.currentPosition], 16);
2560
			int digit1 = ScannerHelper.digit(this.source[this.currentPosition], 16);
2550
			int digit2 = ScannerHelper.digit(this.source[this.currentPosition + 1], 16);
2561
			int digit2 = ScannerHelper.digit(this.source[this.currentPosition + 1], 16);
Lines 2598-2603 Link Here
2598
//			else
2609
//			else
2599
//				throw new InvalidInputException(INVALID_ESCAPE);
2610
//				throw new InvalidInputException(INVALID_ESCAPE);
2600
	}
2611
	}
2612
	return true;
2601
}
2613
}
2602
public int scanIdentifierOrKeywordWithBoundCheck() {
2614
public int scanIdentifierOrKeywordWithBoundCheck() {
2603
	//test keywords
2615
	//test keywords
Lines 4151-4158 Link Here
4151
					this.currentCharacter = this.source[this.currentPosition++];
4163
					this.currentCharacter = this.source[this.currentPosition++];
4152
				}
4164
				}
4153
				// we need to compute the escape character in a separate buffer
4165
				// we need to compute the escape character in a separate buffer
4154
				scanEscapeCharacter();
4166
				if (scanEscapeCharacter() && this.withoutUnicodePtr != 0) {
4155
				if (this.withoutUnicodePtr != 0) {
4156
					unicodeStore();
4167
					unicodeStore();
4157
				}
4168
				}
4158
			}
4169
			}
(-)src/org/eclipse/wst/jsdt/core/tests/compiler/parser/SyntaxErrorTest.java (+135 lines)
Lines 189-192 Link Here
189
		expectedSyntaxErrorDiagnosis,
189
		expectedSyntaxErrorDiagnosis,
190
		testName);
190
		testName);
191
}
191
}
192
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=241647
193
public void test05a() {
194
	String s = 
195
		"var foo = \"1\\\n"+
196
		"2\";"+
197
		"\n"; 
198
199
	String expectedSyntaxErrorDiagnosis =
200
		"";
201
202
	String testName = "<test>";
203
	checkParse(
204
		s.toCharArray(),
205
		expectedSyntaxErrorDiagnosis,
206
		testName);
207
}
208
public void test05b() {
209
	String s = 
210
		"var foo = '111\\\n"+
211
		"222';"+
212
		"	\n"; 
213
214
	String expectedSyntaxErrorDiagnosis =
215
		"";
216
217
	String testName = "<test>";
218
	checkParse(
219
		s.toCharArray(),
220
		expectedSyntaxErrorDiagnosis,
221
		testName);
222
}
223
public void test05c() {
224
	String s = 
225
		"var foo = \"  \\\r\n"+
226
		"    \";"+
227
		"	\r\n"; 
228
229
	String expectedSyntaxErrorDiagnosis =
230
		"";
231
232
	String testName = "<test>";
233
	checkParse(
234
		s.toCharArray(),
235
		expectedSyntaxErrorDiagnosis,
236
		testName);
237
}
238
public void test05d() {
239
	String s = 
240
		"var foo = '  \\\r\n"+
241
		"    ';"+
242
		"	\r\n"; 
243
244
	String expectedSyntaxErrorDiagnosis =
245
		"";
246
247
	String testName = "<test>";
248
	checkParse(
249
		s.toCharArray(),
250
		expectedSyntaxErrorDiagnosis,
251
		testName);
252
}
253
public void test05e() {
254
	String s = 
255
		"var foo = \"  \\\r"+
256
		"    \";"+
257
		"	\r"; 	
258
259
	String expectedSyntaxErrorDiagnosis =
260
		"";
261
262
	String testName = "<test>";
263
	checkParse(
264
		s.toCharArray(),
265
		expectedSyntaxErrorDiagnosis,
266
		testName);
267
}
268
public void test05f() {
269
	String s = 
270
		"var foo = '  \\\r"+
271
		"    ';"+
272
		"	\r"; 	
273
274
	String expectedSyntaxErrorDiagnosis =
275
		"";
276
277
	String testName = "<test>";
278
	checkParse(
279
		s.toCharArray(),
280
		expectedSyntaxErrorDiagnosis,
281
		testName);
282
}
283
public void test05g() {
284
	String s = 
285
		"var foo = '  \\\r"+
286
		"\r"+
287
		"    ';"+
288
		"	\r"; 	
289
290
	String expectedSyntaxErrorDiagnosis =
291
		"----------\n"+
292
		"1. ERROR in <test> (at line 1)\n"+
293
		"	var foo = '  \\\n"+
294
		"\n"+
295
		"	          ^^^^^\n"+
296
		"String literal is not properly closed by a matching quote\n"+
297
		"----------\n";
298
299
	String testName = "<test>";
300
	checkParse(
301
		s.toCharArray(),
302
		expectedSyntaxErrorDiagnosis,
303
		testName);
304
}
305
public void test05h() {
306
	String s = 
307
		"var foo = \"  \\\r"+
308
		"\r"+
309
		"    \";"+
310
		"	\r"; 	
311
312
	String expectedSyntaxErrorDiagnosis =
313
		"----------\n"+
314
		"1. ERROR in <test> (at line 1)\n"+
315
		"	var foo = \"  \\\n"+
316
		"\n"+
317
		"	          ^^^^^\n"+
318
		"String literal is not properly closed by a matching quote\n"+
319
		"----------\n";
320
321
	String testName = "<test>";
322
	checkParse(
323
		s.toCharArray(),
324
		expectedSyntaxErrorDiagnosis,
325
		testName);
326
}
192
}
327
}
(-)src/org/eclipse/wst/jsdt/internal/ui/text/FastJavaPartitionScanner.java (-2 / +14 lines)
Lines 41-46 Link Here
41
	private static final int STAR= 5; // postfix for MULTI_LINE_COMMENT or JSDOC
41
	private static final int STAR= 5; // postfix for MULTI_LINE_COMMENT or JSDOC
42
	private static final int CARRIAGE_RETURN=6; // postfix for STRING, CHARACTER and SINGLE_LINE_COMMENT
42
	private static final int CARRIAGE_RETURN=6; // postfix for STRING, CHARACTER and SINGLE_LINE_COMMENT
43
	private static final int REGULAR_EXPRESSION_END=7;
43
	private static final int REGULAR_EXPRESSION_END=7;
44
	private static final int BACKSLASH_CARRIAGE_RETURN = 8; // anti-postfix for STRING, CHARACTER
44
45
45
	/** The scanner. */
46
	/** The scanner. */
46
	private final BufferedDocumentScanner fScanner= new BufferedDocumentScanner(1000);	// faster implementation
47
	private final BufferedDocumentScanner fScanner= new BufferedDocumentScanner(1000);	// faster implementation
Lines 102-107 Link Here
102
		 		}
103
		 		}
103
104
104
	 		case '\r':
105
	 		case '\r':
106
	 			if ((fState == STRING || fState == CHARACTER) && fLast == BACKSLASH) {
107
	 				fLast = BACKSLASH_CARRIAGE_RETURN;
108
	 				fTokenLength++;
109
	 				continue;
110
	 			}
105
	 			if (fLast != CARRIAGE_RETURN) {
111
	 			if (fLast != CARRIAGE_RETURN) {
106
						fLast= CARRIAGE_RETURN;
112
						fLast= CARRIAGE_RETURN;
107
						fTokenLength++;
113
						fTokenLength++;
Lines 134-144 Link Here
134
	 			}
140
	 			}
135
141
136
	 		case '\n':
142
	 		case '\n':
143
	 		case '\u2028':
144
	 		case '\u2029':
137
				switch (fState) {
145
				switch (fState) {
138
				case SINGLE_LINE_COMMENT:
146
				case STRING:
139
				case CHARACTER:
147
				case CHARACTER:
148
					if(fLast == BACKSLASH || fLast == BACKSLASH_CARRIAGE_RETURN) {
149
						consume();
150
						continue;
151
					}
152
				case SINGLE_LINE_COMMENT:
140
				case REGULAR_EXPRESSION:
153
				case REGULAR_EXPRESSION:
141
				case STRING:
142
					return postFix(fState);
154
					return postFix(fState);
143
155
144
				default:
156
				default:

Return to bug 326346