fparser.two.C99Preprocessor

C99 Preprocessor Syntax Rules.

Module Contents

Classes

Cpp_Pp_Tokens

Generic class for preprocessor tokens that form the right hand

Cpp_If_Stmt

C99 6.10.1 Conditional inclusion

Cpp_Elif_Stmt

C99 6.10.1 Conditional inclusion

Cpp_Else_Stmt

C99 6.10.1 Conditional inclusion

Cpp_Endif_Stmt

C99 6.10.1 Conditional inclusion

Cpp_Include_Stmt

C99 6.10.2 Source file inclusion

Cpp_Macro_Stmt

C99 6.10.3 Macro replacement

Cpp_Macro_Identifier

Implements the matching of a macro identifier.

Cpp_Macro_Identifier_List

Implements the matching of an identifier list in a macro definition.

Cpp_Undef_Stmt

Implements the matching of a preprocessor undef statement for a macro.

Cpp_Line_Stmt

C99 6.10.4 Line control

Cpp_Error_Stmt

C99 6.10.5 Error directive

Cpp_Warning_Stmt

Not actually part of C99 but supported by most preprocessors and

Cpp_Null_Stmt

C99 6.10.7 Null directive

Functions

match_cpp_directive(reader)

Creates single-line C99 preprocessor directive object from the

Attributes

CPP_CLASS_NAMES

fparser.two.C99Preprocessor.CPP_CLASS_NAMES = ['Cpp_If_Stmt', 'Cpp_Elif_Stmt', 'Cpp_Else_Stmt', 'Cpp_Endif_Stmt', 'Cpp_Include_Stmt',...[source]
fparser.two.C99Preprocessor.match_cpp_directive(reader)[source]

Creates single-line C99 preprocessor directive object from the current line, if any is found.

Parameters:

reader (fparser.common.readfortran.FortranFileReader or fparser.common.readfortran.FortranStringReader) – the fortran file reader containing the line of code that we are trying to match.

Returns:

the matched preprocessor directive object or None.

Return type:

one of (fparser.two.C99Preprocess.Cpp_*_Stmt,) or NoneType

class fparser.two.C99Preprocessor.Cpp_Pp_Tokens(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Generic class for preprocessor tokens that form the right hand side of a preprocessor directive (such as #error, #line, #if, etc.).

subclass_names = [][source]
static match(string)[source]

Implements the matching for arbitrary preprocessor tokens that form the right hand side of a preprocessor directive. It does not impose any restrictions other than the string not being empty.

Parameters:

string (str) – the string to be matched as pp-tokens.

Returns:

a 1-tuple containing the matched string or None.

Return type:

(str,) or NoneType

tostr()[source]
Returns:

this pp-tokens as a string.

Return type:

str

class fparser.two.C99Preprocessor.Cpp_If_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.WORDClsBase

C99 6.10.1 Conditional inclusion

if-stmt is # if constant-expression new-line

or ifdef identifier new-line or ifndef identifier new-line

subclass_names = [][source]
use_names = ['Cpp_Macro_Identifier', 'Cpp_Pp_Tokens'][source]
_regex[source]
_if_pattern[source]
_def_pattern = ()[source]
static match(string)[source]

Implements the matching for an if preprocessor directive (or its variations ifdef, ifndef). For ifdef and ifndef statements it matches the macro identifier using fparser.two.C99Preprocesser.Cpp_Macro_Identifier otherwise it uses fparser.two.C99Preprocessor.Cpp_Pp_Tokens to accept any non-empty string as rhs.

Parameters:

string (str) – the string to match with as an if statement.

Returns:

a tuple of size 2 containing the statement’s keyword and the right hand side, or None if there is no match.

Return type:

(str, py:class:fparser.two.C99Preprocessor.Cpp_Macro_Identifier) or (str, py:class:fparser.two.C99Preprocessor.Cpp_Pp_Tokens) or NoneType

tostr()[source]
Returns:

this if-stmt as a string.

Return type:

str

class fparser.two.C99Preprocessor.Cpp_Elif_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.WORDClsBase

C99 6.10.1 Conditional inclusion

elif-stmt is # elif constant-expression new-line

subclass_names = [][source]
use_names = ['Cpp_Pp_Tokens'][source]
_pattern[source]
static match(string)[source]

Implements the matching for an elif preprocessor directive.

Parameters:

string (str) – the string to match with as an elif statement.

Returns:

a tuple of size 2 containing the statements keyword and right hand side, or None if there is no match.

Return type:

(str, fparser.two.C99_Preprocessor.Cpp_Pp_Tokens) or NoneType

tostr()[source]
Returns:

this elif-stmt as a string.

Return type:

str

class fparser.two.C99Preprocessor.Cpp_Else_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StringBase

C99 6.10.1 Conditional inclusion

else-stmt is # else new-line

subclass_names = [][source]
_pattern[source]
static match(string)[source]

Implements the matching for an else preprocessor directive.

Parameters:

string (str) – the string to match with as an else statement.

Returns:

a 1-tuple containing the matched string or None if there is no match.

Return type:

(str,) or NoneType

tostr()[source]
Returns:

this else-stmt as a string.

Return type:

str

class fparser.two.C99Preprocessor.Cpp_Endif_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StringBase

C99 6.10.1 Conditional inclusion

endif-stmt is # endif new-line

subclass_names = [][source]
_pattern[source]
static match(string)[source]

Implements the matching for an endif preprocessor directive.

Parameters:

string (str) – the string to match with as an endif statement.

Returns:

a 1-tuple containing the matched string or None if there is no match.

Return type:

(str,) or NoneType

tostr()[source]
Returns:

this endif-stmt as a string.

Return type:

str

class fparser.two.C99Preprocessor.Cpp_Include_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

C99 6.10.2 Source file inclusion

include_stmt is # include [ <h-char-sequence>

or “q-char-sequence” or pp-tokens ] new-line

_regex[source]
use_names = ['Include_Filename'][source]
static match(string)[source]

Implements the matching for an include statement.

Allows for the filename to appear in double quotes or angle brackets. Only very loose restrictions are enforced for the filename, which is matched by py:class:fparser.two.Fortran2003.Include_Filename.

Parameters:

string (str) – the string to match with as an include statement.

Returns:

a tuple of size 1 containing a py:class:fparser.two.C99Preprocessor.Cpp_Include_Filename object with the matched filename if there is a match, or None if there is not.

Return type:

(fparser.two.Fortran2003.Include_Filename, ) or NoneType

tostr()[source]
Returns:

this include-stmt as a string.

Return type:

str

class fparser.two.C99Preprocessor.Cpp_Macro_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

C99 6.10.3 Macro replacement

macro_stmt is # define identifier [( [identifier-list] ) or (…) ]

[ replacement-list ] new-line

Important: No preceding whitespace is allowed for the left parenthesis of the optional identifier-list. If a preceding whitespace is encountered, the bracket is considered part of the replacement-list.

use_names = ['Cpp_Macro_Identifier', 'Cpp_Macro_Identifier_List', 'Cpp_Pp_Tokens'][source]
_regex[source]
static match(string)[source]

Implements the matching for a preprocessor macro definition.

It matches define directives with macro identifier, optional identifier list, and optional replacement list. The macro identifier is matched using fparser.two.C99Preprocessor.Cpp_Macro_Identifier and the optional argument identifier list using fparser.two.C99Preprocessor.Cpp_Macro_Identifier_List.

Important: No preceding whitespace is allowed for the left parentheses of the dentifier-list. If a preceding whitespace is encountered, the it is considered part of the replacement-list.

Parameters:

string (str) – the string to match with as an if statement.

Returns:

a tuple of size 3 containing the macro identifier, identifier list or None, and replacement list or None, or None if there is no match.

Return type:

(py:class:fparser.two.C99Preprocessor.Cpp_Macro_Identifier, py:class:fparser.two.C99Preprocessor.Cpp_Macro_Identifier_List or NoneType, py:class:fparser.two.C99Preprocessor.Cpp_Pp_Tokens or NoneType) or NoneType

tostr()[source]
Returns:

this macro-stmt as a string.

Return type:

str

class fparser.two.C99Preprocessor.Cpp_Macro_Identifier(string, parent_cls=None)[source]

Bases: fparser.two.utils.StringBase

Implements the matching of a macro identifier.

subclass_names = [][source]
static match(string)[source]

Implements the matching of a macro identifier.

It matches the string with the regular expression abs_macro_name in the pattern_tools file. The macro identifier may contain only letters and underscore.

Parameters:

string (str) – the string to match with the pattern rule.

Returns:

a tuple of size 1 containing a string with the matched name if there is a match, or None if there is not.

Return type:

(str) or NoneType

class fparser.two.C99Preprocessor.Cpp_Macro_Identifier_List(string, parent_cls=None)[source]

Bases: fparser.two.utils.StringBase

Implements the matching of an identifier list in a macro definition.

identifier-list is (identifier [, identifier-list or …])

or (…)

subclass_names = [][source]
_pattern[source]
static match(string)[source]

Implements the matching of a macro identifier list as part of a macro definition. It must consist of one or more macro identifier separated by comma, or “…” for a variadic argument list, and must be surrouned by parentheses.

For simplicity, the matched list is kept as a single string and not matched as fparser.two.C99Preprocessor.Cpp_Macro_Identifier.

Parameters:

string (str) – the string to match with the pattern rule.

Returns:

a tuple of size 1 containing a string with the matched identifier list if there is a match, or None if there is not.

Return type:

(str,) or NoneType

tostr()[source]
Returns:

this macro-identifier-list as a string.

Return type:

str

class fparser.two.C99Preprocessor.Cpp_Undef_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.WORDClsBase

Implements the matching of a preprocessor undef statement for a macro.

undef-stmt is # undef identifier new-line

Strictly, this is part of 6.10.3 but since it is identified by a different directive keyword (undef instead of define) we treat it separately.

subclass_names = [][source]
use_names = ['Cpp_Macro_Identifier'][source]
_pattern[source]
static match(string)[source]

Implements the matching for a preprocessor undef statement for a macro. The macro identifier is matched using fparser.two.C99Preprocessor.Cpp_Macro_Identifier.

Parameters:

string (str) – the string to match with as an if statement.

Returns:

a tuple of size 1 containing the macro identifier, or None if there is no match.

Return type:

(py:class:fparser.two.C99Preprocessor.Cpp_Macro_Identifier) or NoneType

tostr()[source]
Returns:

this undef-stmt as a string.

Return type:

str

class fparser.two.C99Preprocessor.Cpp_Line_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.WORDClsBase

C99 6.10.4 Line control

line-stmt is # line digit-sequence [ “s-char-sequence” ] new-line

or pp-tokens new-line

subclass_names = [][source]
use_names = ['Cpp_Pp_Tokens'][source]
_pattern[source]
static match(string)[source]

Implements the matching for a line preprocessor directive. The right hand side of the directive is not matched any further but simply kept as a string.

Parameters:

string (str) – the string to match with as a line statement.

Returns:

a tuple of size 1 with the right hand side as a string, or None if there is no match.

Return type:

(str) or NoneType

tostr()[source]
Returns:

this line-stmt as a string.

Return type:

str

class fparser.two.C99Preprocessor.Cpp_Error_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.WORDClsBase

C99 6.10.5 Error directive

error-stmt is # error [pp-tokens] new-line

subclass_names = [][source]
use_names = ['Cpp_Pp_Tokens'][source]
_pattern[source]
static match(string)[source]

Implements the matching for an error preprocessor directive. The optional right hand side of the directive is not matched any further but simply kept as a string.

Parameters:

string (str) – the string to match with as a line statement.

Returns:

an empty tuple or a tuple of size 1 with the right hand side as a string, or None if there is no match.

Return type:

() or (str) or NoneType

tostr()[source]
Returns:

this error-stmt as a string.

Return type:

str

class fparser.two.C99Preprocessor.Cpp_Warning_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.WORDClsBase

Not actually part of C99 but supported by most preprocessors and with syntax identical to Cpp_Error_Stmt

warning-stmt is # warning [pp-tokens] new-line

subclass_names = [][source]
use_names = ['Cpp_Pp_Tokens'][source]
_pattern[source]
static match(string)[source]

Implements the matching for a warning preprocessor directive. The optional right hand side of the directive is not matched any further but simply kept as a string.

Parameters:

string (str) – the string to match with as a line statement.

Returns:

an empty tuple or a tuple of size 1 with the right hand side as a string, or None if there is no match.

Return type:

() or (str) or NoneType

tostr()[source]
Returns:

this warning-stmt as a string.

Return type:

str

class fparser.two.C99Preprocessor.Cpp_Null_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

C99 6.10.7 Null directive

null-stmt is # new-line

subclass_names = [][source]
static match(string)[source]

Implements the matching for a Null (empty) directive.

Parameters:

string (str) – the string to match with as a line statement.

Returns:

an empty tuple or None if there is no match.

Return type:

() or NoneType

tostr()[source]
Returns:

this null-stmt as a string.

Return type:

str