fortls package#
Subpackages#
- fortls.parsers package
- Subpackages
- fortls.parsers.internal package
- Submodules
- fortls.parsers.internal.associate module
- fortls.parsers.internal.ast module
- fortls.parsers.internal.base module
- fortls.parsers.internal.block module
- fortls.parsers.internal.diagnostics module
- fortls.parsers.internal.do module
- fortls.parsers.internal.enum module
- fortls.parsers.internal.function module
- fortls.parsers.internal.if_block module
- fortls.parsers.internal.imports module
- fortls.parsers.internal.include module
- fortls.parsers.internal.interface module
- fortls.parsers.internal.intrinsics module
- fortls.parsers.internal.method module
- fortls.parsers.internal.module module
- fortls.parsers.internal.parser module
- fortls.parsers.internal.program module
- fortls.parsers.internal.scope module
- fortls.parsers.internal.select module
- fortls.parsers.internal.submodule module
- fortls.parsers.internal.subroutine module
- fortls.parsers.internal.type module
- fortls.parsers.internal.use module
- fortls.parsers.internal.utilities module
- fortls.parsers.internal.variable module
- fortls.parsers.internal.where module
- Module contents
- fortls.parsers.internal package
- Module contents
- 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
fortls.debug module#
- 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_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.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.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
- pro_links: list[str]#
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
- 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
- class fortls.ftypes.SmodInfo(name, parent)#
Bases:
object
Holds information about Fortran SUBMODULES
- 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.
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:
- Returns:
True if file_lines are of Fixed Fortran style
- Return type:
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
- 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:
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
- fortls.helper_functions.find_word_in_line(line, word)#
Find Fortran word in line
- fortls.helper_functions.fortran_md(code, docs)#
Convert Fortran code to markdown
- 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
andpre_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:
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:
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
andend
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:
- Returns:
Tuple of arguments as a string and snippet string
- Return type:
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
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:
- 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-fnmatchroot_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:
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
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
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:
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)#
- 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.read_rpc_messages(content)#
- fortls.jsonrpc.write_rpc_notification(method, params)#
- fortls.jsonrpc.write_rpc_request(rid, method, params)#
fortls.langserver module#
- class fortls.langserver.LangServer(conn, settings)#
Bases:
object
- static file_init(filepath, pp_defs, pp_suffixes, include_dirs, sort)#
Initialise a Fortran file
- Parameters:
- 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:
- 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_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.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
-
END:
Pattern
= re.compile('[ ]*(END)( |MODULE|PROGRAM|SUBROUTINE|FUNCTION|PROCEDURE|TYPE|DO|IF|SELECT)?', 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)#
-
GENERIC_PRO:
Pattern
= re.compile('[ ]*(GENERIC)[, ]*(PRIVATE|PUBLIC)?[ ]*::[ ]*[a-z]', re.IGNORECASE)#
-
IMPORT:
Pattern
= re.compile('[ ]*IMPORT(?:[ ]*,[ ]*(?P<spec>ALL|NONE)|[ ]*,[ ]*(?P<only>ONLY)[ ]*:[ ]*(?P<start1>[\\w_])|[ ]+(?:::[ ]*)?(?P<start2>[\\w_]))?', 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)#
-
NUMBER:
Pattern
= re.compile('[\\+\\-]?(\\b\\d+\\.?\\d*|\\.\\d+)(_\\w+|d[\\+\\-]?\\d+|e[\\+\\-]?\\d+(_\\w+)?)?(?!\\w)', re.IGNORECASE)#
-
PARAMETER_VAL:
Pattern
= re.compile('\\w*[\\s\\&]*=(([\\s\\&]*[\\w\\.\\-\\+\\*\\/\\\'\\"])*)', re.IGNORECASE)#
-
PP_DEF:
Pattern
= re.compile('[ ]*#[ ]*(define|undef|undefined)[ ]*(\\w+)(\\([ ]*([ \\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)#
-
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.
-
TATTR_LIST:
Pattern
= re.compile('[ ]*,[ ]*(PUBLIC|PRIVATE|ABSTRACT|EXTENDS\\(\\w*\\))', re.IGNORECASE)#
-
USE:
Pattern
= re.compile('[ ]*USE([, ]+(?:INTRINSIC|NON_INTRINSIC))?[ :]+(\\w*)([, ]+ONLY[ :]+)?', re.IGNORECASE)#
-
END:
- 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