fparser.two.C99Preprocessor
C99 Preprocessor Syntax Rules.
Module Contents
Classes
Generic class for preprocessor tokens that form the right hand |
|
C99 6.10.1 Conditional inclusion |
|
C99 6.10.1 Conditional inclusion |
|
C99 6.10.1 Conditional inclusion |
|
C99 6.10.1 Conditional inclusion |
|
C99 6.10.2 Source file inclusion |
|
C99 6.10.3 Macro replacement |
|
Implements the matching of a macro identifier. |
|
Implements the matching of an identifier list in a macro definition. |
|
Implements the matching of a preprocessor undef statement for a macro. |
|
C99 6.10.4 Line control |
|
C99 6.10.5 Error directive |
|
Not actually part of C99 but supported by most preprocessors and |
|
C99 6.10.7 Null directive |
Functions
|
Creates single-line C99 preprocessor directive object from the |
Attributes
- 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
orfparser.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.).
- 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
- 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 usesfparser.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
- 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
- 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
- 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
- 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
- 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
- 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
- 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.
- 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 usingfparser.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
- class fparser.two.C99Preprocessor.Cpp_Macro_Identifier(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StringBase
Implements the matching of a macro identifier.
- 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 (…)
- 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
- 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.
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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