subroutineparse_comprehensionrecursiveprivate
recursive subroutine parse_comprehension(c, s, element, id)
The for clauses after the item element.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| c | type(fypp_t) | inout | the state | |
| s | type(scan_t) | inout | the expression | |
| element | integer | in | the item | |
| id | integer | out | the result |
Calls
Source
Show the code
recursive subroutine parse_comprehension(c, s, element, id)
type(fypp_t), intent(inout) :: c !! the state
type(scan_t), intent(inout) :: s !! the expression
integer, intent(in) :: element !! the item
integer, intent(out) :: id !! the result
integer :: clause, iterable, condition, name, comprehension
comprehension = new_expr(c, E_COMP, element)
do while (at_word(s, 'for') .and. .not. allocated(c%error))
call next_token(c, s)
clause = new_expr(c, E_CLAUSE)
allocate (c%exprs(clause)%args(0), c%exprs(clause)%names(0))
do
if (s%kind /= T_NAME) call fail(c, 'cannot read the loop in: '//s%text)
if (allocated(c%error)) return
call intern(c, s%word, name)
call push_id(c%exprs(clause)%names, name)
call next_token(c, s)
if (.not. at_word(s, ',')) exit
call next_token(c, s)
end do
call expect(c, s, 'in')
call parse_or(c, s, iterable)
c%exprs(clause)%a = iterable
do while (at_word(s, 'if'))
call next_token(c, s)
call parse_or(c, s, condition)
call push_id(c%exprs(clause)%args, condition)
end do
call push_id(c%exprs(comprehension)%args, clause)
end do
id = comprehension
end subroutine parse_comprehension