subroutineparse_textrecursiveprivate
recursive subroutine parse_text(c, text, path)
Split text, the contents of file path, into text and directives.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| c | type(fypp_t) | inout | the state | |
| text | character(len=*) | in | the text | |
| path | character(len=*) | in | the file |
Calls
Source
Show the code
recursive subroutine parse_text(c, text, path)
type(fypp_t), intent(inout) :: c !! the state
character(len=*), intent(in) :: text !! the text
character(len=*), intent(in) :: path !! the file
character(len=:), allocatable :: content
integer :: pos, start, n, q, e, close_brace
logical :: line_start
character :: ch
n = len(text)
pos = 1
start = 1
line_start = .true.
do while (pos <= n .and. .not. allocated(c%error))
if (line_start) then
line_start = .false.
q = skip_blanks(text, pos)
if (q < n) then
if (text(q:q + 1) == '#!') then
call flush_text(c, text, start, pos - 1)
do
e = end_of_line(text, q)
pos = e + 1
q = skip_blanks(text, pos)
if (q >= n) exit
if (text(q:q + 1) /= '#!') exit
end do
pos = min(pos, n + 1)
start = pos
line_start = .true.
cycle
end if
if (index('#$@', text(q:q)) > 0 .and. text(q + 1:q + 1) == ':') then
call flush_text(c, text, start, pos - 1)
call read_line_directive(text, q + 2, content, pos)
start = pos
line_start = .true.
call handle_directive(c, text(q:q), content, .true., path)
cycle
end if
end if
end if
ch = text(pos:pos)
if (ch == NL) then
line_start = .true.
else if (pos < n .and. index('$#@', ch) > 0) then
if (text(pos + 1:pos + 1) == '{') then
e = end_of_line(text, pos)
close_brace = index(text(pos + 2:e - 1), '}'//ch)
if (close_brace > 0) then
call flush_text(c, text, start, pos - 1)
q = skip_blanks(text, pos + 2)
content = trim_right(text(q:pos + close_brace))
pos = pos + close_brace + 3
start = pos
call handle_directive(c, ch, content, .false., path)
cycle
end if
end if
end if
pos = pos + 1
end do
call flush_text(c, text, start, n)
end subroutine parse_text