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);