Skip to content

Commit

Permalink
Cleanups made while backporting to Java
Browse files Browse the repository at this point in the history
  • Loading branch information
dberlin committed Apr 6, 2019
1 parent 6e5215f commit f11396a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
5 changes: 2 additions & 3 deletions src/IncrementalParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { ParseTreeListener } from "./tree/ParseTreeListener";
export abstract class IncrementalParser extends Parser
implements ParseTreeListener {
// Current parser epoch. Incremented every time a new incremental parser is created.
public static _PARSER_EPOCH: number = 0;
private static _PARSER_EPOCH: number = 0;
public static get PARSER_EPOCH() {
return this._PARSER_EPOCH;
}
Expand Down Expand Up @@ -61,8 +61,7 @@ export abstract class IncrementalParser extends Parser
// Pop the min max stack the stream is using and return the interval.
private popCurrentMinMax(ctx: IncrementalParserRuleContext) {
let incStream = this.inputStream as IncrementalTokenStream;
let interval = incStream.popMinMax();
return interval;
return incStream.popMinMax();
}

/**
Expand Down
19 changes: 6 additions & 13 deletions src/IncrementalParserData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,6 @@ export interface TokenChange {
newToken?: CommonToken;
}

// Unfortunately we have to make this public in order to be able to use it
// from IncrementalParserData properly.
// We do this in a type safe way however.
class SyncableTokenStream extends IncrementalTokenStream {
public sync(i: number): boolean {
return super.sync(i);
}
}
/**
*
* This class computes and stores data needed by the incremental parser.
Expand Down Expand Up @@ -270,9 +262,9 @@ export class IncrementalParserData {
depth: number,
state: number,
rule: number,
tokenindex: number,
tokenIndex: number,
) {
return `${depth},${rule},${tokenindex}`;
return `${depth},${rule},${tokenIndex}`;
}
/**
* Index a given parse tree and adjust the min/max ranges
Expand All @@ -283,6 +275,7 @@ export class IncrementalParserData {
// could walk the old parse tree as the parse proceeds. This is left as
// a future optimization. We also could just allow passing in
// constructed maps if this turns out to be slow.
this.tokenStream.fill();
let listener = new IncrementalParserData.ParseTreeProcessor(this);
ParseTreeWalker.DEFAULT.walk(listener, tree);
}
Expand All @@ -296,12 +289,12 @@ export class IncrementalParserData {
*/
class ParseTreeProcessor implements ParseTreeListener {
private incrementalData: IncrementalParserData;
private tokenStream: SyncableTokenStream;
private tokenStream: IncrementalTokenStream;
private tokenOffsets: TokenOffsetRange[];
private ruleStartMap: Map<string, IncrementalParserRuleContext>;
constructor(incrementalData: IncrementalParserData) {
this.incrementalData = incrementalData;
this.tokenStream = incrementalData.tokenStream as SyncableTokenStream;
this.tokenStream = incrementalData.tokenStream;
this.tokenOffsets = incrementalData.tokenOffsets;
this.ruleStartMap = incrementalData.ruleStartMap;
}
Expand All @@ -319,7 +312,7 @@ export class IncrementalParserData {
);
if (newTokenIndex !== undefined) {
let syncableStream = this.tokenStream;
syncableStream.sync(newTokenIndex);
// We filled the stream before the walk
return syncableStream.get(newTokenIndex);
}
return undefined;
Expand Down

0 comments on commit f11396a

Please sign in to comment.