diff --git a/src/BufferedTokenStream.ts b/src/BufferedTokenStream.ts index 3f1ef2d4..f74011be 100644 --- a/src/BufferedTokenStream.ts +++ b/src/BufferedTokenStream.ts @@ -33,7 +33,7 @@ export class BufferedTokenStream implements TokenStream { * The {@link TokenSource} from which tokens for this stream are fetched. */ @NotNull - protected tokenSource: TokenSource; + private _tokenSource: TokenSource; /** * A collection of all tokens fetched from the token source. The list is @@ -75,11 +75,11 @@ export class BufferedTokenStream implements TokenStream { throw new Error("tokenSource cannot be null"); } - this.tokenSource = tokenSource; + this._tokenSource = tokenSource; } @Override - getTokenSource(): TokenSource { + get tokenSource(): TokenSource { return this.tokenSource; } @@ -295,8 +295,8 @@ export class BufferedTokenStream implements TokenStream { } /** Reset this token stream by setting its token source. */ - setTokenSource(tokenSource: TokenSource): void { - this.tokenSource = tokenSource; + set tokenSource(tokenSource: TokenSource) { + this._tokenSource = tokenSource; this.tokens.length = 0; this.p = -1; } diff --git a/src/CommonToken.ts b/src/CommonToken.ts index 8d033c98..28450519 100644 --- a/src/CommonToken.ts +++ b/src/CommonToken.ts @@ -114,7 +114,7 @@ export class CommonToken implements WritableToken { result.source = oldToken.source; } else { result.text = oldToken.getText(); - result.source = { source: oldToken.getTokenSource(), stream: oldToken.getInputStream() }; + result.source = { source: oldToken.tokenSource, stream: oldToken.getInputStream() }; } return result; @@ -222,7 +222,7 @@ export class CommonToken implements WritableToken { } @Override - getTokenSource(): TokenSource | undefined { + get tokenSource(): TokenSource | undefined { return this.source.source; } diff --git a/src/DefaultErrorStrategy.ts b/src/DefaultErrorStrategy.ts index 93e32887..925e6adf 100644 --- a/src/DefaultErrorStrategy.ts +++ b/src/DefaultErrorStrategy.ts @@ -583,7 +583,7 @@ export class DefaultErrorStrategy implements ANTLRErrorStrategy { current = lookback; } - return this.constructToken(recognizer.getInputStream().getTokenSource(), expectedTokenType, tokenText, current); + return this.constructToken(recognizer.getInputStream().tokenSource, expectedTokenType, tokenText, current); } protected constructToken( @@ -592,7 +592,7 @@ export class DefaultErrorStrategy implements ANTLRErrorStrategy { tokenText: string, current: Token): Token { let factory: TokenFactory = tokenSource.getTokenFactory(); - let x = current.getTokenSource(); + let x = current.tokenSource; let stream = x ? x.getInputStream() : undefined; return factory.create( diff --git a/src/Parser.ts b/src/Parser.ts index 9d29f104..f206585f 100644 --- a/src/Parser.ts +++ b/src/Parser.ts @@ -386,7 +386,7 @@ export abstract class Parser extends Recognizer { } getTokenFactory(): TokenFactory { - return this._input.getTokenSource().getTokenFactory(); + return this._input.tokenSource.getTokenFactory(); } /** @@ -436,7 +436,7 @@ export abstract class Parser extends Recognizer { compileParseTreePattern(pattern: string, patternRuleIndex: number, lexer?: Lexer): ParseTreePattern { if (!lexer) { if (this.getInputStream()) { - let tokenSource = this.getInputStream().getTokenSource(); + let tokenSource = this.getInputStream().tokenSource; if (tokenSource instanceof Lexer) { lexer = tokenSource; } diff --git a/src/ParserInterpreter.ts b/src/ParserInterpreter.ts index a08909a3..6aff13ed 100644 --- a/src/ParserInterpreter.ts +++ b/src/ParserInterpreter.ts @@ -419,7 +419,7 @@ export class ParserInterpreter extends Parser { throw new Error("Expected exception to have an offending token"); } - let source = tok.getTokenSource(); + let source = tok.tokenSource; let stream = source !== undefined ? source.getInputStream() : undefined; let sourcePair = { source: source, stream: stream }; @@ -439,7 +439,7 @@ export class ParserInterpreter extends Parser { this._ctx.addErrorNode(errToken); } else { // NoViableAlt - let source = tok.getTokenSource(); + let source = tok.tokenSource; let errToken: Token = this.getTokenFactory().create(sourcePair, Token.INVALID_TYPE, tok.getText(), diff --git a/src/Token.ts b/src/Token.ts index c6003b95..dd95aa9f 100644 --- a/src/Token.ts +++ b/src/Token.ts @@ -60,7 +60,7 @@ export interface Token { /** Gets the {@link TokenSource} which created this token. */ - getTokenSource(): TokenSource | undefined; + readonly tokenSource: TokenSource | undefined; /** * Gets the {@link CharStream} from which this token was derived. diff --git a/src/TokenStream.ts b/src/TokenStream.ts index b704707f..dd7de6ca 100644 --- a/src/TokenStream.ts +++ b/src/TokenStream.ts @@ -65,7 +65,7 @@ export interface TokenStream extends IntStream { * stream. */ //@NotNull - getTokenSource(): TokenSource; + readonly tokenSource: TokenSource; /** * Return the text of all tokens within the specified {@code interval}. This diff --git a/src/UnbufferedTokenStream.tssoon b/src/UnbufferedTokenStream.tssoon index f2287f93..6a1e5654 100644 --- a/src/UnbufferedTokenStream.tssoon +++ b/src/UnbufferedTokenStream.tssoon @@ -6,7 +6,7 @@ // ConvertTo-TS run at 2016-10-04T11:26:58.9673509-07:00 export class UnbufferedTokenStream implements TokenStream { - protected tokenSource: TokenSource; + private _tokenSource: TokenSource; /** * A moving window buffer of the data being scanned. While there's a marker, @@ -64,7 +64,7 @@ export class UnbufferedTokenStream implements TokenStream { } constructor1(tokenSource: TokenSource, bufferSize: number) { - this.tokenSource = tokenSource; + this._tokenSource = tokenSource; this.tokens = new Token[bufferSize]; n = 0; fill(1); // prime the pump @@ -106,8 +106,8 @@ export class UnbufferedTokenStream implements TokenStream { } @Override - getTokenSource(): TokenSource { - return tokenSource; + get tokenSource(): TokenSource { + return this._tokenSource; } @NotNull diff --git a/src/tree/pattern/RuleTagToken.ts b/src/tree/pattern/RuleTagToken.ts index d1eeae9a..bfe313e0 100644 --- a/src/tree/pattern/RuleTagToken.ts +++ b/src/tree/pattern/RuleTagToken.ts @@ -164,7 +164,7 @@ export class RuleTagToken implements Token { *

The implementation for {@link RuleTagToken} always returns {@code null}.

*/ @Override - getTokenSource(): TokenSource | undefined { + get tokenSource(): TokenSource | undefined { return undefined; } diff --git a/test/tool/BaseTest.tssoon b/test/tool/BaseTest.tssoon index 1d5479dc..5d89efda 100644 --- a/test/tool/BaseTest.tssoon +++ b/test/tool/BaseTest.tssoon @@ -1327,7 +1327,7 @@ export abstract class BaseTest { } @Override - getTokenSource(): TokenSource { + get tokenSource(): TokenSource { return null; }