loki.frontend.regex

The implementation of a regex parser frontend

This is intended to allow for fast, partial extraction of IR objects from Fortran source files without the need to generate a complete parse tree.

Module Attributes

HAVE_REGEX

Indicate that the regex frontend is available.

PATTERN_REGISTRY

A global registry of all available patterns

Functions

parse_regex_source(source[, parser_classes, ...])

Generate a reduced Loki IR from regex parsing of the given Fortran source

Classes

CallPattern()

Pattern to match CallStatement nodes

GenericBindingPattern()

Pattern to match generic bindings

ImportPattern()

Pattern to match Import nodes

InterfacePattern()

Pattern to match Interface objects

ModulePattern()

Pattern to match Module objects

Pattern(pattern[, flags])

Base class for patterns used in the REGEX frontend

ProcedureBindingPattern()

Pattern to match procedure bindings

ProcedureStatementPattern()

Pattern to match procedure statements in interfaces

RegexParserClass(value)

Classes to configure active patterns in the REGEX frontend

SubroutineFunctionPattern()

Pattern to match Subroutine objects

TypedefPattern()

Pattern to match TypeDef objects

VariableDeclarationPattern()

Pattern to match VariableDeclaration nodes.

class RegexParserClass(value)

Bases: Flag

Classes to configure active patterns in the REGEX frontend

Every Pattern in the frontend is categorized as one of these classes. By specifying some (or all of them) as parser_classes to parse_regex_source, pattern matching can be switched on and off for some pattern classes, and thus the overall parse time reduced.

EmptyClass = 0
ProgramUnitClass = 1
InterfaceClass = 2
ImportClass = 4
TypeDefClass = 8
DeclarationClass = 16
CallClass = 32
AllClasses = 63
parse_regex_source(source, parser_classes=None, scope=None)

Generate a reduced Loki IR from regex parsing of the given Fortran source

The IR nodes that should be matched can be configured via parser_classes. Any non-matched source code snippets are retained as RawSource objects.

Parameters:
  • source (str or Source) – The raw source string

  • parser_classes (RegexParserClass) – Active parser classes for matching

  • scope (Scope, optional) – The enclosing parent scope

HAVE_REGEX = True

Indicate that the regex frontend is available.