2626#include <stdlib.h>
2727#include <string.h>
2828
29+ static position_T erb_content_end_position (const AST_ERB_CONTENT_NODE_T * erb_node ) {
30+ if (erb_node -> tag_closing != NULL ) {
31+ return erb_node -> tag_closing -> location .end ;
32+ } else if (erb_node -> content != NULL ) {
33+ return erb_node -> content -> location .end ;
34+ } else {
35+ return erb_node -> tag_opening -> location .end ;
36+ }
37+ }
38+
2939static analyzed_ruby_T * herb_analyze_ruby (hb_string_T source ) {
3040 analyzed_ruby_T * analyzed = init_analyzed_ruby (source );
3141
@@ -279,11 +289,11 @@ static control_type_t find_earliest_control_keyword(pm_node_t* root, const uint8
279289
280290static control_type_t detect_control_type (AST_ERB_CONTENT_NODE_T * erb_node ) {
281291 if (!erb_node || erb_node -> base .type != AST_ERB_CONTENT_NODE ) { return CONTROL_TYPE_UNKNOWN ; }
292+ if (erb_node -> tag_closing == NULL ) { return CONTROL_TYPE_UNKNOWN ; }
282293
283294 analyzed_ruby_T * ruby = erb_node -> analyzed_ruby ;
284295
285296 if (!ruby ) { return CONTROL_TYPE_UNKNOWN ; }
286-
287297 if (ruby -> valid ) { return CONTROL_TYPE_UNKNOWN ; }
288298
289299 pm_node_t * root = ruby -> root ;
@@ -340,7 +350,7 @@ static AST_NODE_T* create_control_node(
340350 erb_node -> base .errors = NULL ;
341351
342352 position_T start_position = erb_node -> tag_opening -> location .start ;
343- position_T end_position = erb_node -> tag_closing -> location . end ;
353+ position_T end_position = erb_content_end_position ( erb_node ) ;
344354
345355 if (end_node ) {
346356 end_position = end_node -> base .location .end ;
@@ -695,14 +705,16 @@ static size_t process_control_structure(
695705 }
696706 }
697707
708+ position_T when_end_position = erb_content_end_position (erb_content );
709+
698710 AST_ERB_WHEN_NODE_T * when_node = ast_erb_when_node_init (
699711 erb_content -> tag_opening ,
700712 erb_content -> content ,
701713 erb_content -> tag_closing ,
702714 then_keyword ,
703715 when_statements ,
704716 erb_content -> tag_opening -> location .start ,
705- erb_content -> tag_closing -> location . end ,
717+ when_end_position ,
706718 when_errors
707719 );
708720
@@ -736,14 +748,16 @@ static size_t process_control_structure(
736748 }
737749 }
738750
751+ position_T in_end_position = erb_content_end_position (erb_content );
752+
739753 AST_ERB_IN_NODE_T * in_node = ast_erb_in_node_init (
740754 erb_content -> tag_opening ,
741755 erb_content -> content ,
742756 erb_content -> tag_closing ,
743757 in_then_keyword ,
744758 in_statements ,
745759 erb_content -> tag_opening -> location .start ,
746- erb_content -> tag_closing -> location . end ,
760+ in_end_position ,
747761 in_errors
748762 );
749763
@@ -785,7 +799,7 @@ static size_t process_control_structure(
785799 next_erb -> tag_closing ,
786800 else_children ,
787801 next_erb -> tag_opening -> location .start ,
788- next_erb -> tag_closing -> location . end ,
802+ erb_content_end_position ( next_erb ) ,
789803 else_errors
790804 );
791805
@@ -811,7 +825,7 @@ static size_t process_control_structure(
811825 end_erb -> content ,
812826 end_erb -> tag_closing ,
813827 end_erb -> tag_opening -> location .start ,
814- end_erb -> tag_closing -> location . end ,
828+ erb_content_end_position ( end_erb ) ,
815829 end_errors
816830 );
817831
@@ -823,7 +837,7 @@ static size_t process_control_structure(
823837 }
824838
825839 position_T start_position = erb_node -> tag_opening -> location .start ;
826- position_T end_position = erb_node -> tag_closing -> location . end ;
840+ position_T end_position = erb_content_end_position ( erb_node ) ;
827841
828842 if (end_node ) {
829843 end_position = end_node -> base .location .end ;
@@ -933,7 +947,7 @@ static size_t process_control_structure(
933947 next_erb -> tag_closing ,
934948 else_children ,
935949 next_erb -> tag_opening -> location .start ,
936- next_erb -> tag_closing -> location . end ,
950+ erb_content_end_position ( next_erb ) ,
937951 else_errors
938952 );
939953
@@ -979,7 +993,7 @@ static size_t process_control_structure(
979993 next_erb -> tag_closing ,
980994 ensure_children ,
981995 next_erb -> tag_opening -> location .start ,
982- next_erb -> tag_closing -> location . end ,
996+ erb_content_end_position ( next_erb ) ,
983997 ensure_errors
984998 );
985999
@@ -1005,7 +1019,7 @@ static size_t process_control_structure(
10051019 end_erb -> content ,
10061020 end_erb -> tag_closing ,
10071021 end_erb -> tag_opening -> location .start ,
1008- end_erb -> tag_closing -> location . end ,
1022+ erb_content_end_position ( end_erb ) ,
10091023 end_errors
10101024 );
10111025
@@ -1017,7 +1031,7 @@ static size_t process_control_structure(
10171031 }
10181032
10191033 position_T start_position = erb_node -> tag_opening -> location .start ;
1020- position_T end_position = erb_node -> tag_closing -> location . end ;
1034+ position_T end_position = erb_content_end_position ( erb_node ) ;
10211035
10221036 if (end_node ) {
10231037 end_position = end_node -> base .location .end ;
@@ -1068,12 +1082,14 @@ static size_t process_control_structure(
10681082 hb_array_T * end_errors = close_erb -> base .errors ;
10691083 close_erb -> base .errors = NULL ;
10701084
1085+ position_T close_end_pos = erb_content_end_position (close_erb );
1086+
10711087 end_node = ast_erb_end_node_init (
10721088 close_erb -> tag_opening ,
10731089 close_erb -> content ,
10741090 close_erb -> tag_closing ,
10751091 close_erb -> tag_opening -> location .start ,
1076- close_erb -> tag_closing -> location . end ,
1092+ close_end_pos ,
10771093 end_errors
10781094 );
10791095
@@ -1085,7 +1101,7 @@ static size_t process_control_structure(
10851101 }
10861102
10871103 position_T start_position = erb_node -> tag_opening -> location .start ;
1088- position_T end_position = erb_node -> tag_closing -> location . end ;
1104+ position_T end_position = erb_content_end_position ( erb_node ) ;
10891105
10901106 if (end_node ) {
10911107 end_position = end_node -> base .location .end ;
@@ -1142,12 +1158,14 @@ static size_t process_control_structure(
11421158 hb_array_T * end_errors = end_erb -> base .errors ;
11431159 end_erb -> base .errors = NULL ;
11441160
1161+ position_T end_erb_final_pos = erb_content_end_position (end_erb );
1162+
11451163 end_node = ast_erb_end_node_init (
11461164 end_erb -> tag_opening ,
11471165 end_erb -> content ,
11481166 end_erb -> tag_closing ,
11491167 end_erb -> tag_opening -> location .start ,
1150- end_erb -> tag_closing -> location . end ,
1168+ end_erb_final_pos ,
11511169 end_errors
11521170 );
11531171
0 commit comments