fortrangoingonforty/fortsh / f972ead

Browse files

fix: skip <<< (here-string) in heredoc detection — was consuming subsequent lines as heredoc content

Authored by espadonne
SHA
f972eadd6a458ced993ee083a49087869bdda1d0
Parents
f89c518
Tree
390d173

2 changed files

StatusFile+-
M src/fortsh.f90 10 2
M src/parsing/parser.f90 6 1
src/fortsh.f90modified
@@ -599,9 +599,11 @@ contains
599599
         in_double_quote = .not. in_double_quote
600600
       end if
601601
 
602
-      ! Check for << when outside quotes
602
+      ! Check for << when outside quotes (but NOT <<< which is here-string)
603603
       if (.not. in_single_quote .and. .not. in_double_quote) then
604604
         if (str(i:i+1) == '<<') then
605
+          ! Skip <<< (here-string)
606
+          if (i + 2 <= len_trim(str) .and. str(i+2:i+2) == '<') cycle
605607
           has_heredoc = .true.
606608
           return
607609
         end if
@@ -682,9 +684,15 @@ contains
682684
             in_double_quote = .not. in_double_quote
683685
           end if
684686
 
685
-          ! Check for << when outside quotes
687
+          ! Check for << when outside quotes (but NOT <<< which is here-string)
686688
           if (.not. in_single_quote .and. .not. in_double_quote) then
687689
             if (cmd_line(search_pos:search_pos+1) == '<<') then
690
+              ! Skip <<< (here-string)
691
+              if (search_pos + 2 <= len_trim(cmd_line) .and. &
692
+                  cmd_line(search_pos+2:search_pos+2) == '<') then
693
+                search_pos = search_pos + 3
694
+                cycle
695
+              end if
688696
               j = search_pos
689697
               exit
690698
             end if
src/parsing/parser.f90modified
@@ -2727,8 +2727,13 @@ contains
27272727
         i = i + 1; cycle
27282728
       end if
27292729
 
2730
-      ! Look for << not inside quotes
2730
+      ! Look for << not inside quotes (but NOT <<< which is here-string)
27312731
       if (line(i:i) == '<' .and. i + 1 <= line_len .and. line(i+1:i+1) == '<') then
2732
+        ! Skip <<< (here-string, not heredoc)
2733
+        if (i + 2 <= line_len .and. line(i+2:i+2) == '<') then
2734
+          i = i + 3
2735
+          cycle
2736
+        end if
27322737
         i = i + 2
27332738
         ! Skip <<- (strip tabs variant)
27342739
         strip_tabs = .false.