Group tokens into code statements and standalone blank, comment and preprocessor lines.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | src |
source text |
||
| type(token_list_t), | intent(in) | :: | tokens |
tokens of |
||
| type(statement_list_t), | intent(out) | :: | stmts |
the items, covering every token once |
subroutine split_statements(src, tokens, stmts) !! Group `tokens` into code statements and standalone blank, comment and preprocessor lines. character(len=*), intent(in) :: src !! source text type(token_list_t), intent(in) :: tokens !! tokens of `src` type(statement_list_t), intent(out) :: stmts !! the items, covering every token once integer :: i, lend, start, semi, kind allocate (stmts%s(64)) i = 1 do while (i <= tokens%n) lend = line_end_token(tokens, i) kind = line_kind(tokens, i, lend) if (kind /= SK_CODE) then call stmts%push(statement_t(kind, i, lend)) i = lend + 1 cycle end if start = i do ! a `;` with more code after it ends the statement within the line semi = find_semicolon(src, tokens, i, lend) if (semi > 0) then call stmts%push(statement_t(SK_CODE, start, semi)) i = semi + 1 start = i cycle end if if (.not. ends_with_continuation(tokens, i, lend)) exit ! continued: take in the next code line and any comment, blank or preprocessor lines before it do i = lend + 1 if (i > tokens%n) exit lend = line_end_token(tokens, i) if (line_kind(tokens, i, lend) == SK_CODE) exit end do if (i > tokens%n) then lend = tokens%n exit end if end do call stmts%push(statement_t(SK_CODE, start, lend)) i = lend + 1 end do end subroutine split_statements