Skip to content

Commit

Permalink
Place the dedent after first new line
Browse files Browse the repository at this point in the history
  • Loading branch information
aabounegm committed Oct 2, 2024
1 parent 1919efa commit 048d76d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/langium/src/parser/indentation-aware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,14 @@ export class IndentationAwareTokenBuilder<Terminals extends string = string, Key
}

const numberOfDedents = this.indentationStack.length - matchIndentIndex - 1;
const newlinesBeforeDedent = text.substring(0, offset).match(/[\r\n]+$/)?.[0].length ?? 1;

for (let i = 0; i < numberOfDedents; i++) {
const token = this.createIndentationTokenInstance(
this.dedentTokenType,
text,
'', // Dedents are 0-width tokens
offset,
offset - (newlinesBeforeDedent - 1), // Place the dedent after the first new line character
);
tokens.push(token);
this.indentationStack.pop();
Expand Down

0 comments on commit 048d76d

Please sign in to comment.