subroutinerender_noderecursiveprivate
recursive subroutine render_node(c, id, out, top)
Render a node.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| c | type(fypp_t) | inout | the state | |
| id | integer | in | the node | |
| out | type(buffer_t) | inout | the output | |
| top | logical | in | true if this is not going into a macro's result |
Calls
- add
- evaluate
- write_value
- record_span
- truth_of
- render_body
- render_loop
- assign_targets
- define_macro
- render_call
- fail
Source
Show the code
recursive subroutine render_node(c, id, out, top)
type(fypp_t), intent(inout) :: c !! the state
integer, intent(in) :: id !! the node
type(buffer_t), intent(inout) :: out !! the output
logical, intent(in) :: top !! true if this is not going into a macro's result
type(value_t) :: v
type(buffer_t) :: discarded
integer :: k, first
select case (c%nodes(id)%kind)
case (N_TEXT)
call add(out, c%nodes(id)%text)
case (N_EVAL)
call evaluate(c, c%nodes(id)%expr, v)
if (allocated(c%error)) return
if (v%kind /= V_NONE) then
first = out%n
call write_value(v, .false., out)
if (top) call record_span(c, first, out%n)
end if
if (c%nodes(id)%on_lines) call add(out, NL)
case (N_IF)
do k = 1, size(c%nodes(id)%block%bodies)
if (c%nodes(id)%block%conds(k) > 0) then
call evaluate(c, c%nodes(id)%block%conds(k), v)
if (allocated(c%error)) return
if (.not. truth_of(v)) cycle
end if
call render_body(c, c%nodes(id)%block%bodies(k), out, top)
exit
end do
case (N_FOR)
call render_loop(c, id, out, top)
case (N_SET)
if (c%nodes(id)%expr > 0) call evaluate(c, c%nodes(id)%expr, v)
if (.not. allocated(c%error)) call assign_targets(c, c%nodes(id)%block%targets, v)
case (N_DEF)
call define_macro(c, id)
case (N_CALL)
call render_call(c, id, out, top)
case (N_MUTE)
call render_body(c, c%nodes(id)%block%bodies(1), discarded, .false.)
case (N_ASSERT)
call evaluate(c, c%nodes(id)%expr, v)
if (.not. truth_of(v)) call fail(c, 'assertion failed: '//c%nodes(id)%source)
end select
end subroutine render_node