fortls package

Subpackages

Submodules

fortls.constants module

fortls.constants.FORTRAN_LITERAL = '0^=__LITERAL_INTERNAL_DUMMY_VAR_'

A string used to mark literals e.g. 10, 3.14, “words”, etc. The description name chosen is non-ambiguous and cannot naturally occur in Fortran (with/out C preproc) code It is invalid syntax to define a type starting with numerics it cannot also be a comment that requires !, c, d and ^= (xor_eq) operator is invalid in Fortran C++ preproc

class fortls.constants.Severity

Bases: object

error = 1
info = 3
warn = 2

fortls.debug module

exception fortls.debug.DebugError

Bases: Exception

Base class for debug CLI.

exception fortls.debug.ParameterError

Bases: DebugError

Exception raised for errors in the parameters.

fortls.debug.check_request_params(args, loc_needed=True)
fortls.debug.debug_actions(args, server)
fortls.debug.debug_completion(args, server)
fortls.debug.debug_definition(args, server)
fortls.debug.debug_diagnostics(args, server)
fortls.debug.debug_generic(args, test_label, lsp_request, format_results, loc_needed=True)
fortls.debug.debug_hover(args, server)
fortls.debug.debug_implementation(args, server)
fortls.debug.debug_lsp(args, settings)
fortls.debug.debug_parser(args)

Debug the parser of the Language Server Triggered by –debug_parser option.

Parameters:

args (Namespace) – The arguments parsed from the ArgumentParser

fortls.debug.debug_preprocessor(args)

Debug the preprocessor of the Language Server Triggered by –debug_preprocessor option.

Parameters:

args (Namespace) – The arguments parsed from the ArgumentParser

fortls.debug.debug_references(args, server)
fortls.debug.debug_rename(args, server)
fortls.debug.debug_rootpath(args, server)
fortls.debug.debug_signature(args, server)
fortls.debug.debug_symbols(args, server)
fortls.debug.debug_workspace_symbols(args, server)
fortls.debug.ensure_file_accessible(filepath)

Ensure the file exists and is accessible, raising an error if not.

fortls.debug.is_debug_mode(args)
fortls.debug.locate_config(root, input_config)
Return type:

str | None

fortls.debug.print_children(obj, indent='')
fortls.debug.print_results(results, format_results, args)

Helper function to print results based on detail level requested.

fortls.debug.process_file_changes(file_path, changes, file_contents)
fortls.debug.read_config(root, input_config)
fortls.debug.separator()

fortls.ftypes module

class fortls.ftypes.ClassInfo(name, parent, keywords)

Bases: object

Holds information about a Fortran CLASS

keywords: list[str]

Keywords associated with the class

name: str

Class name

parent: str

Parent object of class e.g. TYPE, EXTENDS(scaled_vector) :: a

class fortls.ftypes.FunSig(name, args, keywords=<factory>, mod_flag=False, result=<factory>)

Bases: SubInfo

Holds information about a Fortran FUNCTION

result: ResultSig

Function’s result with default result.name = name

class fortls.ftypes.GenProcDefInfo(bound_name, pro_links, vis_flag)

Bases: object

Holds information about a GENERIC PROCEDURE DEFINITION

bound_name: str

Procedure name

Procedure links

vis_flag: int

Visibility flag, public or private

class fortls.ftypes.IncludeInfo(line_number, path, file, scope_objs)

Bases: object

Holds information about a Fortran INCLUDE statement

file: None
line_number: int

Line number of include

path: str

File path to include

scope_objs: list[str]

A list of available scopes

class fortls.ftypes.InterInfo(name, abstract)

Bases: object

Holds information about a Fortran INTERFACE

abstract: bool

Whether or not the interface is abstract

name: str

Interface name

class fortls.ftypes.Range(start, end)

Bases: tuple

A single line range tuple

end: int

Alias for field number 1

start: int

Alias for field number 0

class fortls.ftypes.ResultSig(name=None, type=None, kind=None, keywords=<factory>)

Bases: object

Holds information about the RESULT section of a Fortran FUNCTION

keywords: list[str]

Keywords associated with the result variable, can append without init

kind: str | None = None

Variable kind of result

name: str | None = None

Variable name of result

type: str | None = None

Variable type of result

class fortls.ftypes.SelectInfo(type, binding, desc)

Bases: object

Holds information about a SELECT construct

binding: str

Variable/Object being selected upon

desc: str

Description of select e.g. “TYPE”, “CLASS”, None

type: int

Type of SELECT e.g. normal, select type, select kind, select rank

class fortls.ftypes.SmodInfo(name, parent)

Bases: object

Holds information about Fortran SUBMODULES

name: str

Submodule name

parent: str

Submodule i.e. module, parent

class fortls.ftypes.SubInfo(name, args, keywords=<factory>, mod_flag=False)

Bases: object

Holds information about a Fortran SUBROUTINE

args: str

Argument list

keywords: list[str]

Keywords associated with procedure

mod_flag: bool = False

Whether or not this is a MODULE PROCEDURE

name: str

Procedure name

class fortls.ftypes.UseInfo(mod_name, only_list, rename_map)

Bases: object

Holds information about a Fortran USE statement

mod_name: str

Module name

only_list: set[str]

List of procedures, variables, interfaces, etc. imported via only

rename_map: dict[str, str]

A dictionary holding the new names after a rename operation

class fortls.ftypes.VarInfo(var_type, keywords, var_names, var_kind=None)

Bases: object

Holds information about a Fortran VARIABLE

keywords: list[str]

Keywords associated with variable

var_kind: str | None = None

Kind of variable e.g. INTEGER*4 etc.

var_names: list[str]

Variable names

var_type: str

Type of variable e.g. INTEGER, REAL, etc.

class fortls.ftypes.VisInfo(type, obj_names)

Bases: object

Holds information about the VISIBILITY of a module’s contents

obj_names: list[str]

Module variables, procedures, etc. with that visibility

type: int

PRIVATE TODO: convert to boolean

Type:

Visibility type 0

Type:

PUBLIC 1

fortls.helper_functions module

fortls.helper_functions.detect_fixed_format(file_lines)

Detect fixed/free format by looking for characters in label columns and variable declarations before column 6. Treat intersection format files as free format.

Parameters:

file_lines (list[str]) – List of consecutive file lines

Returns:

True if file_lines are of Fixed Fortran style

Return type:

bool

Examples

>>> detect_fixed_format([' free format'])
False
>>> detect_fixed_format([' INTEGER, PARAMETER :: N = 10'])
False
>>> detect_fixed_format(['C Fixed format'])
True

Lines wih ampersands are not fixed format >>> detect_fixed_format([‘trailing line & ! comment’]) False

But preprocessor lines will be ignored >>> detect_fixed_format( … [‘#if defined(A) && !defined(B)’, ‘C Fixed format’, ‘#endif’]) True

>>> detect_fixed_format(
...     ['#if defined(A) && !defined(B)', ' free format', '#endif'])
False

And preprocessor line-continuation is taken into account >>> detect_fixed_format( … [‘#if defined(A) \ ‘, ‘ && !defined(B)’, ‘C Fixed format’, ‘#endif’]) True

>>> detect_fixed_format(
...     ['#if defined(A) \\', '&& \\', '!defined(B)', ' free format', '#endif'])
False
fortls.helper_functions.expand_name(line, char_pos)

Get full word containing given cursor position

Parameters:
  • line (str) – Text line

  • char_pos (int) – Column position along the line

Returns:

Word regex match for the input column

Return type:

str

fortls.helper_functions.find_paren_match(string)

Find matching closing parenthesis from an already open parenthesis scope by forward search of the string, returns -1 if no match is found

Parameters:

string (str) – Input string

Returns:

The index of the matching ) character in the string

Return type:

int

Examples

>>> find_paren_match('a, b)')
4

Multiple parenthesis that are closed

>>> find_paren_match('a, (b, c), d)')
12

If the outermost parenthesis is not closed function returns -1

>>> find_paren_match('a, (b, (c, d)')
-1
>>> find_paren_match('nt(sin(0.5))+8+len("ab((c")-3) :: y')
29
>>> find_paren_match("nt(sin(0.5))+8+len('ab))c')-3) :: y")
29
fortls.helper_functions.find_word_in_line(line, word)

Find Fortran word in line

Parameters:
  • line (str) – Text line

  • word (str) – word to find in line

Returns:

start and end positions (indices) of the word if not found it returns -1, len(word) -1

Return type:

Range

fortls.helper_functions.fortran_md(code, docs)

Convert Fortran code to markdown

Parameters:
  • code (str) – Fortran code

  • docs (str | None) – Documentation string

Returns:

Markdown string

Return type:

str

fortls.helper_functions.get_keywords(keywords, keyword_info=None)
fortls.helper_functions.get_line_prefix(pre_lines, curr_line, col, qs=True)

Get code line prefix from current line and preceding continuation lines

Parameters:
  • pre_lines (list) – for multiline cases get all the previous, relevant lines

  • curr_line (str) – the current line

  • col (int) – column index of the current line

  • qs (bool, optional) – strip quotes i.e. string literals from curr_line and pre_lines. Need this disable when hovering over string literals, by default True

Returns:

part of the line including any relevant line continuations before col

Return type:

str

Examples

>>> get_line_prefix([''], '#pragma once', 0) is None
True
fortls.helper_functions.get_paren_level(line)

Get sub-string corresponding to a single parenthesis level, via backward search up through the line.

Parameters:

line (str) – Document line

Returns:

Arguments as a string and a list of Ranges for the arguments against line

Return type:

tuple[str, list[Range]]

Examples

>>> get_paren_level('CALL sub1(arg1,arg2')
('arg1,arg2', [Range(start=10, end=19)])

If the range is interrupted by parenthesis, another Range variable is used to mark the start and end of the argument

>>> get_paren_level('CALL sub1(arg1(i),arg2')
('arg1,arg2', [Range(start=10, end=14), Range(start=17, end=22)])
>>> get_paren_level('')
('', [Range(start=0, end=0)])
fortls.helper_functions.get_paren_substring(string)

Get the contents enclosed by the first pair of parenthesis

Parameters:

string (str) – A string

Returns:

The part of the string enclosed in parenthesis e.g. or None

Return type:

str | None

Examples

>>> get_paren_substring('some line(a, b, (c, d))')
'a, b, (c, d)'

If the line has incomplete parenthesis however, None is returned >>> get_paren_substring(‘some line(a, b’) is None True

fortls.helper_functions.get_placeholders(arg_list)

Function used to generate placeholders for snippets

Parameters:

arg_list (list[str]) – Method arguments list

Returns:

Tuple of arguments as a string and snippet string

Return type:

Tuple[str, str]

Examples

>>> get_placeholders(['x', 'y'])
('(x, y)', '(${1:x}, ${2:y})')
>>> get_placeholders(['x=1', 'y=2'])
('(x=1, y=2)', '(x=${1:1}, y=${2:2})')
>>> get_placeholders(['x', 'y=2', 'z'])
('(x, y=2, z)', '(${1:x}, y=${2:2}, ${3:z})')
fortls.helper_functions.get_var_stack(line)

Get user-defined type field sequence terminating the given line

Parameters:

line (str) – Document line

Returns:

list of objects split by %

Return type:

list[str]

Examples

>>> get_var_stack('myvar%foo%bar')
['myvar', 'foo', 'bar']
>>> get_var_stack('myarray(i)%foo%bar')
['myarray', 'foo', 'bar']
>>> get_var_stack('myarray( i ) % foo   % bar')
['myarray', 'foo', 'bar']

In this case it will operate at the end of the string i.e. 'this%foo'

>>> get_var_stack('CALL self%method(this%foo')
['this', 'foo']
>>> get_var_stack('')
['']
fortls.helper_functions.map_keywords(keywords)
fortls.helper_functions.only_dirs(paths)

From a list of strings returns only paths that are directories

Parameters:

paths (list[str]) – A list containing the files and directories

Returns:

A list containing only valid directories

Return type:

list[str]

Raises:

FileNotFoundError – A list containing all the non existing directories

Examples

>>> only_dirs(['./test/', './test/test_source/', './test/test_source/test.f90'])
['./test/', './test/test_source/']
>>> only_dirs(['/fake/dir/a', '/fake/dir/b', '/fake/dir/c'])
Traceback (most recent call last):
FileNotFoundError: /fake/dir/a
/fake/dir/b
/fake/dir/c
fortls.helper_functions.parenthetic_contents(string)

Generate parenthesized contents in string as pairs (contents, start-position, level).

Examples

>>> list(parenthetic_contents('character*(10*size(val(1), 2)) :: name'))
[('1', 22, 2), ('val(1), 2', 18, 1), ('10*size(val(1), 2)', 10, 0)]
fortls.helper_functions.resolve_globs(glob_path, root_path=None)

Resolve paths (absolute and relative) and glob patterns while nonexistent paths are ignored

Parameters:
  • glob_path (str) – Path containing the glob pattern follows fnmatch glob pattern, can include relative paths, etc. see fnmatch: https://docs.python.org/3/library/fnmatch.html#module-fnmatch

  • root_path (str, optional) – root path to start glob search. If left empty the root_path will be extracted from the glob_path, by default None

Returns:

Expanded glob patterns with absolute paths. Absolute paths are used to resolve any potential ambiguity

Return type:

list[str]

Examples

Relative to a root path >>> import os, pathlib >>> resolve_globs(‘test’, os.getcwd()) == [str(pathlib.Path(os.getcwd()) / ‘test’)] True

Absolute path resolution >>> resolve_globs(‘test’) == [str(pathlib.Path(os.getcwd()) / ‘test’)] True

fortls.helper_functions.separate_def_list(test_str)

Separate definition lists, skipping parenthesis and bracket groups

Parameters:

test_str (str) – Text string

Returns:

[description]

Return type:

list[str] | None

Examples

>>> separate_def_list('var1, var2, var3')
['var1', 'var2', 'var3']
>>> separate_def_list('var, init_var(3) = [1,2,3], array(3,3)')
['var', 'init_var(3) = [1,2,3]', 'array(3,3)']
fortls.helper_functions.set_keyword_ordering(sorted)
fortls.helper_functions.strip_line_label(line)

Strip leading numeric line label

Parameters:

line (str) – Text line

Returns:

Output string, Line label returns None if no line label present

Return type:

tuple[str, str | None]

fortls.helper_functions.strip_strings(in_line, maintain_len=False)

Strips string literals from code line

Parameters:
  • in_line (str) – Text string

  • maintain_len (bool, optional) – Maintain the len(in_line) in the output string, by default False

Returns:

Stripped string

Return type:

str

fortls.interface module

class fortls.interface.SetAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)

Bases: Action

fortls.interface.cli(name='fortls')

Parses the command line arguments to the Language Server

Returns:

command line arguments

Return type:

argparse.ArgumentParser

fortls.json_templates module

fortls.json_templates.change_json(new_text, sln, sch, eln=None, ech=None)
fortls.json_templates.diagnostic_json(sln, sch, eln, ech, msg, sev)
fortls.json_templates.location_json(uri, sln, sch, eln=None, ech=None)
fortls.json_templates.range_json(sln, sch, eln=None, ech=None)
fortls.json_templates.symbol_json(name, kind, uri, sln, sch, eln=None, ech=None, container_name=None)
fortls.json_templates.uri_json(uri, sln, sch, eln=None, ech=None)

fortls.jsonrpc module

class fortls.jsonrpc.JSONRPC2Connection(conn=None)

Bases: object

read_message(want=None)

Read a JSON RPC message sent over the current connection. If id is None, the next available message is returned.

send_notification(method, params)
send_request(method, params)
send_request_batch(requests)

Pipelines requests and returns responses.

The responses is a generator where the nth response corresponds with the nth request. Users must read the generator until the end, otherwise you will leak a thread.

write_error(rid, code, message, data=None)
write_response(rid, result)
exception fortls.jsonrpc.JSONRPC2ProtocolError

Bases: Exception

class fortls.jsonrpc.ReadWriter(reader, writer)

Bases: object

read(*args)
readline(*args)
write(out)
class fortls.jsonrpc.TCPReadWriter(reader, writer)

Bases: ReadWriter

read(*args)
readline(*args)
write(out)
fortls.jsonrpc.deque_find_and_pop(d, f)
fortls.jsonrpc.path_from_uri(uri)
Return type:

str

fortls.jsonrpc.path_to_uri(path)
Return type:

str

fortls.jsonrpc.read_rpc_messages(content)
fortls.jsonrpc.write_rpc_notification(method, params)
fortls.jsonrpc.write_rpc_request(rid, method, params)

fortls.langserver module

exception fortls.langserver.JSONRPC2Error(code, message, data=None)

Bases: Exception

class fortls.langserver.LangServer(conn, settings)

Bases: object

static file_init(filepath, pp_defs, pp_suffixes, include_dirs, sort)

Initialise a Fortran file

Parameters:
  • filepath (str) – Path to file

  • pp_defs (dict) – Preprocessor definitions

  • pp_suffixes (list[str]) – Preprocessor file extension, additional to default

  • include_dirs (set[str]) – Preprocessor only include directories, not used by normal parser

  • sort (bool) – Whether or not keywords should be sorted

Returns:

A Fortran file object or a string containing the error message

Return type:

fortran_file | str

get_all_references(def_obj, type_mem, file_obj=None)
get_definition(def_file, def_line, def_char, hover_req=False)

Return the Fortran object for the definition that matches the Fortran file, line number, column number

Parameters:
  • def_file (fortran_file) – File to query

  • def_line (int) – Line position in the file

  • def_char (int) – Column position in the file

  • hover_req (bool, optional) – Flag to enable if calling from a hover request, by default False

Returns:

Fortran object

Return type:

fortran_var | fortran_include | None

get_diagnostics(uri)
handle(request)
post_message(msg, severity=1, exc_info=False)
run()
send_diagnostics(uri)
serve_autocomplete(request)
serve_codeActions(request)
serve_default(request)

Raise an error in the Language Server

Parameters:

request (dict) – client dictionary with requests

Raises:

JSONRPC2Error – error with code -32601

serve_definition(request)
serve_document_symbols(request)
serve_exit(request)
Return type:

None

serve_hover(request)
serve_implementation(request)
serve_initialize(request)
serve_onChange(request)
serve_onClose(request)
serve_onOpen(request)
serve_onSave(request, did_open=False, did_close=False)
serve_references(request)
serve_rename(request)
serve_signature(request)
serve_workspace_symbol(request)
update_workspace_file(filepath, read_file=False, allow_empty=False, update_links=False)
workspace_init()

Initialise the workspace root across multiple threads

fortls.langserver.update_recursion_limit(limit)

Update the recursion limit of the Python interpreter

Parameters:

limit (int) – New recursion limit

Return type:

None

Examples

>>> update_recursion_limit(10000)

fortls.regex_patterns module

class fortls.regex_patterns.FortranRegularExpressions(USE=re.compile('[ ]*USE([, ]+(?:INTRINSIC|NON_INTRINSIC))?[ :]+(\\\\w*)([, ]+ONLY[ :]+)?', re.IGNORECASE), IMPORT=re.compile('[ ]*IMPORT(?:[ ]*,[ ]*(?P<spec>ALL|NONE)|[ ]*,[ ]*(?P<only>ONLY)[ ]*:[ ]*(?P<start1>[\\\\w_])|[ ]+(?:::[ ]*)?(?P<start2>[\\\\w_]))?', re.IGNORECASE), INCLUDE=re.compile('[ ]*INCLUDE[ :]*[\\\\\\'\\\\"]([^\\\\\\'\\\\"]*)', re.IGNORECASE), CONTAINS=re.compile('[ ]*(CONTAINS)[ ]*$', re.IGNORECASE), IMPLICIT=re.compile('[ ]*IMPLICIT[ ]+([a-z]*)', re.IGNORECASE), SUB_MOD=re.compile('[ ]*(?!<[,\\\\()][ ]*)\\\\b(PURE|IMPURE|ELEMENTAL|RECURSIVE)\\\\b(?![,\\\\)][ ]*)', re.IGNORECASE), SUB=re.compile('[ ]*SUBROUTINE[ ]+(\\\\w+)', re.IGNORECASE), END_SUB=re.compile('SUBROUTINE', re.IGNORECASE), FUN=re.compile('[ ]*FUNCTION[ ]+(\\\\w+)', re.IGNORECASE), RESULT=re.compile('RESULT[ ]*\\\\((\\\\w*)\\\\)', re.IGNORECASE), END_FUN=re.compile('FUNCTION', re.IGNORECASE), MOD=re.compile('[ ]*MODULE[ ]+(\\\\w+)', re.IGNORECASE), END_MOD=re.compile('MODULE', re.IGNORECASE), SUBMOD=re.compile('[ ]*SUBMODULE[ ]*\\\\(', re.IGNORECASE), END_SMOD=re.compile('SUBMODULE', re.IGNORECASE), END_PRO=re.compile('(MODULE)?[ ]*PROCEDURE', re.IGNORECASE), BLOCK=re.compile('[ ]*([a-z_]\\\\w*[ ]*:[ ]*)?BLOCK|CRITICAL(?!\\\\w)', re.IGNORECASE), END_BLOCK=re.compile('BLOCK|CRITICAL', re.IGNORECASE), DO=re.compile('[ ]*(?:[a-z_]\\\\w*[ ]*:[ ]*)?DO([ ]+[0-9]*|$)', re.IGNORECASE), END_DO=re.compile('DO', re.IGNORECASE), WHERE=re.compile('[ ]*WHERE[ ]*\\\\(', re.IGNORECASE), END_WHERE=re.compile('WHERE', re.IGNORECASE), IF=re.compile('[ ]*(?:[a-z_]\\\\w*[ ]*:[ ]*)?IF[ ]*\\\\(', re.IGNORECASE), THEN=re.compile('\\\\)[ ]*THEN$', re.IGNORECASE), END_IF=re.compile('IF', re.IGNORECASE), ASSOCIATE=re.compile('[ ]*ASSOCIATE[ ]*\\\\(', re.IGNORECASE), END_ASSOCIATE=re.compile('ASSOCIATE', re.IGNORECASE), END_FIXED=re.compile('[ ]*([0-9]*)[ ]*CONTINUE', re.IGNORECASE), SELECT=re.compile('[ ]*(?:[a-z_]\\\\w*[ ]*:[ ]*)?SELECT[ ]*(CASE|TYPE)[ ]*\\\\(([\\\\w=> ]*)', re.IGNORECASE), SELECT_TYPE=re.compile('[ ]*(TYPE|CLASS)[ ]+IS[ ]*\\\\(([\\\\w ]*)', re.IGNORECASE), SELECT_DEFAULT=re.compile('[ ]*CLASS[ ]+DEFAULT', re.IGNORECASE), END_SELECT=re.compile('SELECT', re.IGNORECASE), PROG=re.compile('[ ]*PROGRAM[ ]+(\\\\w+)', re.IGNORECASE), END_PROG=re.compile('PROGRAM', re.IGNORECASE), INT=re.compile('[ ]*(ABSTRACT)?[ ]*INTERFACE[ ]*(\\\\w*)', re.IGNORECASE), END_INT=re.compile('INTERFACE', re.IGNORECASE), END_WORD=re.compile('[ ]*END[ ]*(DO|WHERE|IF|BLOCK|CRITICAL|ASSOCIATE|SELECT|TYPE|ENUM|MODULE|SUBMODULE|PROGRAM|INTERFACE|SUBROUTINE|FUNCTION|PROCEDURE|FORALL)?([ ]+(?!\\\\W)|$)', re.IGNORECASE), TYPE_DEF=re.compile('[ ]*(TYPE)[, :]+', re.IGNORECASE), EXTENDS=re.compile('EXTENDS[ ]*\\\\((\\\\w*)\\\\)', re.IGNORECASE), GENERIC_PRO=re.compile('[ ]*(GENERIC)[, ]*(PRIVATE|PUBLIC)?[ ]*::[ ]*[a-z]', re.IGNORECASE), GEN_ASSIGN=re.compile('(ASSIGNMENT|OPERATOR)\\\\(', re.IGNORECASE), END_TYPED=re.compile('TYPE', re.IGNORECASE), ENUM_DEF=re.compile('[ ]*ENUM[, ]+', re.IGNORECASE), END_ENUMD=re.compile('ENUM', re.IGNORECASE), VAR=re.compile('[ ]*(INTEGER|REAL|DOUBLE[ ]*PRECISION|COMPLEX|DOUBLE[ ]*COMPLEX|CHARACTER|LOGICAL|PROCEDURE|EXTERNAL|CLASS|TYPE)', re.IGNORECASE), KIND_SPEC=re.compile('[ ]*([*]?\\\\([ ]*[\\\\w*:]|\\\\*[ ]*[0-9:]*)', re.IGNORECASE), KEYWORD_LIST=re.compile('[ ]*,[ ]*(PUBLIC|PRIVATE|ALLOCATABLE|POINTER|TARGET|DIMENSION[ ]*\\\\(|OPTIONAL|INTENT[ ]*\\\\([ ]*(?:IN|OUT|IN[ ]*OUT)[ ]*\\\\)|DEFERRED|NOPASS|PASS[ ]*\\\\(\\\\w*\\\\)|SAVE|PARAMETER|EXTERNAL|CONTIGUOUS)', re.IGNORECASE), PARAMETER_VAL=re.compile('\\\\w*[\\\\s\\\\&]*=(([\\\\s\\\\&]*[\\\\w\\\\.\\\\-\\\\+\\\\*\\\\/\\\\\\'\\\\"])*)', re.IGNORECASE), TATTR_LIST=re.compile('[ ]*,[ ]*(PUBLIC|PRIVATE|ABSTRACT|EXTENDS\\\\(\\\\w*\\\\))', re.IGNORECASE), VIS=re.compile('[ ]*\\\\b(PUBLIC|PRIVATE)\\\\b', re.IGNORECASE), WORD=re.compile('[a-z_][\\\\w\\\\$]*', re.IGNORECASE), NUMBER=re.compile('[\\\\+\\\\-]?(\\\\b\\\\d+\\\\.?\\\\d*|\\\\.\\\\d+)(_\\\\w+|d[\\\\+\\\\-]?\\\\d+|e[\\\\+\\\\-]?\\\\d+(_\\\\w+)?)?(?!\\\\w)', re.IGNORECASE), LOGICAL=re.compile('.true.|.false.', re.IGNORECASE), SUB_PAREN=re.compile('\\\\([\\\\w, ]*\\\\)', re.IGNORECASE), SQ_STRING=re.compile("\\\\'[^\\\\']*\\\\'", re.IGNORECASE), DQ_STRING=re.compile('\\\\"[^\\\\"]*\\\\"', re.IGNORECASE), LINE_LABEL=re.compile('[ ]*([0-9]+)[ ]+', re.IGNORECASE), NON_DEF=re.compile('[ ]*(CALL[ ]+[a-z_]|[a-z_][\\\\w%]*[ ]*=)', re.IGNORECASE), FIXED_COMMENT=re.compile('([!cd*])', re.IGNORECASE), FIXED_CONT=re.compile('( {5}[\\\\S])'), FIXED_DOC=re.compile('(?:[!cd\\\\*])([<>!])', re.IGNORECASE), FIXED_OPENMP=re.compile('[!c\\\\*]\\\\$OMP', re.IGNORECASE), FREE_COMMENT=re.compile('([ ]*!)'), FREE_CONT=re.compile('([ ]*&)'), FREE_DOC=re.compile('[ ]*!([<>!])'), FREE_OPENMP=re.compile('[ ]*!\\\\$OMP', re.IGNORECASE), FREE_FORMAT_TEST=re.compile('[ ]{1,4}[a-z]', re.IGNORECASE), DEFINED=re.compile('defined[ ]*\\\\(?[ ]*([a-z_]\\\\w*)[ ]*\\\\)?', re.IGNORECASE), PP_REGEX=re.compile('[ ]*#[ ]*(if |ifdef|ifndef|else|elif|endif)', re.IGNORECASE), PP_DEF=re.compile('[ ]*#[ ]*(define|undef|undefined)[ ]*(\\\\w+)(\\\\([ ]*([ \\\\w,]*?)[ ]*\\\\))?', re.IGNORECASE), PP_DEF_TEST=re.compile('(![ ]*)?defined[ ]*\\\\([ ]*(\\\\w*)[ ]*\\\\)$', re.IGNORECASE), PP_INCLUDE=re.compile('[ ]*#[ ]*include[ ]*([\\\\"\\\\w\\\\.]*)', re.IGNORECASE), PP_ANY=re.compile('^[ ]*#:?[ ]*(\\\\w+)'), CALL=re.compile('[ ]*CALL[ ]+[\\\\w%]*$', re.IGNORECASE), INT_STMNT=re.compile('^[ ]*[a-z]*$', re.IGNORECASE), TYPE_STMNT=re.compile('[ ]*(TYPE|CLASS)[ ]*(IS)?[ ]*$', re.IGNORECASE), PROCEDURE_STMNT=re.compile('[ ]*(PROCEDURE)[ ]*$', re.IGNORECASE), PRO_LINK=re.compile('[ ]*(MODULE[ ]*PROCEDURE )', re.IGNORECASE), SCOPE_DEF=re.compile('[ ]*(MODULE|PROGRAM|SUBROUTINE|FUNCTION|INTERFACE)[ ]+', re.IGNORECASE), END=re.compile('[ ]*(END)( |MODULE|PROGRAM|SUBROUTINE|FUNCTION|PROCEDURE|TYPE|DO|IF|SELECT)?', re.IGNORECASE), CLASS_VAR=re.compile('(TYPE|CLASS)[ ]*\\\\(', re.IGNORECASE), DEF_KIND=re.compile('(\\\\w*)[ ]*\\\\((?:KIND|LEN)?[ =]*(\\\\w*)', re.IGNORECASE), OBJBREAK=re.compile('[\\\\/\\\\-(.,+*<>=: ]', re.IGNORECASE))

Bases: object

ASSOCIATE: Pattern = re.compile('[ ]*ASSOCIATE[ ]*\\(', re.IGNORECASE)
BLOCK: Pattern = re.compile('[ ]*([a-z_]\\w*[ ]*:[ ]*)?BLOCK|CRITICAL(?!\\w)', re.IGNORECASE)
CALL: Pattern = re.compile('[ ]*CALL[ ]+[\\w%]*$', re.IGNORECASE)
CLASS_VAR: Pattern = re.compile('(TYPE|CLASS)[ ]*\\(', re.IGNORECASE)
CONTAINS: Pattern = re.compile('[ ]*(CONTAINS)[ ]*$', re.IGNORECASE)
DEFINED: Pattern = re.compile('defined[ ]*\\(?[ ]*([a-z_]\\w*)[ ]*\\)?', re.IGNORECASE)
DEF_KIND: Pattern = re.compile('(\\w*)[ ]*\\((?:KIND|LEN)?[ =]*(\\w*)', re.IGNORECASE)
DO: Pattern = re.compile('[ ]*(?:[a-z_]\\w*[ ]*:[ ]*)?DO([ ]+[0-9]*|$)', re.IGNORECASE)
DQ_STRING: Pattern = re.compile('\\"[^\\"]*\\"', re.IGNORECASE)
END: Pattern = re.compile('[ ]*(END)( |MODULE|PROGRAM|SUBROUTINE|FUNCTION|PROCEDURE|TYPE|DO|IF|SELECT)?', re.IGNORECASE)
END_ASSOCIATE: Pattern = re.compile('ASSOCIATE', re.IGNORECASE)
END_BLOCK: Pattern = re.compile('BLOCK|CRITICAL', re.IGNORECASE)
END_DO: Pattern = re.compile('DO', re.IGNORECASE)
END_ENUMD: Pattern = re.compile('ENUM', re.IGNORECASE)
END_FIXED: Pattern = re.compile('[ ]*([0-9]*)[ ]*CONTINUE', re.IGNORECASE)
END_FUN: Pattern = re.compile('FUNCTION', re.IGNORECASE)
END_IF: Pattern = re.compile('IF', re.IGNORECASE)
END_INT: Pattern = re.compile('INTERFACE', re.IGNORECASE)
END_MOD: Pattern = re.compile('MODULE', re.IGNORECASE)
END_PRO: Pattern = re.compile('(MODULE)?[ ]*PROCEDURE', re.IGNORECASE)
END_PROG: Pattern = re.compile('PROGRAM', re.IGNORECASE)
END_SELECT: Pattern = re.compile('SELECT', re.IGNORECASE)
END_SMOD: Pattern = re.compile('SUBMODULE', re.IGNORECASE)
END_SUB: Pattern = re.compile('SUBROUTINE', re.IGNORECASE)
END_TYPED: Pattern = re.compile('TYPE', re.IGNORECASE)
END_WHERE: Pattern = re.compile('WHERE', re.IGNORECASE)
END_WORD: Pattern = re.compile('[ ]*END[ ]*(DO|WHERE|IF|BLOCK|CRITICAL|ASSOCIATE|SELECT|TYPE|ENUM|MODULE|SUBMODULE|PROGRAM|INTERFACE|SUBROUTINE|FUNCTION|PROCEDURE|FORALL)?([ ]+(?!\\W)|$)', re.IGNORECASE)
ENUM_DEF: Pattern = re.compile('[ ]*ENUM[, ]+', re.IGNORECASE)
EXTENDS: Pattern = re.compile('EXTENDS[ ]*\\((\\w*)\\)', re.IGNORECASE)
FIXED_COMMENT: Pattern = re.compile('([!cd*])', re.IGNORECASE)
FIXED_CONT: Pattern = re.compile('( {5}[\\S])')
FIXED_DOC: Pattern = re.compile('(?:[!cd\\*])([<>!])', re.IGNORECASE)
FIXED_OPENMP: Pattern = re.compile('[!c\\*]\\$OMP', re.IGNORECASE)
FREE_COMMENT: Pattern = re.compile('([ ]*!)')
FREE_CONT: Pattern = re.compile('([ ]*&)')
FREE_DOC: Pattern = re.compile('[ ]*!([<>!])')
FREE_FORMAT_TEST: Pattern = re.compile('[ ]{1,4}[a-z]', re.IGNORECASE)
FREE_OPENMP: Pattern = re.compile('[ ]*!\\$OMP', re.IGNORECASE)
FUN: Pattern = re.compile('[ ]*FUNCTION[ ]+(\\w+)', re.IGNORECASE)
GENERIC_PRO: Pattern = re.compile('[ ]*(GENERIC)[, ]*(PRIVATE|PUBLIC)?[ ]*::[ ]*[a-z]', re.IGNORECASE)
GEN_ASSIGN: Pattern = re.compile('(ASSIGNMENT|OPERATOR)\\(', re.IGNORECASE)
IF: Pattern = re.compile('[ ]*(?:[a-z_]\\w*[ ]*:[ ]*)?IF[ ]*\\(', re.IGNORECASE)
IMPLICIT: Pattern = re.compile('[ ]*IMPLICIT[ ]+([a-z]*)', re.IGNORECASE)
IMPORT: Pattern = re.compile('[ ]*IMPORT(?:[ ]*,[ ]*(?P<spec>ALL|NONE)|[ ]*,[ ]*(?P<only>ONLY)[ ]*:[ ]*(?P<start1>[\\w_])|[ ]+(?:::[ ]*)?(?P<start2>[\\w_]))?', re.IGNORECASE)
INCLUDE: Pattern = re.compile('[ ]*INCLUDE[ :]*[\\\'\\"]([^\\\'\\"]*)', re.IGNORECASE)
INT: Pattern = re.compile('[ ]*(ABSTRACT)?[ ]*INTERFACE[ ]*(\\w*)', re.IGNORECASE)
INT_STMNT: Pattern = re.compile('^[ ]*[a-z]*$', re.IGNORECASE)
KEYWORD_LIST: Pattern = re.compile('[ ]*,[ ]*(PUBLIC|PRIVATE|ALLOCATABLE|POINTER|TARGET|DIMENSION[ ]*\\(|OPTIONAL|INTENT[ ]*\\([ ]*(?:IN|OUT|IN[ ]*OUT)[ ]*\\)|DEFERRED|NOPASS|PASS[ ]*\\(\\w*\\)|SAVE|PARAMETER|EXTERNAL|CONTIGUOUS)', re.IGNORECASE)
KIND_SPEC: Pattern = re.compile('[ ]*([*]?\\([ ]*[\\w*:]|\\*[ ]*[0-9:]*)', re.IGNORECASE)
LINE_LABEL: Pattern = re.compile('[ ]*([0-9]+)[ ]+', re.IGNORECASE)
LOGICAL: Pattern = re.compile('.true.|.false.', re.IGNORECASE)
MOD: Pattern = re.compile('[ ]*MODULE[ ]+(\\w+)', re.IGNORECASE)
NON_DEF: Pattern = re.compile('[ ]*(CALL[ ]+[a-z_]|[a-z_][\\w%]*[ ]*=)', re.IGNORECASE)
NUMBER: Pattern = re.compile('[\\+\\-]?(\\b\\d+\\.?\\d*|\\.\\d+)(_\\w+|d[\\+\\-]?\\d+|e[\\+\\-]?\\d+(_\\w+)?)?(?!\\w)', re.IGNORECASE)
OBJBREAK: Pattern = re.compile('[\\/\\-(.,+*<>=: ]', re.IGNORECASE)
PARAMETER_VAL: Pattern = re.compile('\\w*[\\s\\&]*=(([\\s\\&]*[\\w\\.\\-\\+\\*\\/\\\'\\"])*)', re.IGNORECASE)
PP_ANY: Pattern = re.compile('^[ ]*#:?[ ]*(\\w+)')
PP_DEF: Pattern = re.compile('[ ]*#[ ]*(define|undef|undefined)[ ]*(\\w+)(\\([ ]*([ \\w,]*?)[ ]*\\))?', re.IGNORECASE)
PP_DEF_TEST: Pattern = re.compile('(![ ]*)?defined[ ]*\\([ ]*(\\w*)[ ]*\\)$', re.IGNORECASE)
PP_INCLUDE: Pattern = re.compile('[ ]*#[ ]*include[ ]*([\\"\\w\\.]*)', re.IGNORECASE)
PP_REGEX: Pattern = re.compile('[ ]*#[ ]*(if |ifdef|ifndef|else|elif|endif)', re.IGNORECASE)
PROCEDURE_STMNT: Pattern = re.compile('[ ]*(PROCEDURE)[ ]*$', re.IGNORECASE)
PROG: Pattern = re.compile('[ ]*PROGRAM[ ]+(\\w+)', re.IGNORECASE)
RESULT: Pattern = re.compile('RESULT[ ]*\\((\\w*)\\)', re.IGNORECASE)
SCOPE_DEF: Pattern = re.compile('[ ]*(MODULE|PROGRAM|SUBROUTINE|FUNCTION|INTERFACE)[ ]+', re.IGNORECASE)
SELECT: Pattern = re.compile('[ ]*(?:[a-z_]\\w*[ ]*:[ ]*)?SELECT[ ]*(CASE|TYPE)[ ]*\\(([\\w=> ]*)', re.IGNORECASE)
SELECT_DEFAULT: Pattern = re.compile('[ ]*CLASS[ ]+DEFAULT', re.IGNORECASE)
SELECT_TYPE: Pattern = re.compile('[ ]*(TYPE|CLASS)[ ]+IS[ ]*\\(([\\w ]*)', re.IGNORECASE)
SQ_STRING: Pattern = re.compile("\\'[^\\']*\\'", re.IGNORECASE)
SUB: Pattern = re.compile('[ ]*SUBROUTINE[ ]+(\\w+)', re.IGNORECASE)
SUBMOD: Pattern = re.compile('[ ]*SUBMODULE[ ]*\\(', re.IGNORECASE)
SUB_MOD: Pattern = re.compile('[ ]*(?!<[,\\()][ ]*)\\b(PURE|IMPURE|ELEMENTAL|RECURSIVE)\\b(?![,\\)][ ]*)', re.IGNORECASE)

Parse procedure keywords but not if they start with , or ( or end with , or ) This is to avoid parsing as keywords variables named pure, impure, etc.

SUB_PAREN: Pattern = re.compile('\\([\\w, ]*\\)', re.IGNORECASE)
TATTR_LIST: Pattern = re.compile('[ ]*,[ ]*(PUBLIC|PRIVATE|ABSTRACT|EXTENDS\\(\\w*\\))', re.IGNORECASE)
THEN: Pattern = re.compile('\\)[ ]*THEN$', re.IGNORECASE)
TYPE_DEF: Pattern = re.compile('[ ]*(TYPE)[, :]+', re.IGNORECASE)
TYPE_STMNT: Pattern = re.compile('[ ]*(TYPE|CLASS)[ ]*(IS)?[ ]*$', re.IGNORECASE)
USE: Pattern = re.compile('[ ]*USE([, ]+(?:INTRINSIC|NON_INTRINSIC))?[ :]+(\\w*)([, ]+ONLY[ :]+)?', re.IGNORECASE)
VAR: Pattern = re.compile('[ ]*(INTEGER|REAL|DOUBLE[ ]*PRECISION|COMPLEX|DOUBLE[ ]*COMPLEX|CHARACTER|LOGICAL|PROCEDURE|EXTERNAL|CLASS|TYPE)', re.IGNORECASE)
VIS: Pattern = re.compile('[ ]*\\b(PUBLIC|PRIVATE)\\b', re.IGNORECASE)
WHERE: Pattern = re.compile('[ ]*WHERE[ ]*\\(', re.IGNORECASE)
WORD: Pattern = re.compile('[a-z_][\\w\\$]*', re.IGNORECASE)
fortls.regex_patterns.create_src_file_exts_regex(input_exts=[])

Create a REGEX for which sources the Language Server should parse.

Default extensions are (case insensitive): F F03 F05 F08 F18 F77 F90 F95 FOR FPP

Parameters:

input_exts (list[str], optional) – Additional list of file extensions to parse, in Python REGEX format that means special characters must be escaped , by default []

Examples

>>> regex = create_src_file_exts_regex([r"\.fypp", r"\.inc"])
>>> regex.search("test.fypp")
<re.Match object; span=(4, 9), match='.fypp'>
>>> regex.search("test.inc")
<re.Match object; span=(4, 8), match='.inc'>
>>> regex = create_src_file_exts_regex([r"\.inc.*"])
>>> regex.search("test.inc.1")
<re.Match object; span=(4, 10), match='.inc.1'>

Invalid regex expressions will cause the function to revert to the default extensions

>>> regex = create_src_file_exts_regex(["*.inc"])
>>> regex.search("test.inc") is None
True
Returns:

A compiled regular expression for matching file extensions

Return type:

Pattern[str]

fortls.regex_patterns.create_src_file_exts_str(input_exts=[])

This is a version of create_src_file_exts_regex that takes a list sanitises the list of input_exts before compiling the regex. For more info see create_src_file_exts_regex

Return type:

Pattern[str]

fortls.schema module

fortls.schema.create_schema(root=None)

fortls.version module

Module contents