fparser.two.C99Preprocessor =========================== .. py:module:: fparser.two.C99Preprocessor .. autoapi-nested-parse:: C99 Preprocessor Syntax Rules. Attributes ---------- .. autoapisummary:: fparser.two.C99Preprocessor.CPP_CLASS_NAMES Classes ------- .. autoapisummary:: fparser.two.C99Preprocessor.Cpp_Pp_Tokens fparser.two.C99Preprocessor.Cpp_If_Stmt fparser.two.C99Preprocessor.Cpp_Elif_Stmt fparser.two.C99Preprocessor.Cpp_Else_Stmt fparser.two.C99Preprocessor.Cpp_Endif_Stmt fparser.two.C99Preprocessor.Cpp_Include_Stmt fparser.two.C99Preprocessor.Cpp_Macro_Stmt fparser.two.C99Preprocessor.Cpp_Macro_Identifier fparser.two.C99Preprocessor.Cpp_Macro_Identifier_List fparser.two.C99Preprocessor.Cpp_Undef_Stmt fparser.two.C99Preprocessor.Cpp_Line_Stmt fparser.two.C99Preprocessor.Cpp_Error_Stmt fparser.two.C99Preprocessor.Cpp_Warning_Stmt fparser.two.C99Preprocessor.Cpp_Null_Stmt Functions --------- .. autoapisummary:: fparser.two.C99Preprocessor.match_cpp_directive Module Contents --------------- .. py:data:: CPP_CLASS_NAMES :value: ['Cpp_If_Stmt', 'Cpp_Elif_Stmt', 'Cpp_Else_Stmt', 'Cpp_Endif_Stmt', 'Cpp_Include_Stmt',... .. py:function:: match_cpp_directive(reader) Creates single-line C99 preprocessor directive object from the current line, if any is found. :param reader: the fortran file reader containing the line of code that we are trying to match. :type reader: :py:class:`fparser.common.readfortran.FortranFileReader` or :py:class:`fparser.common.readfortran.FortranStringReader` :return: the matched preprocessor directive object or `None`. :rtype: one of (:py:class:`fparser.two.C99Preprocess.Cpp_*_Stmt`,) or `NoneType` .. py:class:: Cpp_Pp_Tokens(string, parent_cls=None) Bases: :py:obj:`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.). .. py:attribute:: subclass_names :value: [] .. py:method:: match(string) :staticmethod: 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. :param str string: the string to be matched as pp-tokens. :return: a 1-tuple containing the matched string or None. :rtype: (str,) or NoneType .. py:method:: tostr() :return: this pp-tokens as a string. :rtype: str .. py:class:: Cpp_If_Stmt(string, parent_cls=None) Bases: :py:obj:`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 .. py:attribute:: subclass_names :value: [] .. py:attribute:: use_names :value: ['Cpp_Macro_Identifier', 'Cpp_Pp_Tokens'] .. py:attribute:: _regex .. py:attribute:: _if_pattern .. py:attribute:: _def_pattern .. py:method:: match(string) :staticmethod: Implements the matching for an if preprocessor directive (or its variations ifdef, ifndef). For ifdef and ifndef statements it matches the macro identifier using :py:class:`fparser.two.C99Preprocesser.Cpp_Macro_Identifier` otherwise it uses :py:class:`fparser.two.C99Preprocessor.Cpp_Pp_Tokens` to accept any non-empty string as rhs. :param str string: the string to match with as an if statement. :return: a tuple of size 2 containing the statement's keyword and the right hand side, or `None` if there is no match. :rtype: (`str`, py:class:`fparser.two.C99Preprocessor.Cpp_Macro_Identifier`) or (`str`, py:class:`fparser.two.C99Preprocessor.Cpp_Pp_Tokens`) or `NoneType` .. py:method:: tostr() :return: this if-stmt as a string. :rtype: str .. py:class:: Cpp_Elif_Stmt(string, parent_cls=None) Bases: :py:obj:`fparser.two.utils.WORDClsBase` C99 6.10.1 Conditional inclusion elif-stmt is # elif constant-expression new-line .. py:attribute:: subclass_names :value: [] .. py:attribute:: use_names :value: ['Cpp_Pp_Tokens'] .. py:attribute:: _pattern .. py:method:: match(string) :staticmethod: Implements the matching for an elif preprocessor directive. :param str string: the string to match with as an elif statement. :return: a tuple of size 2 containing the statements keyword and right hand side, or `None` if there is no match. :rtype: (`str`, :py:class:`fparser.two.C99_Preprocessor.Cpp_Pp_Tokens`) or `NoneType` .. py:method:: tostr() :return: this elif-stmt as a string. :rtype: str .. py:class:: Cpp_Else_Stmt(string, parent_cls=None) Bases: :py:obj:`fparser.two.utils.StringBase` C99 6.10.1 Conditional inclusion else-stmt is # else new-line .. py:attribute:: subclass_names :value: [] .. py:attribute:: _pattern .. py:method:: match(string) :staticmethod: Implements the matching for an else preprocessor directive. :param str string: the string to match with as an else statement. :return: a 1-tuple containing the matched string or `None` if there is no match. :rtype: (str,) or NoneType .. py:method:: tostr() :return: this else-stmt as a string. :rtype: str .. py:class:: Cpp_Endif_Stmt(string, parent_cls=None) Bases: :py:obj:`fparser.two.utils.StringBase` C99 6.10.1 Conditional inclusion endif-stmt is # endif new-line .. py:attribute:: subclass_names :value: [] .. py:attribute:: _pattern .. py:method:: match(string) :staticmethod: Implements the matching for an endif preprocessor directive. :param str string: the string to match with as an endif statement. :return: a 1-tuple containing the matched string or `None` if there is no match. :rtype: (str,) or NoneType .. py:method:: tostr() :return: this endif-stmt as a string. :rtype: str .. py:class:: Cpp_Include_Stmt(string, parent_cls=None) Bases: :py:obj:`fparser.two.utils.Base` C99 6.10.2 Source file inclusion include_stmt is # include [ or "q-char-sequence" or pp-tokens ] new-line .. py:attribute:: _regex .. py:attribute:: use_names :value: ['Include_Filename'] .. py:method:: match(string) :staticmethod: 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`. :param str string: the string to match with as an include statement. :return: 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. :rtype: (:py:class:`fparser.two.Fortran2003.Include_Filename`, ) or `NoneType` .. py:method:: tostr() :return: this include-stmt as a string. :rtype: str .. py:class:: Cpp_Macro_Stmt(string, parent_cls=None) Bases: :py:obj:`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. .. py:attribute:: use_names :value: ['Cpp_Macro_Identifier', 'Cpp_Macro_Identifier_List', 'Cpp_Pp_Tokens'] .. py:attribute:: _regex .. py:method:: match(string) :staticmethod: 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 :py:class:`fparser.two.C99Preprocessor.Cpp_Macro_Identifier` and the optional argument identifier list using :py:class:`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. :param str string: the string to match with as an if statement. :return: 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. :rtype: (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` .. py:method:: tostr() :return: this macro-stmt as a string. :rtype: str .. py:class:: Cpp_Macro_Identifier(string, parent_cls=None) Bases: :py:obj:`fparser.two.utils.StringBase` Implements the matching of a macro identifier. .. py:attribute:: subclass_names :value: [] .. py:method:: match(string) :staticmethod: 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. :param str string: the string to match with the pattern rule. :return: a tuple of size 1 containing a string with the matched name if there is a match, or None if there is not. :rtype: (str) or NoneType .. py:class:: Cpp_Macro_Identifier_List(string, parent_cls=None) Bases: :py:obj:`fparser.two.utils.StringBase` Implements the matching of an identifier list in a macro definition. identifier-list is (identifier [, identifier-list or ...]) or (...) .. py:attribute:: subclass_names :value: [] .. py:attribute:: _pattern .. py:method:: match(string) :staticmethod: 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 :py:class:`fparser.two.C99Preprocessor.Cpp_Macro_Identifier`. :param str string: the string to match with the pattern rule. :return: a tuple of size 1 containing a string with the matched identifier list if there is a match, or None if there is not. :rtype: (`str`,) or `NoneType` .. py:method:: tostr() :return: this macro-identifier-list as a string. :rtype: str .. py:class:: Cpp_Undef_Stmt(string, parent_cls=None) Bases: :py:obj:`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. .. py:attribute:: subclass_names :value: [] .. py:attribute:: use_names :value: ['Cpp_Macro_Identifier'] .. py:attribute:: _pattern .. py:method:: match(string) :staticmethod: Implements the matching for a preprocessor undef statement for a macro. The macro identifier is matched using :py:class:`fparser.two.C99Preprocessor.Cpp_Macro_Identifier`. :param str string: the string to match with as an if statement. :return: a tuple of size 1 containing the macro identifier, or `None` if there is no match. :rtype: (py:class:`fparser.two.C99Preprocessor.Cpp_Macro_Identifier`) or `NoneType` .. py:method:: tostr() :return: this undef-stmt as a string. :rtype: str .. py:class:: Cpp_Line_Stmt(string, parent_cls=None) Bases: :py:obj:`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 .. py:attribute:: subclass_names :value: [] .. py:attribute:: use_names :value: ['Cpp_Pp_Tokens'] .. py:attribute:: _pattern .. py:method:: match(string) :staticmethod: 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. :param str string: the string to match with as a line statement. :return: a tuple of size 1 with the right hand side as a string, or `None` if there is no match. :rtype: (`str`) or `NoneType` .. py:method:: tostr() :return: this line-stmt as a string. :rtype: str .. py:class:: Cpp_Error_Stmt(string, parent_cls=None) Bases: :py:obj:`fparser.two.utils.WORDClsBase` C99 6.10.5 Error directive error-stmt is # error [pp-tokens] new-line .. py:attribute:: subclass_names :value: [] .. py:attribute:: use_names :value: ['Cpp_Pp_Tokens'] .. py:attribute:: _pattern .. py:method:: match(string) :staticmethod: 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. :param str string: the string to match with as a line statement. :return: an empty tuple or a tuple of size 1 with the right hand side as a string, or `None` if there is no match. :rtype: () or (`str`) or `NoneType` .. py:method:: tostr() :return: this error-stmt as a string. :rtype: str .. py:class:: Cpp_Warning_Stmt(string, parent_cls=None) Bases: :py:obj:`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 .. py:attribute:: subclass_names :value: [] .. py:attribute:: use_names :value: ['Cpp_Pp_Tokens'] .. py:attribute:: _pattern .. py:method:: match(string) :staticmethod: 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. :param str string: the string to match with as a line statement. :return: an empty tuple or a tuple of size 1 with the right hand side as a string, or `None` if there is no match. :rtype: () or (`str`) or `NoneType` .. py:method:: tostr() :return: this warning-stmt as a string. :rtype: str .. py:class:: Cpp_Null_Stmt(string, parent_cls=None) Bases: :py:obj:`fparser.two.utils.Base` C99 6.10.7 Null directive null-stmt is # new-line .. py:attribute:: subclass_names :value: [] .. py:method:: match(string) :staticmethod: Implements the matching for a Null (empty) directive. :param str string: the string to match with as a line statement. :return: an empty tuple or `None` if there is no match. :rtype: () or `NoneType` .. py:method:: tostr() :return: this null-stmt as a string. :rtype: str