Skip to main content
Version: v0.0.8

Function: unexpectedSegment()

unexpectedSegment(position, context): X12ParseWarning

Build an X12_UNEXPECTED_SEGMENT warning. Emitted when a structurally meaningful segment (GE, SE, ST, TA1, or a body segment) appears outside its expected parent. The parser preserves lenient-never-throw and continues; context names which structural rule broke and position locates the segment.

The segment's own id is deliberately not a parameter. Note that a segment in one of these positions is NOT retained on the model at all (it has no open container to belong to), so position.segmentIndex against the input is the only way back to its bytes. For a segment that IS retained, the X12Segment.id a consumer reads is bounded to the X12 segment-id grammar (see "./segment.js".decodeSegment) while seg.raw and seg.elements[0] stay verbatim.

Parameters

position

X12Position

context

X12UnexpectedSegmentContext

Returns

X12ParseWarning

Example

import { unexpectedSegment, UNEXPECTED_SEGMENT_CONTEXTS } from "@cosyte/x12";
const w = unexpectedSegment(
{ segmentIndex: 12, interchangeIndex: 0 },
UNEXPECTED_SEGMENT_CONTEXTS.GE_WITHOUT_GS,
);