Repair span of identifier after `$`

This commit is contained in:
Tony Garnock-Jones 2024-03-23 10:43:42 +01:00
parent da97db8548
commit 2dca2c2d77
1 changed files with 14 additions and 4 deletions

View File

@ -2,9 +2,10 @@
/// SPDX-FileCopyrightText: Copyright © 2016-2024 Tony Garnock-Jones <tonyg@leastfixedpoint.com> /// SPDX-FileCopyrightText: Copyright © 2016-2024 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
import { import {
Token, Items, TokenBase, TokenType, Token, Items, TokenBase, TokenType, Pos,
Pattern, Pattern,
foldItems, match, anonymousTemplate as template, commaJoin, foldItems, match, anonymousTemplate as template, commaJoin,
advancePos,
scope, bind, seq, seqTuple, alt, upTo, atom, atomString, group, scope, bind, seq, seqTuple, alt, upTo, atom, atomString, group,
repeat, option, withoutSpace, map, mapm, rest, discard, repeat, option, withoutSpace, map, mapm, rest, discard,
@ -410,9 +411,18 @@ export class SyndicateParser {
pCaptureBinder = (b: Pattern<Binder>): Pattern<Binder> => pCaptureBinder = (b: Pattern<Binder>): Pattern<Binder> =>
mapm(b, i => { mapm(b, i => {
return i.id.text.startsWith('$') if (i.id.text.startsWith('$')) {
? succeed({ id: { ... i.id, text: i.id.text.slice(1) }, type: i.type }) const adjustedStart: Pos = { ... i.id.start };
: fail; 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); readonly pCaptureDefaultBinder = this.pCaptureBinder(this.defaultBinder);