subroutinedefinition_blockrecursiveprivate
recursive subroutine definition_block(t, parent, block, at, stack, n)
The definition list processor.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| t | type(tree_t) | inout | the conversion | |
| parent | integer | in | the node | |
| block | character(len=*) | in | the chunk | |
| at | integer | in | where the definition starts | |
| stack | type(string_t) | inout | allocatabledimension(:) | the chunks left |
| n | integer | inout | how many there are |
Calls
Source
Show the code
recursive subroutine definition_block(t, parent, block, at, stack, n)
type(tree_t), intent(inout) :: t !! the conversion
integer, intent(in) :: parent !! the node
character(len=*), intent(in) :: block !! the chunk
integer, intent(in) :: at !! where the definition starts
type(string_t), allocatable, intent(inout) :: stack(:) !! the chunks left
integer, intent(inout) :: n !! how many there are
type(string_t), allocatable :: terms(:), lines(:)
character(len=:), allocatable :: def
integer :: list, sibling, node, k, first, stop_line
allocate (terms(0))
if (at > 1) terms = split_on(block(:at - 2), NL)
sibling = last_child(t, parent)
list = 0
if (sibling > 0) then
if (t%nodes(sibling)%tag == 'dl') then
list = sibling
else if (size(terms) == 0 .and. t%nodes(sibling)%tag == 'p') then
terms = split_on(t%nodes(sibling)%text, NL)
t%nodes(parent)%kids = t%nodes(parent)%kids(:size(t%nodes(parent)%kids) - 1)
end if
end if
if (size(terms) == 0 .and. list == 0) then
call paragraph(t, parent, block)
return
end if
if (list == 0) call new_node(t, parent, 'dl', list)
do k = 1, size(terms)
call new_node(t, list, 'dt', node)
t%nodes(node)%text = strip(terms(k)%s)
end do
lines = split_on(block(at:), NL)
stop_line = size(lines)
do k = 2, size(lines)
first = verify(lines(k)%s//'x', ' ')
if (first <= 4 .and. first < len(lines(k)%s)) then
if (lines(k)%s(first:first + 1) == ': ') then
stop_line = k - 1
exit
end if
end if
end do
first = index(lines(1)%s, ':')
def = strip(lines(1)%s(first + 1:))
do k = 2, stop_line
def = def//NL//strip(lines(k)%s)
end do
call new_node(t, list, 'dd', node)
call set_state(t, 'list')
call parse_one(t, node, def)
call reset_state(t)
if (stop_line < size(lines)) call push_back(stack, n, join(lines(stop_line + 1:), NL))
end subroutine definition_block