Lexer for free-form Fortran.
The lexer never fails: malformed input (e.g. an unterminated string) still produces tokens that cover every byte, flagged where relevant, so the formatter can leave such code alone.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| character(len=1), | private, | parameter | :: | CR | = | achar(13) | |
| character(len=1), | private, | parameter | :: | LF | = | achar(10) | |
| character(len=1), | private, | parameter | :: | TAB | = | achar(9) |
Lexer state for one source text.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| logical, | public | :: | glue_next | = | .false. |
the next code token continues the previous one |
|
| logical, | public | :: | glue_pending | = | .false. |
the previous line ended with a code character directly followed by |
|
| integer, | public | :: | line | = | 1 |
current line |
|
| logical, | public | :: | line_start | = | .true. |
only blanks so far on the current line |
Comment sub-kind (one of the CM_* constants) of a comment.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | text |
comment text, from |
Last digit of the run starting at i, or i - 1 if there is none.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | src |
source text |
||
| integer, | intent(in) | :: | i |
byte where the run of digits starts |
True if a dot operator such as .and. or .true. starts at i.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | src |
source text |
||
| integer, | intent(in) | :: | i |
byte to look at |
Last byte of the dot operator at i, including a kind suffix on .true._lk / .false._lk.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | src |
source text |
||
| integer, | intent(in) | :: | i |
byte of the opening |
Last byte of inline fypp (${...}$, @{...}@, #{...}#) starting at i, or 0.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | src |
source text |
||
| integer, | intent(in) | :: | i |
byte to look at |
True for a blank or tab.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=1), | intent(in) | :: | c |
the character |
A character that can be part of a code token (not a blank, line break or comment).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=1), | intent(in) | :: | c |
the character |
True for 0 to 9.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=1), | intent(in) | :: | c |
the character |
True for an ASCII letter.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=1), | intent(in) | :: | c |
the character |
Characters allowed after the first letter of a name ($ is a common extension).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=1), | intent(in) | :: | c |
the character |
True if a preprocessor line starts at i (the first non-blank of the line): cpp #...,
fypp #:, #!, $: and @:. Inline fypp #{ is not a directive line.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | src |
source text |
||
| integer, | intent(in) | :: | i |
first non-blank byte of the line |
True for ' or ".
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=1), | intent(in) | :: | c |
the character |
Last non-blank byte in src(i:j), or 0.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | src |
source text |
||
| integer, | intent(in) | :: | i |
byte range to search |
||
| integer, | intent(in) | :: | j |
byte range to search |
Index of the last byte before the line break at or after i.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | src |
source text |
||
| integer, | intent(in) | :: | i |
byte to start from |
Last byte of the name starting at i, stopping before inline fypp ${.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | src |
source text |
||
| integer, | intent(in) | :: | i |
first byte of the name |
True if there are only blanks from i to the end of the line.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | src |
source text |
||
| integer, | intent(in) | :: | i |
byte to start from |
Last byte of a two- or one-character operator at i, or 0 if there is none.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | src |
source text |
||
| integer, | intent(in) | :: | i |
byte to look at |
Character at i, or NUL outside the string.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | src |
source text |
||
| integer, | intent(in) | :: | i |
byte index, possibly outside |
Last byte of a preprocessor line at i, including continuation lines: a trailing \ for
cpp, a trailing & for fypp. The final line break is not included.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | src |
source text |
||
| integer, | intent(in) | :: | i |
first byte of the directive ( |
Last byte of a string literal whose opening quote is at i. Handles doubled quotes and
continuation lines; flags reports STR_* conditions.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | src |
source text |
||
| integer, | intent(in) | :: | i |
byte of the opening quote |
||
| integer, | intent(out) | :: | flags |
STR_* bit flags of the literal |
Append a token, maintaining the line count and the glue state for split tokens.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(token_list_t), | intent(inout) | :: | tokens |
token list to append to |
||
| type(lexer_t), | intent(inout) | :: | lx |
lexer state |
||
| character(len=*), | intent(in) | :: | src |
source text |
||
| integer, | intent(in) | :: | kind |
token kind, one of the TK_* constants |
||
| integer, | intent(in) | :: | first |
first byte of the token in |
||
| integer, | intent(in) | :: | last |
last byte of the token in |
||
| integer, | intent(in), | optional | :: | sub |
sub-kind (CM_, CT_, STR_*); 0 if absent |
Integer or real literal starting at i (a digit, or . followed by a digit).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | src |
source text |
||
| integer, | intent(in) | :: | i |
first byte of the literal |
||
| integer, | intent(out) | :: | j |
last byte of the literal, including any kind suffix |
||
| integer, | intent(out) | :: | kind |
|
Split src into tokens.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | src |
source text |
||
| type(token_list_t), | intent(out) | :: | tokens |
its tokens, covering every byte |