Skip to content
Snippets Groups Projects
Select Git revision
  • a6c3cf1ee928b9a4b1a2af18ce13d1143a00c83c
  • master default protected
  • fix/macos-meta-files-in-menu
  • koalo/bhi160
  • genofire/ble-rewrite
  • rahix/simple_menu
  • ch3/splashscreen
  • koalo/bhi160-works-but-dirty
  • ios-workarounds
  • koalo/wip/i2c-for-python
  • renze/safe_mode
  • renze/hatchery_apps
  • schneider/fundamental-test
  • koalo/factory-reset
  • msgctl/gfx_rle
  • msgctl/faultscreen
  • msgctl/textbuffer_api
  • schneider/bonding
  • schneider/bootloader-update-9a0d158
  • schneider/bsec
  • rahix/bma
  • v1.12
  • v1.11
  • v1.10
  • v1.9
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
37 results

main.c

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    doccompat.py 2.62 KiB
    # Copyright (c) 2016-2017, Jani Nikula <jani@nikula.org>
    # Licensed under the terms of BSD 2-Clause, see LICENSE for details.
    """
    Alternative docstring syntax
    ============================
    
    This module abstracts different compatibility options converting different
    syntaxes into 'native' reST ones.
    """
    
    import re
    
    # Basic Javadoc/Doxygen/kernel-doc import
    #
    # FIXME: One of the design goals of Hawkmoth is to keep things simple. There's a
    # fine balance between sticking to that goal and adding compat code to
    # facilitate any kind of migration to Hawkmoth. The compat code could be turned
    # into a fairly simple plugin architecture, with some basic compat builtins, and
    # the users could still extend the compat features to fit their specific needs.
    def convert(comment, mode):
        """Convert documentation from a supported syntax into reST."""
        # FIXME: try to preserve whitespace better
    
        if mode == 'javadoc-basic' or mode == 'javadoc-liberal':
            # @param
            comment = re.sub(r"(?m)^([ \t]*)@param([ \t]+)([a-zA-Z0-9_]+|\.\.\.)([ \t]+)",
                             "\n\\1:param\\2\\3:\\4", comment)
            # @param[direction]
            comment = re.sub(r"(?m)^([ \t]*)@param\[([^]]*)\]([ \t]+)([a-zA-Z0-9_]+|\.\.\.)([ \t]+)",
                             "\n\\1:param\\3\\4: *(\\2)* \\5", comment)
            # @return
            comment = re.sub(r"(?m)^([ \t]*)@returns?([ \t]+|$)",
                             "\n\\1:return:\\2", comment)
            # @code/@endcode blocks. Works if the code is indented.
            comment = re.sub(r"(?m)^([ \t]*)@code([ \t]+|$)",
                             "\n::\n", comment)
            comment = re.sub(r"(?m)^([ \t]*)@endcode([ \t]+|$)",
                             "\n", comment)
            # Ignore @brief.
            comment = re.sub(r"(?m)^([ \t]*)@brief[ \t]+", "\n\\1", comment)
    
            # Ignore groups
            comment = re.sub(r"(?m)^([ \t]*)@(defgroup|addtogroup)[ \t]+[a-zA-Z0-9_]+[ \t]*",
                             "\n\\1", comment)
            comment = re.sub(r"(?m)^([ \t]*)@(ingroup|{|}).*", "\n", comment)
    
        if mode == 'javadoc-liberal':
            # Liberal conversion of any @tags, will fail for @code etc. but don't
            # care.
            comment = re.sub(r"(?m)^([ \t]*)@([a-zA-Z0-9_]+)([ \t]+)",
                             "\n\\1:\\2:\\3", comment)
    
        if mode == 'kernel-doc':
            # Basic kernel-doc convert, will document struct members as params, etc.
            comment = re.sub(r"(?m)^([ \t]*)@(returns?|RETURNS?):([ \t]+|$)",
                             "\n\\1:return:\\3", comment)
            comment = re.sub(r"(?m)^([ \t]*)@([a-zA-Z0-9_]+|\.\.\.):([ \t]+)",
                             "\n\\1:param \\2:\\3", comment)
    
        return comment