mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
Changed the tokenizer so it is bug-for-bug compatible with the CPython tokenizer in versions 3.10 and newer in the case where a backslash (continuation character) is located by itself on a line. This addresses #7799.
This commit is contained in:
parent
1aed0e3261
commit
fcf5b372be
@ -494,13 +494,25 @@ export class Tokenizer {
|
||||
} else {
|
||||
this._cs.advance(2);
|
||||
}
|
||||
|
||||
this._addLineRange();
|
||||
return true;
|
||||
} else if (this._cs.nextChar === Char.LineFeed) {
|
||||
this._cs.advance(2);
|
||||
this._addLineRange();
|
||||
|
||||
if (this._tokens.length > 0 && this._tokens[this._tokens.length - 1].type === TokenType.NewLine) {
|
||||
this._readIndentationAfterNewLine();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this._cs.nextChar === Char.LineFeed) {
|
||||
this._cs.advance(2);
|
||||
this._addLineRange();
|
||||
|
||||
if (this._tokens.length > 0 && this._tokens[this._tokens.length - 1].type === TokenType.NewLine) {
|
||||
this._readIndentationAfterNewLine();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return this._handleInvalid();
|
||||
}
|
||||
|
||||
|
@ -25,14 +25,20 @@ test('Empty', () => {
|
||||
assert.equal(parserOutput.parseTree.statements.length, 0);
|
||||
});
|
||||
|
||||
test('Sample1', () => {
|
||||
test('Parser1', () => {
|
||||
const diagSink = new DiagnosticSink();
|
||||
const parserOutput = TestUtils.parseSampleFile('sample1.py', diagSink).parserOutput;
|
||||
const parserOutput = TestUtils.parseSampleFile('parser1.py', diagSink).parserOutput;
|
||||
|
||||
assert.equal(diagSink.fetchAndClear().length, 0);
|
||||
assert.equal(parserOutput.parseTree.statements.length, 4);
|
||||
});
|
||||
|
||||
test('Parser2', () => {
|
||||
const diagSink = new DiagnosticSink();
|
||||
TestUtils.parseSampleFile('parser2.py', diagSink);
|
||||
assert.strictEqual(diagSink.getErrors().length, 0);
|
||||
});
|
||||
|
||||
test('FStringEmptyTuple', () => {
|
||||
assert.doesNotThrow(() => {
|
||||
const diagSink = new DiagnosticSink();
|
||||
|
11
packages/pyright-internal/src/tests/samples/parser2.py
Normal file
11
packages/pyright-internal/src/tests/samples/parser2.py
Normal file
@ -0,0 +1,11 @@
|
||||
class A:
|
||||
\
|
||||
pass
|
||||
|
||||
class B:
|
||||
\
|
||||
pass
|
||||
|
||||
class C:
|
||||
\
|
||||
pass
|
Loading…
Reference in New Issue
Block a user