subroutinecall_methodrecursiveprivate
recursive subroutine call_method(c, id, v)
A method: of strings startswith, format, join, strip and split, and of dicts get.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| c | type(fypp_t) | inout | the state | |
| id | integer | in | the expression | |
| v | type(value_t) | out | the result |
Calls
- evaluate
- evaluate_args
- equal
- fail
- make_bool
- format_string
- items_of
- add
- write_value
- take
- make_string
- is_space
- split_string
Source
Show the code
recursive subroutine call_method(c, id, v)
type(fypp_t), intent(inout) :: c !! the state
integer, intent(in) :: id !! the expression
type(value_t), intent(out) :: v !! the result
type(value_t), allocatable :: args(:), by_keyword(:), list(:)
integer, allocatable :: keywords(:)
type(value_t) :: object
type(buffer_t) :: b
character(len=:), allocatable :: text
integer :: n, k, first, last
call evaluate(c, c%exprs(id)%a, object)
call evaluate_args(c, id, args, n, keywords, by_keyword)
if (allocated(c%error)) return
if (object%kind == V_DICT .and. c%exprs(id)%text == 'get') then
if (n == 2) v = args(2)
do k = 1, size(object%items), 2
if (equal(object%items(k), args(1))) then
v = object%items(k + 1)
return
end if
end do
return
end if
if (object%kind /= V_STR) then
call fail(c, 'the method '//c%exprs(id)%text//' is not supported')
return
end if
select case (c%exprs(id)%text)
case ('startswith')
k = len(args(1)%text)
if (k > len(object%text)) then
call make_bool(.false., v)
else
call make_bool(object%text(:k) == args(1)%text, v)
end if
case ('format')
call format_string(c, object%text, args(:n), v)
case ('join')
call items_of(c, args(1), list)
if (allocated(c%error)) return
do k = 1, size(list)
if (k > 1) call add(b, object%text)
call write_value(list(k), .false., b)
end do
call take(b, text)
call make_string(text, v)
case ('strip')
first = 1
last = len(object%text)
do while (first <= last)
if (.not. is_space(object%text(first:first))) exit
first = first + 1
end do
do while (last >= first)
if (.not. is_space(object%text(last:last))) exit
last = last - 1
end do
call make_string(object%text(first:last), v)
case ('split')
call split_string(object%text, args(1)%text, v)
case default
call fail(c, 'the method '//c%exprs(id)%text//' is not supported')
end select
end subroutine call_method