From 2dca2c2d77c5ec816b27a74c1201de1798db77bf Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Sat, 23 Mar 2024 10:43:42 +0100 Subject: [PATCH] Repair span of identifier after `$` --- packages/compiler/src/compiler/grammar.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/compiler/src/compiler/grammar.ts b/packages/compiler/src/compiler/grammar.ts index c5f951a..3585e2b 100644 --- a/packages/compiler/src/compiler/grammar.ts +++ b/packages/compiler/src/compiler/grammar.ts @@ -2,9 +2,10 @@ /// SPDX-FileCopyrightText: Copyright © 2016-2024 Tony Garnock-Jones import { - Token, Items, TokenBase, TokenType, + Token, Items, TokenBase, TokenType, Pos, Pattern, foldItems, match, anonymousTemplate as template, commaJoin, + advancePos, scope, bind, seq, seqTuple, alt, upTo, atom, atomString, group, repeat, option, withoutSpace, map, mapm, rest, discard, @@ -410,9 +411,18 @@ export class SyndicateParser { pCaptureBinder = (b: Pattern): Pattern => mapm(b, i => { - return i.id.text.startsWith('$') - ? succeed({ id: { ... i.id, text: i.id.text.slice(1) }, type: i.type }) - : fail; + if (i.id.text.startsWith('$')) { + const adjustedStart: Pos = { ... i.id.start }; + advancePos(adjustedStart, ' '); + const adjustedId: Token = { + ... i.id, + start: adjustedStart, + text: i.id.text.slice(1), + }; + return succeed({ id: adjustedId, type: i.type }); + } else { + return fail; + } }); readonly pCaptureDefaultBinder = this.pCaptureBinder(this.defaultBinder);