foresight_tokens
foresight_tokens, lexer of the gnuplot-like command language.
A line is split into statements at ; and cut at # (both outside quotes); a statement into tokens: words, quoted strings (single quotes literal, double quotes with \t for a tab, \n for a new line and \ taking the next character literally, so \" and \\, as gnuplot), commas and bracketed ranges [a:b]. Each token remembers where it lies in the statement, so that a plot item can be quoted as written. Inside parentheses a word goes on across blanks and commas: ($2 * 1e3) and atan2($2, $1) are single words; quotes inside a word keep their content, blanks included, and a quoted string followed by : starts a word: 1:"the res" and "it":"res" are using specifications.
Source: src/lib/foresight_tokens.F90
Contents
Variables
| Name | Type | Attributes | Description |
|---|---|---|---|
k_ | integer | Implied-do variable of the parameters below. | |
HIGH_BYTES | character(len=128) | parameter | Bytes 128-255. |
UNAME_START | character(len=*) | parameter | The first character of a user name: a letter, _, or a byte of a UTF-8 character (gnuplot's π = pi). |
UNAME_CHARS | character(len=*) | parameter | The characters of a user name. |
TOKEN_WORD | integer(kind=I4P) | parameter | Bare word: keyword, number, column spec. |
TOKEN_STRING | integer(kind=I4P) | parameter | Quoted string, quotes removed. |
TOKEN_COMMA | integer(kind=I4P) | parameter | Comma. |
TOKEN_RANGE | integer(kind=I4P) | parameter | Bracketed range, brackets removed. |
Derived Types
token_object
Token.
Components
| Name | Type | Attributes | Description |
|---|---|---|---|
kind | integer(kind=I4P) | Token kind. | |
text | character(len=:) | allocatable | Token text. |
quote | character(len=1) | Quote of a string token, blank for others. | |
first | integer(kind=I4P) | First character in the statement, quotes or brackets included. | |
last | integer(kind=I4P) | Last character in the statement. |
Interfaces
push
Append an item through a temporary: nvfortran 26.9 corrupts list = [list, item] (and any list = f(list)) when the items hold deferred-length characters.
Module procedures: push_token
Subroutines
gnuplot_escape
gnuplot's escape (parse_esc) in a double-quoted string, src(pos:pos) the character after the backslash, appended to text, pos then after it: \n, \t and \r; octal \ooo a byte (up to 4 digits after a 0, else 3); \U+ kept with its backslash for the enhanced text; another character as it is (\ a backslash, " a quote).
Attributes: pure
subroutine gnuplot_escape(src, pos, text)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
src | character(len=*) | in | Text. | |
pos | integer(kind=I4P) | inout | Escaped character, then the next one. | |
text | character(len=:) | inout | allocatable | Text read. |
Call graph
split_statements
Split line at ; (and new lines) outside quotes and braces, dropping the # comment; blank statements are skipped. A block do for [...] { ...; ... } is one statement. Each statement's first and last are its characters in line (whether two are on the same line).
subroutine split_statements(line, statements)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
line | character(len=*) | in | Source line. | |
statements | type(token_object) | out | allocatable | Statements (kind word). |
Call graph
tokenize
Split statement into tokens.
Attributes: pure
subroutine tokenize(statement, tokens, iostat, iomsg)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
statement | character(len=*) | in | Statement. | |
tokens | type(token_object) | out | allocatable | Tokens. |
iostat | integer(kind=I4P) | out | 0, or 1 on a lexical error. | |
iomsg | character(len=:) | out | allocatable | Error message. |
Call graph
push_token
Append item to list (an unallocated list is empty), through a temporary: see push.
Attributes: pure
subroutine push_token(list, item)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
list | type(token_object) | inout | allocatable | List. |
item | type(token_object) | in | New item. |
Functions
strip_comment
line without its # comment (a # outside quotes).
Attributes: pure
Returns: character(len=:)
function strip_comment(line) result(code)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
line | character(len=*) | in | Line. |
brace_balance
Braces opened minus closed in code (no comment), outside quotes: a block goes on while it is positive.
Attributes: pure
Returns: integer(kind=I4P)
function brace_balance(code) result(balance)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
code | character(len=*) | in | Code. |