ffmt_tokens Module

Tokens of free-form Fortran source.

Every byte of the source belongs to exactly one token, including blanks, comments, line breaks and continuation markers, so joining the text of all tokens reproduces the source exactly.


Uses

  • module~~ffmt_tokens~~UsesGraph module~ffmt_tokens ffmt_tokens module~ffmt_strings ffmt_strings module~ffmt_tokens->module~ffmt_strings

Used by

  • module~~ffmt_tokens~~UsedByGraph module~ffmt_tokens ffmt_tokens module~ffmt_case ffmt_case module~ffmt_case->module~ffmt_tokens module~ffmt_source ffmt_source module~ffmt_case->module~ffmt_source module~ffmt_statements ffmt_statements module~ffmt_case->module~ffmt_statements module~ffmt_constructs ffmt_constructs module~ffmt_constructs->module~ffmt_tokens module~ffmt_constructs->module~ffmt_statements module~ffmt_directives ffmt_directives module~ffmt_directives->module~ffmt_tokens module~ffmt_directives->module~ffmt_statements module~ffmt_format ffmt_format module~ffmt_format->module~ffmt_tokens module~ffmt_format->module~ffmt_case module~ffmt_layout ffmt_layout module~ffmt_format->module~ffmt_layout module~ffmt_lexer ffmt_lexer module~ffmt_format->module~ffmt_lexer module~ffmt_linebreak ffmt_linebreak module~ffmt_format->module~ffmt_linebreak module~ffmt_relational ffmt_relational module~ffmt_format->module~ffmt_relational module~ffmt_format->module~ffmt_source module~ffmt_format->module~ffmt_statements module~ffmt_structure ffmt_structure module~ffmt_format->module~ffmt_structure module~ffmt_use_sort ffmt_use_sort module~ffmt_format->module~ffmt_use_sort module~ffmt_whitespace ffmt_whitespace module~ffmt_format->module~ffmt_whitespace module~ffmt_layout->module~ffmt_tokens module~ffmt_layout->module~ffmt_case module~ffmt_layout->module~ffmt_source module~ffmt_layout->module~ffmt_statements module~ffmt_layout->module~ffmt_structure module~ffmt_layout->module~ffmt_whitespace module~ffmt_lexer->module~ffmt_tokens module~ffmt_linebreak->module~ffmt_tokens module~ffmt_linebreak->module~ffmt_source module~ffmt_linebreak->module~ffmt_statements module~ffmt_relational->module~ffmt_tokens module~ffmt_relational->module~ffmt_source module~ffmt_relational->module~ffmt_statements module~ffmt_source->module~ffmt_tokens module~ffmt_source->module~ffmt_directives module~ffmt_source->module~ffmt_lexer module~ffmt_source->module~ffmt_statements module~ffmt_statements->module~ffmt_tokens module~ffmt_structure->module~ffmt_tokens module~ffmt_structure->module~ffmt_constructs module~ffmt_structure->module~ffmt_source module~ffmt_structure->module~ffmt_statements module~ffmt_use_sort->module~ffmt_tokens module~ffmt_use_sort->module~ffmt_source module~ffmt_use_sort->module~ffmt_statements module~ffmt_whitespace->module~ffmt_tokens module~ffmt_whitespace->module~ffmt_source module~ffmt_whitespace->module~ffmt_statements module~ffmt_cli ffmt_cli module~ffmt_cli->module~ffmt_format

Variables

Type Visibility Attributes Name Initial
integer, public, parameter :: CM_CONDITIONAL = 2

OpenMP conditional compilation: !$ code

integer, public, parameter :: CM_DIRECTIVE = 1

compiler directive: !$omp, !$acc, !dir$, !gcc$, ...

integer, public, parameter :: CM_FORMATTER = 3

formatter directive: !&, !&<, !&>

integer, public, parameter :: CM_PLAIN = 0

ordinary comment

integer, public, parameter :: CT_LEADING = 2

& starting a continuation line

integer, public, parameter :: CT_TRAILING = 1

& ending a line

integer, public, parameter :: STR_MULTILINE = 2

continued across lines

integer, public, parameter :: STR_RAW_CONT = 4

a continuation line without a leading &: its blanks are in the string

integer, public, parameter :: STR_UNTERMINATED = 1

no closing quote before the end of the line

integer, public, parameter :: TK_BOM = 15

UTF-8 byte order mark at the start of the file

integer, public, parameter :: TK_BOZ = 10

b'0101', o'17', z'ff'

integer, public, parameter :: TK_COMMENT = 3

from ! to the end of the line

integer, public, parameter :: TK_CONT = 4

continuation &

integer, public, parameter :: TK_DOTOP = 11

.and., .eq., .true., user-defined .op.

integer, public, parameter :: TK_FYPP = 13

inline fypp: ${...}$, @{...}@, #{...}#

integer, public, parameter :: TK_INT = 7

integer literal, possibly with a kind (10_ik)

integer, public, parameter :: TK_NAME = 6

names and keywords

integer, public, parameter :: TK_NEWLINE = 2

LF, CRLF or CR

integer, public, parameter :: TK_OP = 12

operators and punctuation: **, //, ==, =>, ::, (, %, ?, ...

integer, public, parameter :: TK_OTHER = 14

any other character

integer, public, parameter :: TK_PREPROC = 5

a cpp or fypp directive line, with its continuation lines

integer, public, parameter :: TK_REAL = 8

real literal (1.0, .5e-3_dp)

integer, public, parameter :: TK_SPACE = 1

blanks and tabs

integer, public, parameter :: TK_STRING = 9

character literal, possibly with a kind prefix

logical, public, parameter :: is_code_kind(0:15) = [.true., .false., .false., .false., .false., .false., .true., .true., .true., .true., .true., .true., .true., .true., .true., .false.]

True for the kinds of tokens that are part of the code, as opposed to layout (blanks, line breaks, continuation markers), comments and preprocessor lines. Indexed by kind, is_code_kind(t%kind) reads like a function call, and as a constant it is inlined, where a function in another module is not.


Derived Types

type, public ::  token_list_t

The tokens of a source text, in source order.

Components

Type Visibility Attributes Name Initial
integer, public :: n = 0

number of tokens

type(token_t), public, allocatable :: tok(:)

storage; only tok(1:n) is in use

Type-Bound Procedures

procedure, public :: push

append a token

type, public ::  token_t

One token: a byte range of the source with its kind.

Components

Type Visibility Attributes Name Initial
integer, public :: first = 1

first byte in the source

logical, public :: glued = .false.

joined to the previous code token across a line break, with no blank allowed between

integer, public :: kind = 0

one of the TK_* constants

integer, public :: last = 0

last byte in the source

integer, public :: line = 1

line of the first byte

integer, public :: sub = 0

sub-kind (CM_, CT_, STR_*)


Functions

public function detokenize(src, tokens) result(text)

Join the text of all tokens.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: src

the source the tokens were read from

type(token_list_t), intent(in) :: tokens

tokens of src

Return Value character(len=:), allocatable

public pure function is_chevron(src, tokens, t)

True if token t is a < or > operator directly next to another one, as in the CUDA kernel launch call k<<<grid, block>>>(x), where they are not relational operators.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: src

the source the tokens were read from

type(token_list_t), intent(in) :: tokens

tokens of src

integer, intent(in) :: t

index into tokens

Return Value logical

public pure function token_lower(src, t) result(text)

Token text in lowercase (ASCII).

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: src

the source the token was read from

type(token_t), intent(in) :: t

a token of src

Return Value character(len=t)

public pure function token_text(src, t) result(text)

Token text, as it appears in the source.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: src

the source the token was read from

type(token_t), intent(in) :: t

a token of src

Return Value character(len=t)


Subroutines

private subroutine push(self, t)

Append token t, growing the storage as needed.

Arguments

Type IntentOptional Attributes Name
class(token_list_t), intent(inout) :: self

the token list

type(token_t), intent(in) :: t

token to append