Repair indexing calculation in StringScanner to support nontrivial use of source positions

This commit is contained in:
Tony Garnock-Jones 2021-01-18 15:32:21 +01:00
parent 2ff3067fad
commit f46276cf05
2 changed files with 3 additions and 45 deletions

View File

@ -1,44 +0,0 @@
#!/usr/bin/env -S node --es-module-specifier-resolution=node
//---------------------------------------------------------------------------
// @syndicate-lang/core, an implementation of Syndicate dataspaces for JS.
// Copyright (C) 2016-2021 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//---------------------------------------------------------------------------
assertion type BoxState(value);
message type SetBox(newValue);
const N = 100000;
console.time('box-and-client-' + N.toString());
boot {
spawn named 'box' {
field this.value = 0;
assert BoxState(this.value);
stop on (this.value === N) console.log('terminated box root facet');
on message SetBox($v) => this.value = v;
}
spawn named 'client' {
on asserted BoxState($v) => send SetBox(v + 1);
on retracted BoxState(_) => console.log('box gone');
}
thisFacet.actor.dataspace.addStopHandler(() =>
console.timeEnd('box-and-client-' + N.toString()));
}
new __SYNDICATE__.Ground(__SYNDICATE__bootProc).start();

View File

@ -203,13 +203,15 @@ export abstract class Scanner implements IterableIterator<Token> {
export class StringScanner extends Scanner {
readonly input: string;
readonly startPos: number;
constructor(pos: Pos, input: string) {
super(pos);
this.input = input;
this.startPos = this.pos.pos;
}
_peekChar(): string | null {
return this.input[this.pos.pos] ?? null;
return this.input[this.pos.pos - this.startPos] ?? null;
}
}