From 74adaa5738368ce473870451422f4a7175b6a736 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 18 Apr 2019 17:46:13 +0200 Subject: Fix parsing of enums with trailing comma with -doxygen To correctly parse Doxygen post-comments after the trailing comma, switch to right recursion in "enumlist" production rule definition: this does consume more stack space when parsing, but makes the rules much easier to write and to understand and hopefully shouldn't result in any problems with real code (which shouldn't have thousands of enums items in it). Closes #1514. --- Source/CParse/parser.y | 58 +++++++++++++++++++------------------------------- 1 file changed, 22 insertions(+), 36 deletions(-) (limited to 'Source') diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 4046e480e..b526da907 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1650,7 +1650,7 @@ static String *add_qualifier_to_declarator(SwigType *type, SwigType *qualifier) /* C declarations */ %type c_declaration c_decl c_decl_tail c_enum_key c_enum_inherit c_enum_decl c_enum_forward_decl c_constructor_decl; -%type enumlist enumlist_tail enumlist_item edecl_with_dox edecl; +%type enumlist enumlist_item edecl_with_dox edecl; /* C++ declarations */ %type cpp_declaration cpp_class_decl cpp_forward_class_decl cpp_template_decl cpp_alternate_rettype; @@ -6374,37 +6374,36 @@ optional_ignored_defines | empty ; -optional_ignored_define_after_comma - : empty - | COMMA - | COMMA constant_directive - ; - /* Enum lists - any #define macros (constant directives) within the enum list are ignored. Trailing commas accepted. */ -enumlist : enumlist_item optional_ignored_define_after_comma { +enumlist : enumlist_item { Setattr($1,"_last",$1); $$ = $1; } - | enumlist_item enumlist_tail optional_ignored_define_after_comma { - set_nextSibling($1, $2); - Setattr($1,"_last",Getattr($2,"_last")); - Setattr($2,"_last",NULL); + | enumlist_item DOXYGENPOSTSTRING { + Setattr($1,"_last",$1); + set_comment($1, $2); $$ = $1; } - | optional_ignored_defines { - $$ = 0; - } - ; - -enumlist_tail : COMMA enumlist_item { - Setattr($2,"_last",$2); - $$ = $2; + | enumlist_item COMMA enumlist { + if ($3) { + set_nextSibling($1, $3); + Setattr($1,"_last",Getattr($3,"_last")); + Setattr($3,"_last",NULL); + } + $$ = $1; } - | enumlist_tail COMMA enumlist_item { - set_nextSibling(Getattr($1,"_last"), $3); - Setattr($1,"_last",$3); + | enumlist_item COMMA DOXYGENPOSTSTRING enumlist { + if ($4) { + set_nextSibling($1, $4); + Setattr($1,"_last",Getattr($4,"_last")); + Setattr($4,"_last",NULL); + } + set_comment($1, $3); $$ = $1; } + | optional_ignored_defines { + $$ = 0; + } ; enumlist_item : optional_ignored_defines edecl_with_dox optional_ignored_defines { @@ -6419,19 +6418,6 @@ edecl_with_dox : edecl { $$ = $2; set_comment($2, $1); } - | edecl DOXYGENPOSTSTRING { - $$ = $1; - set_comment($1, $2); - } - | DOXYGENPOSTSTRING edecl { - $$ = $2; - set_comment(previousNode, $1); - } - | DOXYGENPOSTSTRING edecl DOXYGENPOSTSTRING { - $$ = $2; - set_comment(previousNode, $1); - set_comment($2, $3); - } ; edecl : identifier { -- cgit v1.2.1