Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change fields to methods to support overriding #1664

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/langium/src/parser/indentation-aware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ export class IndentationAwareTokenBuilder<Terminals extends string = string, Key

this.indentTokenType = createToken({
name: this.options.indentTokenName,
pattern: this.indentMatcher,
pattern: this.indentMatcher.bind(this),
line_breaks: false,
});

this.dedentTokenType = createToken({
name: this.options.dedentTokenName,
pattern: this.dedentMatcher,
pattern: this.dedentMatcher.bind(this),
line_breaks: false,
});
}
Expand Down Expand Up @@ -229,7 +229,7 @@ export class IndentationAwareTokenBuilder<Terminals extends string = string, Key
* @param tokens Previously scanned Tokens
* @param groups Token Groups
*/
protected indentMatcher: CustomPatternMatcherFunc = (text, offset, tokens, _groups) => {
protected indentMatcher(text: string, offset: number, tokens: IToken[], _groups: Record<string, IToken[]>): ReturnType<CustomPatternMatcherFunc> {
const { indentTokenName } = this.options;

if (!this.isStartOfLine(text, offset)) {
Expand All @@ -256,7 +256,7 @@ export class IndentationAwareTokenBuilder<Terminals extends string = string, Key

// Token already added, let the indentation now be consumed as whitespace and ignored
return null;
};
}

/**
* A custom pattern for matching dedents
Expand All @@ -266,7 +266,7 @@ export class IndentationAwareTokenBuilder<Terminals extends string = string, Key
* @param tokens Previously scanned Tokens
* @param groups Token Groups
*/
protected dedentMatcher: CustomPatternMatcherFunc = (text, offset, tokens, _groups) => {
protected dedentMatcher(text: string, offset: number, tokens: IToken[], _groups: Record<string, IToken[]>): ReturnType<CustomPatternMatcherFunc> {
const { dedentTokenName } = this.options;

if (!this.isStartOfLine(text, offset)) {
Expand Down Expand Up @@ -306,7 +306,7 @@ export class IndentationAwareTokenBuilder<Terminals extends string = string, Key

// Token already added, let the dedentation now be consumed as whitespace and ignored
return null;
};
}

protected override buildTerminalToken(terminal: TerminalRule): TokenType {
const tokenType = super.buildTerminalToken(terminal);
Expand Down
Loading