Mercurial > octave
changeset 32918:a4dc80b3e13a stable
select classdef method doc based on comment style (bug #65220)
(base_parser::make_function): For classdef methods, choose the first
comment inside the function as the doc string only if the comment
blocks don't use any '#' characters. Otherwise, use the comment above
the function.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 02 Feb 2024 23:37:46 -0500 |
parents | f41297ca3e1a |
children | 319dcef8962d 8239df5ad55f |
files | libinterp/parse-tree/oct-parse.yy |
diffstat | 1 files changed, 18 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/parse-tree/oct-parse.yy Fri Feb 02 23:03:34 2024 -0500 +++ b/libinterp/parse-tree/oct-parse.yy Fri Feb 02 23:37:46 2024 -0500 @@ -3962,11 +3962,25 @@ tree_statement *end_fcn_stmt, comment_list *lc, comment_list *bc) { + // FIXME: maybe choose which comment to used by checking whether + // any language extensions are noticed in the entire source file, + // not just in the comments that are candidates to become the + // function doc string. + // If we are looking at a classdef method and there is a comment - // prior to the function keyword and another after, choose the one - // inside the function definition for compatibility with Matlab. - - if (m_lexer.m_parsing_classdef && ! m_lexer.m_doc_string.empty () && bc && ! bc->empty ()) + // prior to the function keyword and another after, then + // + // * Choose the one outside the function definition if either of + // the comments use hash '#' characters. This is the preferred + // Octave style. + // + // * Choose the one inside the function definition if both + // comments use percent '%' characters. This is + // Matlab-compatible behavior. + + if (m_lexer.m_parsing_classdef && ! m_lexer.m_doc_string.empty () + && bc && ! bc->empty () && ! m_lexer.m_doc_string.uses_hash_char () + && ! bc->front().uses_hash_char ()) m_lexer.m_doc_string = bc->front (); int l = fcn_tok->line ();