Nested structure
Factor handbook » The language » Parsing words

Prev:Reading ahead
Next:Defining words

Recall that the parser loop calls parsing words with an accumulator vector on the stack. The parser loop can be invoked recursively with a new, empty accumulator; the result can then be added to the original accumulator. This is how parsing words for object literals are implemented; object literals can nest arbitrarily deep.

A simple example is the parsing word that reads a quotation:

This word uses a utility word which recursively invokes the parser, reading objects into a new accumulator until an occurrence of ]:
parse-literal ( accum end quot -- accum )

There is another, lower-level word for reading nested structure, which is also useful when called directly:
parse-until ( end -- vec )

Words such as ] use a declaration which causes them to throw an error when an unpaired occurrence is encountered:

See also
{, H{, V{, W{, T{, }