Skip to main content
Version: v0.0.2

Function: valueFreeLocator()

valueFreeLocator(pos): string

Render an arbitrary parser position object as a value-free locator string, keeping only number-valued own properties (the parsers' positions are index-only): e.g. { segmentIndex: 3, elementIndex: 2 }segmentIndex[3].elementIndex[2]. A non-number field (which a position should never carry) is dropped, so a stray value can never reach a diagnostic. Falls back to "?" when no numeric index is present.

Parameters

pos

unknown

A parser position object (index-only by the parser's contract).

Returns

string

A value-free locator built solely from numeric indices.

Example

import { valueFreeLocator } from "@cosyte/cli";

valueFreeLocator({ segmentIndex: 3, elementIndex: 2 }); // => "segmentIndex[3].elementIndex[2]"
valueFreeLocator({}); // => "?"