fdoc

subroutinecode_blockprivate

subroutine code_block(t, parent, block, stack, n)

The code block processor.

Arguments

NameTypeIntentAttributesDescription
ttype(tree_t)inout

the conversion

parentintegerin

the node

blockcharacter(len=*)in

the chunk

stacktype(string_t)inoutallocatabledimension(:)

the chunks left

nintegerinout

how many there are

Calls

Source

Show the code
subroutine code_block(t, parent, block, stack, n)
    type(tree_t), intent(inout) :: t                        !! the conversion
    integer, intent(in) :: parent                           !! the node
    character(len=*), intent(in) :: block                   !! the chunk
    type(string_t), allocatable, intent(inout) :: stack(:)  !! the chunks left
    integer, intent(inout) :: n                             !! how many there are
    type(string_t), allocatable :: lines(:)
    character(len=:), allocatable :: code, rest
    integer :: k, last, sibling, node

    lines = split_on(block, NL)
    last = 0
    do k = 1, size(lines)
        if (len(lines(k)%s) > 0 .and. .not. starts_with(lines(k)%s, '    ')) exit
        last = k
        if (len(lines(k)%s) > 0) lines(k)%s = lines(k)%s(5:)
    end do
    code = join(lines(:last), NL)
    code = code(:len_trim(trimmed_end(code)))
    rest = ''
    if (last < size(lines)) rest = join(lines(last + 1:), NL)
    sibling = last_child(t, parent)
    node = 0
    if (sibling > 0) then
        if (t%nodes(sibling)%tag == 'code') node = sibling
    end if
    if (node > 0) then
        t%nodes(node)%text = t%nodes(node)%text//NL//code//NL
    else
        call new_node(t, parent, 'code', node)
        t%nodes(node)%text = code//NL
    end if
    if (len(rest) > 0) call push_back(stack, n, rest)
end subroutine code_block

Graphs

Calls

Called by