diff --git a/packages/langium/src/parser/indentation-aware.ts b/packages/langium/src/parser/indentation-aware.ts index 3fe6ccb8b..a62f17821 100644 --- a/packages/langium/src/parser/indentation-aware.ts +++ b/packages/langium/src/parser/indentation-aware.ts @@ -15,7 +15,7 @@ import { DefaultLexer, isTokenTypeArray } from './lexer.js'; type IndentationAwareDelimiter = [begin: TokenName, end: TokenName]; -export interface IndentationTokenBuilderOptions { +export interface IndentationTokenBuilderOptions { /** * The name of the token used to denote indentation in the grammar. * A possible definition in the grammar could look like this: @@ -25,7 +25,7 @@ export interface IndentationTokenBuilderOptions> + ignoreIndentationDelimeters: Array> } export const indentationBuilderDefaultOptions: IndentationTokenBuilderOptions = { @@ -73,15 +73,19 @@ export enum LexingMode { * A token builder that is sensitive to indentation in the input text. * It will generate tokens for indentation and dedentation based on the indentation level. * + * The first generic parameter corresponds to the names of terminal tokens, + * while the second one corresonds to the names of keyword tokens. + * Both parameters are optional and can be imported from `./generated/ast.js`. + * * Inspired by https://github.com/chevrotain/chevrotain/blob/master/examples/lexer/python_indentation/python_indentation.js */ -export class IndentationAwareTokenBuilder extends DefaultTokenBuilder { +export class IndentationAwareTokenBuilder extends DefaultTokenBuilder { /** * The stack in which all the previous matched indentation levels are stored * to understand how deep a the next tokens are nested. */ protected indentationStack: number[] = [0]; - readonly options: IndentationTokenBuilderOptions; + readonly options: IndentationTokenBuilderOptions; /** * The token type to be used for indentation tokens @@ -99,10 +103,10 @@ export class IndentationAwareTokenBuilder ext */ protected whitespaceRegExp = /[ \t]+/y; - constructor(options: Partial>> = indentationBuilderDefaultOptions as IndentationTokenBuilderOptions) { + constructor(options: Partial, NoInfer>> = indentationBuilderDefaultOptions as IndentationTokenBuilderOptions) { super(); this.options = { - ...indentationBuilderDefaultOptions as IndentationTokenBuilderOptions, + ...indentationBuilderDefaultOptions as IndentationTokenBuilderOptions, ...options, };