Chunks

Implementing Chunks

As text is parsed it is accumulated into chunks.

chunks +≡
variable chunk
: chunk+=$ ( A -- )
    chunk @ if chunk @ atom+=$ else drop then ;
: chunk+=ref ( A -- )
    chunk @ if chunk @ atom+=ref else drop then ;

A special primary chunk is kept for the main document.

chunks +≡
atom" ~~~DOC" constant main-documentation
variable documentation-chunk
main-documentation documentation-chunk !

A number of words are provided to write to the current documentation chunk or to set it.

chunks +≡
: documentation ( -- A )
    documentation-chunk @ ;
: doc! ( back to documentation)
    0 chunk ! ;
: doc+=$ ( A -- )
    documentation atom+=$ ;
: .d{ ( -- )
    postpone atom{ postpone doc+=$ ; immediate
: .d| ( -- )
    parse..| ; immediate
: |.d ( -- )
    postpone literal postpone doc+=$ ; immediate
: .dcr   atom-cr doc+=$ ;
: doc+=ref ( A -- )
    documentation atom+=ref ;
: doc+=use
    ( A -- ) .d{ <b>} doc+=$ .d{ </b>} ;
: doc+=def ( A -- )
    .d{ </p><tt><b>} doc+=$
    .d{ </b> +&equiv;</tt><div class="chunk"><pre>} ;

This is critically use by nearly every tag to parse until the next tag using the word feed .

chunks +≡
: feed ( read into current chunk )
    parse..| dup ?atom-cr+ escape doc+=$ atom-cr+ chunk+=$ ;