Example #1
0
    def _type_instance(self):
        """A type declaration.

        The modifiers of a typedef:
                struct s *P[];
                         ^^^^<-    The type instance.
        """
        type_instance = (
            # Function pointer     (*f)(int foobar)
            pyparsing.ZeroOrMore(_STAR) + _OPEN_PARENTHESIS +
            pyparsing.Optional(_STAR("function_pointer")) +
            self._identifier()("type_instance_name") + _CLOSE_PARENTHESIS +
            parsers.anything_in_parentheses()("function_args")) | (
                # Function object  f(foo bar *)
                pyparsing.ZeroOrMore(_STAR) +
                self._identifier()("type_instance_name") +
                parsers.anything_in_parentheses()("function_args")) | (
                    # Simple form: *foo[10];
                    pyparsing.ZeroOrMore(_STAR)
                    ("type_pointer") + self._identifier()("type_instance_name")

                    # Possibly array: [] , [][]
                    + pyparsing.ZeroOrMore(
                        _OPEN_BRACKET + pyparsing.SkipTo(_CLOSE_BRACKET)
                        ("brackets_with_expression_inside*") + _CLOSE_BRACKET)

                    # Bitfields:    int x: 7;
                    + pyparsing.Optional(_COLON +
                                         pyparsing.SkipTo(_SEMICOLON | _COMMA)
                                         ("bitfield")))

        return pyparsing.Group(type_instance + self._maybe_attributes())
Example #2
0
 def static_function(self):
     return (
         (pyparsing.Keyword("static") | pyparsing.Keyword("inline"))
         + pyparsing.OneOrMore(pyparsing.Word(pyparsing.alphanums + "_*&"))
         + parsers.anything_in_parentheses()
         + parsers.anything_in_curly()
     ).suppress()
Example #3
0
 def _parentheses_reducer(self):
     """Removes useless parentheses."""
     return (
         _OPEN_PARENTHESIS
         + parsers.anything_in_parentheses()("nested")
         + _CLOSE_PARENTHESIS
     ).setParseAction(lambda tok: tok.nested)
Example #4
0
 def _typeof_transform(self):
     """Removes typeof expressions."""
     return (
         _OPEN_PARENTHESIS
         + pyparsing.Keyword('typeof')
         + parsers.anything_in_parentheses()
         + _CLOSE_PARENTHESIS
     ).suppress()
Example #5
0
    def _type_instance(self):
        """A type declaration.

        The modifiers of a typedef:
                struct s *P[];
                         ^^^^<-    The type instance.
        """
        type_instance = (
            # Function pointer     (*f)(int foobar)
            pyparsing.ZeroOrMore(_STAR)
            + _OPEN_PARENTHESIS
            + pyparsing.Optional(_STAR("function_pointer"))
            + self._identifier()("type_instance_name")
            + _CLOSE_PARENTHESIS
            + parsers.anything_in_parentheses()("function_args")
        ) | (
            # Function object  f(foo bar *)
            pyparsing.ZeroOrMore(_STAR)
            + self._identifier()("type_instance_name")
            + parsers.anything_in_parentheses()("function_args")
        ) | (
            # Simple form: *foo[10];
            pyparsing.ZeroOrMore(_STAR)("type_pointer")
            + self._identifier()("type_instance_name")

            # Possibly array: [] , [][]
            + pyparsing.ZeroOrMore(
                _OPEN_BRACKET
                + pyparsing.SkipTo(_CLOSE_BRACKET)(
                    "brackets_with_expression_inside*")
                + _CLOSE_BRACKET)

            # Bitfields:    int x: 7;
            + pyparsing.Optional(
                _COLON
                + pyparsing.SkipTo(
                    _SEMICOLON | _COMMA)("bitfield")
            )
        )

        return pyparsing.Group(
            type_instance
            + self._maybe_attributes()
        )
Example #6
0
 def _typeof_transform(self):
     """Removes typeof expressions."""
     return (_OPEN_PARENTHESIS + pyparsing.Keyword('typeof') +
             parsers.anything_in_parentheses() +
             _CLOSE_PARENTHESIS).suppress()
Example #7
0
 def _parentheses_reducer(self):
     """Removes useless parentheses."""
     return (_OPEN_PARENTHESIS +
             parsers.anything_in_parentheses()("nested") +
             _CLOSE_PARENTHESIS).setParseAction(lambda tok: tok.nested)
Example #8
0
 def static_function(self):
     return (
         (pyparsing.Keyword("static") | pyparsing.Keyword("inline")) +
         pyparsing.OneOrMore(pyparsing.Word(pyparsing.alphanums + "_*&")) +
         parsers.anything_in_parentheses() +
         parsers.anything_in_curly()).suppress()