From 12e90a09efd231654692697d2fb6b555296387d0 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Dec 2014 08:33:10 -0800 Subject: [PATCH] Simplify parser API. --- src/services/syntax/incrementalParser.ts | 8 -------- src/services/syntax/parser.ts | 20 ++++---------------- src/services/syntax/scanner.ts | 12 ------------ 3 files changed, 4 insertions(+), 36 deletions(-) diff --git a/src/services/syntax/incrementalParser.ts b/src/services/syntax/incrementalParser.ts index 5556dfc10da..4ecd75b0001 100644 --- a/src/services/syntax/incrementalParser.ts +++ b/src/services/syntax/incrementalParser.ts @@ -72,13 +72,6 @@ module TypeScript.IncrementalParser { updateTokenPositionsAndMarkElements(oldSourceUnit, _changeRange.span().start(), _changeRange.span().end(), delta, /*fullStart:*/ 0); - function release() { - _scannerParserSource.release(); - _scannerParserSource = undefined; - _oldSourceUnitCursor = undefined; - _isSpeculativelyParsing = false; - } - function extendToAffectedRange(changeRange: TextChangeRange, sourceUnit: SourceUnitSyntax): TextChangeRange { // Consider the following code: // void foo() { /; } @@ -382,7 +375,6 @@ module TypeScript.IncrementalParser { consumeNodeOrToken: consumeNodeOrToken, tryParse: tryParse, tokenDiagnostics: tokenDiagnostics, - release: release }; } diff --git a/src/services/syntax/parser.ts b/src/services/syntax/parser.ts index 74ffa81f39c..ecb3c9a5233 100644 --- a/src/services/syntax/parser.ts +++ b/src/services/syntax/parser.ts @@ -77,26 +77,19 @@ module TypeScript.Parser { // Retrieves the diagnostics generated while the source was producing nodes or tokens. // Should generally only be called after the document has been completely parsed. tokenDiagnostics(): Diagnostic[]; - - release(): void; } // Contains the actual logic to parse typescript/javascript. This is the code that generally // represents the logic necessary to handle all the language grammar constructs. When the // language changes, this should generally only be the place necessary to fix up. function createParseSyntaxTree(): (source: IParserSource, isDeclaration: boolean) => SyntaxTree { - // Name of the file we're parsing. - var fileName: string; - // Underlying source where we pull nodes and tokens from. var source: IParserSource; - var languageVersion: ts.ScriptTarget; - // TODO: do we need to store/restore this when speculative parsing? I don't think so. The // parsing logic already handles storing/restoring this and should work properly even if we're // speculative parsing. - var listParsingState: number = 0; + var listParsingState: ListParsingState = 0; // Whether or not we are in strict parsing mode. All that changes in strict parsing mode is // that some tokens that would be considered identifiers may be considered keywords. When @@ -280,9 +273,7 @@ module TypeScript.Parser { function parseSyntaxTree(_source: IParserSource, isDeclaration: boolean): SyntaxTree { // First, set up our state. - fileName = _source.fileName; source = _source; - languageVersion = source.languageVersion; // Now actually parse the tree. var result = parseSyntaxTreeWorker(isDeclaration); @@ -290,10 +281,7 @@ module TypeScript.Parser { // Now, clear out our state so that our singleton parser doesn't keep things alive. diagnostics = []; contextFlags = 0; - fileName = undefined; - source.release(); source = undefined; - _source = undefined; return result; } @@ -304,7 +292,7 @@ module TypeScript.Parser { var allDiagnostics = source.tokenDiagnostics().concat(diagnostics); allDiagnostics.sort((a: Diagnostic, b: Diagnostic) => a.start() - b.start()); - return new SyntaxTree(sourceUnit, isDeclaration, allDiagnostics, fileName, source.text, languageVersion); + return new SyntaxTree(sourceUnit, isDeclaration, allDiagnostics, source.fileName, source.text, source.languageVersion); } function tryParse(callback: () => T): T { @@ -647,7 +635,7 @@ module TypeScript.Parser { } } - return new Diagnostic(fileName, source.text.lineMap(), start(token, source.text), width(token), diagnosticCode, args); + return new Diagnostic(source.fileName, source.text.lineMap(), start(token, source.text), width(token), diagnosticCode, args); } function getBinaryExpressionPrecedence(tokenKind: SyntaxKind): BinaryExpressionPrecedence { @@ -4397,7 +4385,7 @@ module TypeScript.Parser { function reportUnexpectedTokenDiagnostic(listType: ListParsingState): void { var token = currentToken(); - var diagnostic = new Diagnostic(fileName, source.text.lineMap(), + var diagnostic = new Diagnostic(source.fileName, source.text.lineMap(), start(token, source.text), width(token), DiagnosticCode.Unexpected_token_0_expected, [getExpectedListElementType(listType)]); addDiagnostic(diagnostic); } diff --git a/src/services/syntax/scanner.ts b/src/services/syntax/scanner.ts index c20f1dca779..ff19831e891 100644 --- a/src/services/syntax/scanner.ts +++ b/src/services/syntax/scanner.ts @@ -1456,14 +1456,6 @@ module TypeScript.Scanner { // The scanner we're pulling tokens from. var scanner = createScanner(languageVersion, text, reportDiagnostic); - function release() { - slidingWindow = undefined; - scanner = undefined; - _tokenDiagnostics = []; - lastDiagnostic = undefined; - reportDiagnostic = undefined; - } - function currentNode(): ISyntaxNode { // The normal parser source never returns nodes. They're only returned by the // incremental parser source. @@ -1605,12 +1597,8 @@ module TypeScript.Scanner { currentContextualToken: currentContextualToken, peekToken: peekToken, consumeNodeOrToken: consumeNodeOrToken, - //getRewindPoint: getRewindPoint, - //rewind: rewind, - //releaseRewindPoint: releaseRewindPoint, tryParse: tryParse, tokenDiagnostics: tokenDiagnostics, - release: release, absolutePosition: absolutePosition, }; }