Skip to content

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 ​

NameTypeAttributesDescription
k_integerImplied-do variable of the parameters below.
HIGH_BYTEScharacter(len=128)parameterBytes 128-255.
UNAME_STARTcharacter(len=*)parameterThe first character of a user name: a letter, _, or a byte of a UTF-8 character (gnuplot's π = pi).
UNAME_CHARScharacter(len=*)parameterThe characters of a user name.
TOKEN_WORDinteger(kind=I4P)parameterBare word: keyword, number, column spec.
TOKEN_STRINGinteger(kind=I4P)parameterQuoted string, quotes removed.
TOKEN_COMMAinteger(kind=I4P)parameterComma.
TOKEN_RANGEinteger(kind=I4P)parameterBracketed range, brackets removed.

Derived Types ​

token_object ​

Token.

Components

NameTypeAttributesDescription
kindinteger(kind=I4P)Token kind.
textcharacter(len=:)allocatableToken text.
quotecharacter(len=1)Quote of a string token, blank for others.
firstinteger(kind=I4P)First character in the statement, quotes or brackets included.
lastinteger(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

fortran
subroutine gnuplot_escape(src, pos, text)

Arguments

NameTypeIntentAttributesDescription
srccharacter(len=*)inText.
posinteger(kind=I4P)inoutEscaped character, then the next one.
textcharacter(len=:)inoutallocatableText 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).

fortran
subroutine split_statements(line, statements)

Arguments

NameTypeIntentAttributesDescription
linecharacter(len=*)inSource line.
statementstype(token_object)outallocatableStatements (kind word).

Call graph

tokenize ​

Split statement into tokens.

Attributes: pure

fortran
subroutine tokenize(statement, tokens, iostat, iomsg)

Arguments

NameTypeIntentAttributesDescription
statementcharacter(len=*)inStatement.
tokenstype(token_object)outallocatableTokens.
iostatinteger(kind=I4P)out0, or 1 on a lexical error.
iomsgcharacter(len=:)outallocatableError message.

Call graph

push_token ​

Append item to list (an unallocated list is empty), through a temporary: see push.

Attributes: pure

fortran
subroutine push_token(list, item)

Arguments

NameTypeIntentAttributesDescription
listtype(token_object)inoutallocatableList.
itemtype(token_object)inNew item.

Functions ​

strip_comment ​

line without its # comment (a # outside quotes).

Attributes: pure

Returns: character(len=:)

fortran
function strip_comment(line) result(code)

Arguments

NameTypeIntentAttributesDescription
linecharacter(len=*)inLine.

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)

fortran
function brace_balance(code) result(balance)

Arguments

NameTypeIntentAttributesDescription
codecharacter(len=*)inCode.

Released under the GPL v3, BSD 2-Clause, BSD 3-Clause or MIT License.