Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[sipify] Correctly indent multiline list items
  • Loading branch information
nyalldawson committed Jun 11, 2020
1 parent 860dff9 commit 84ec481
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions scripts/sipify.pl
Expand Up @@ -53,6 +53,7 @@
my $PYTHON_SIGNATURE = '';

my $INDENT = '';
my $PREV_INDENT = '';
my $COMMENT = '';
my $COMMENT_PARAM_LIST = 0;
my $COMMENT_LAST_LINE_NOTE_WARNING = 0;
Expand Down Expand Up @@ -188,14 +189,21 @@ sub processDoxygenLine {
$line = '';
}

# if inside multi-line parameter, ensure additional lines are indented
# handle multi-line parameters/returns/lists
if ($line ne '') {
if ( $line !~ m/^\s*[\\:]+(param|note|since|return|deprecated|warning|throws)/ ) {
if ( $line =~ m/^\s*\-/ ){
# start of a list item, ensure following lines are correctly indented
$line = "$PREV_INDENT$line";
$INDENT = $PREV_INDENT." ";
}
elsif ( $line !~ m/^\s*[\\:]+(param|note|since|return|deprecated|warning|throws)/ ) {
# if inside multi-line parameter, ensure additional lines are indented
$line = "$INDENT$line";
}
}
else
{
$PREV_INDENT = $INDENT;
$INDENT = '';
}
# replace \returns with :return:
Expand Down Expand Up @@ -234,15 +242,18 @@ sub processDoxygenLine {
}

if ( $line =~ m/[\\@](ingroup|class)/ ) {
$PREV_INDENT = $INDENT;
$INDENT = '';
return "";
}
if ( $line =~ m/\\since .*?([\d\.]+)/i ) {
$PREV_INDENT = $INDENT;
$INDENT = '';
$FOUND_SINCE = 1;
return "\n.. versionadded:: $1\n";
}
if ( $line =~ m/\\deprecated(?:\s+since\s+(?:QGIS\s+)(?<DEPR_VERSION>[0-9.]+)(,\s*)?)?(?<DEPR_MESSAGE>.*)?/i ) {
$PREV_INDENT = $INDENT;
$INDENT = '';
my $depr_line = "\n.. deprecated::";
$depr_line .= " QGIS $+{DEPR_VERSION}" if (defined $+{DEPR_VERSION});
Expand Down Expand Up @@ -294,15 +305,18 @@ sub processDoxygenLine {

if ( $line =~ m/[\\@]note (.*)/ ) {
$COMMENT_LAST_LINE_NOTE_WARNING = 1;
$PREV_INDENT = $INDENT;
$INDENT = '';
return "\n.. note::\n\n $1\n";
}
if ( $line =~ m/[\\@]warning (.*)/ ) {
$PREV_INDENT = $INDENT;
$INDENT = '';
$COMMENT_LAST_LINE_NOTE_WARNING = 1;
return "\n.. warning::\n\n $1\n";
}
if ( $line =~ m/[\\@]throws (.+?)\b\s*(.*)/ ) {
$PREV_INDENT = $INDENT;
$INDENT = '';
$COMMENT_LAST_LINE_NOTE_WARNING = 1;
return "\n:raises $1: $2\n";
Expand Down Expand Up @@ -481,6 +495,7 @@ sub detect_comment_block{
# dbg_info("detect comment strict:" . $args{strict_mode} );
$COMMENT_PARAM_LIST = 0;
$INDENT = '';
$PREV_INDENT = '';
$COMMENT_CODE_SNIPPET = 0;
$COMMENT_LAST_LINE_NOTE_WARNING = 0;
$FOUND_SINCE = 0;
Expand Down Expand Up @@ -950,6 +965,7 @@ sub detect_non_method_member{
if ( $LINE =~ m/^\s*\/\// ){
if ($LINE =~ m/^\s*\/\/\!\s*(.*?)\n?$/){
$COMMENT_PARAM_LIST = 0;
$PREV_INDENT = $INDENT;
$INDENT = '';
$COMMENT_LAST_LINE_NOTE_WARNING = 0;
$COMMENT = processDoxygenLine( $1 );
Expand Down

0 comments on commit 84ec481

Please sign in to comment.