Tinderbox v9 Icon

Capture operators

The capture family of operators extract a chunk of information from the stream and store them in a target attribute. The target attribute may be the source of the stream, in which case the parse will cease at the first capture.

Stream.captureLine[("targetAttribute")]

Captures text from the current stream position, up to the next line ending or the end of the stream. The text is stored in the designated targetAttribute, and the stream advances to the character following the line break. A failure occurs if the stream is empty.

Stream.captureNumber[("targetAttribute")]

Captures a number from the current steam position, up to the next character that cannot be considered part of a number; the capture is passed targetAttribute. Advances the stream to that character. A failure occurs if the stream cannot be interpreted as a number.

Stream.captureWord[("targetAttribute")]

Captures text from the current stream position up to the next character that is a digit, whitespace, or punctuation; the capture is passed targetAttribute. Fails if the stream is empty or begins with a digit, whitespace, or punctuation.

Stream.captureTo[("pattern","targetAttribute")]

Stores the string up to but not including the designated pattern string in the designated attribute, and returns the string that follows pattern.

Steam.captureToken[("targetAttribute")]

If the string contains a token specified by a prior parsing operator, the token itself is passed to targetAttribute. The stream is not advanced and any chained parsing continues from the same point.

Stream.captureRest[("targetAttribute")]

Captures the rest of the stream in as the value of targetAttribute, and returns the empty string.

Stream.captureXML

Attempts to parse the source string as XML and fails if unsuccessful. The XML is saved as the current XML item; only one XML item may be current at any time. Returns the empty string, since an XML object may contain nothing outside of the XML.

Stream.captureJSON

Attempts to parse the string as JSON. Fails if unsuccessful. The parsed JSON is saved as the current JSON item; only one JSON item may be current at any time. Returns the rest if the string following the JSON.