unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#19809: 24.4; f90-beginning-of-subprogram wrong behavior with string continuation
@ 2015-02-07 20:25 Raul Laasner
  2015-02-11  1:27 ` Glenn Morris
  0 siblings, 1 reply; 6+ messages in thread
From: Raul Laasner @ 2015-02-07 20:25 UTC (permalink / raw)
  To: 19809

[-- Attachment #1: Type: text/plain, Size: 2724 bytes --]

The functions f90-beginning-of-subprogram and f90-end-of-subprogram do not
work correctly if the source file contains lines which begin with the
correct keywords but in fact belong to a continued string. For instance, in
the following,

subroutine foo()
  print*, '&
       end subroutine foo'
  ! The cursor is here
end subroutine foo

f90-beginning-of-subprogram jumps past the line containing 'subroutine
foo()'. A similar example could be written for f90-end-of-subprogram. I
propose to put a small check of whether the previous line ended with an
ampersand into the F90 major mode source file:

--- f90.el    2015-02-07 16:50:56.210519581 +0200
+++ f90_new.el    2015-02-07 16:56:44.997174743 +0200
@@ -1619,6 +1619,14 @@
                 (looking-at "[ \t0-9]*\\(!\\|$\\|#\\)")))
     not-last-statement))

+(defsubst f90-test-string-continuation ()
+  "Return true if the the current is a string continuation."
+  (save-excursion
+    (beginning-of-line)
+    (backward-char)
+    (skip-chars-backward " ")
+    (string= (string (char-before)) "&")))
+
 (defun f90-beginning-of-subprogram ()
   "Move point to the beginning of the current subprogram.
 Return (TYPE NAME), or nil if not found."
@@ -1629,9 +1637,13 @@
                 (re-search-backward f90-program-block-re nil 'move))
       (beginning-of-line)
       (skip-chars-forward " \t0-9")
-      (cond ((setq matching-beg (f90-looking-at-program-block-start))
+      (cond ((and
+          (setq matching-beg (f90-looking-at-program-block-start))
+          (not (f90-test-string-continuation)))
              (setq count (1- count)))
-            ((f90-looking-at-program-block-end)
+            ((and
+          (f90-looking-at-program-block-end)
+          (not (f90-test-string-continuation)))
              (setq count (1+ count)))))
     (beginning-of-line)
     (if (zerop count)
@@ -1654,9 +1666,13 @@
                 (re-search-forward f90-program-block-re nil 'move))
       (beginning-of-line)
       (skip-chars-forward " \t0-9")
-      (cond ((f90-looking-at-program-block-start)
+      (cond ((and
+          (f90-looking-at-program-block-start)
+          (not (f90-test-string-continuation)))
              (setq count (1+ count)))
-            ((setq matching-end (f90-looking-at-program-block-end))
+            ((and
+          (setq matching-end (f90-looking-at-program-block-end))
+          (not (f90-test-string-continuation)))
              (setq count (1- count))))
       (end-of-line))
     ;; This means f90-end-of-subprogram followed by f90-start-of-subprogram


Best wishes,
Raul Laasner

-- 
Raul Laasner
Institute of Physics
University of Tartu
Ravila 14c, 50411, Estonia
e-mail: raullaasner@gmail.com
cell: (+372)5182268

[-- Attachment #2: Type: text/html, Size: 3495 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#19809: 24.4; f90-beginning-of-subprogram wrong behavior with string continuation
  2015-02-07 20:25 bug#19809: 24.4; f90-beginning-of-subprogram wrong behavior with string continuation Raul Laasner
@ 2015-02-11  1:27 ` Glenn Morris
  2015-02-11  9:53   ` Raul Laasner
  0 siblings, 1 reply; 6+ messages in thread
From: Glenn Morris @ 2015-02-11  1:27 UTC (permalink / raw)
  To: Raul Laasner; +Cc: 19809

Raul Laasner wrote:

> The functions f90-beginning-of-subprogram and f90-end-of-subprogram do not
> work correctly if the source file contains lines which begin with the
> correct keywords but in fact belong to a continued string. For instance, in
> the following,
>
> subroutine foo()
>   print*, '&
>        end subroutine foo'
>   ! The cursor is here
> end subroutine foo

But that's not valid Fortran? Continued strings must use '&' at the
start of the continued lines as well? Eg gfortran 4.8.2 says:

    Warning: Missing '&' in continued character constant at (1)

Ie, you must write
  
   subroutine foo()
     print*, '&
          &end subroutine foo'
   end subroutine foo

in which case there isn't a problem.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#19809: 24.4; f90-beginning-of-subprogram wrong behavior with string continuation
  2015-02-11  1:27 ` Glenn Morris
@ 2015-02-11  9:53   ` Raul Laasner
  2015-02-11 19:09     ` Glenn Morris
  0 siblings, 1 reply; 6+ messages in thread
From: Raul Laasner @ 2015-02-11  9:53 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 19809

[-- Attachment #1: Type: text/plain, Size: 1711 bytes --]

I don't think the standard requires the second '&', although it is
recommended. Moreover, GFortran permits its omission and so in practice
people sometimes write such code. In any case, I have realized that the
proposed modification leads to new problems because in principle one could
also have

  subroutine foo
    ! &
  end subroutine foo

or something as weird as

  subroutine foo
    ; &
  end subroutine foo

and it's probably not worth the effort to account for such unlikely cases.
If the function is used mainly interactively then it's immediately clear
anyway if it fails due to unusual coding style. (On a different subject, it
also fails if the subprogram ends with a bare 'end' not followed by a
keyword, also allowed by the standard.)


On Wed, Feb 11, 2015 at 3:27 AM, Glenn Morris <rgm@gnu.org> wrote:

> Raul Laasner wrote:
>
> > The functions f90-beginning-of-subprogram and f90-end-of-subprogram do
> not
> > work correctly if the source file contains lines which begin with the
> > correct keywords but in fact belong to a continued string. For instance,
> in
> > the following,
> >
> > subroutine foo()
> >   print*, '&
> >        end subroutine foo'
> >   ! The cursor is here
> > end subroutine foo
>
> But that's not valid Fortran? Continued strings must use '&' at the
> start of the continued lines as well? Eg gfortran 4.8.2 says:
>
>     Warning: Missing '&' in continued character constant at (1)
>
> Ie, you must write
>
>    subroutine foo()
>      print*, '&
>           &end subroutine foo'
>    end subroutine foo
>
> in which case there isn't a problem.
>



-- 
Raul Laasner
Institute of Physics
University of Tartu
Ravila 14c, 50411, Estonia
e-mail: raullaasner@gmail.com

[-- Attachment #2: Type: text/html, Size: 2526 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#19809: 24.4; f90-beginning-of-subprogram wrong behavior with string continuation
  2015-02-11  9:53   ` Raul Laasner
@ 2015-02-11 19:09     ` Glenn Morris
  2015-02-11 19:33       ` Raul Laasner
  0 siblings, 1 reply; 6+ messages in thread
From: Glenn Morris @ 2015-02-11 19:09 UTC (permalink / raw)
  To: Raul Laasner; +Cc: 19809

Raul Laasner wrote:

> I don't think the standard requires the second '&', although it is
> recommended.

By my reading, it does require it.
Quoting from FCD 1539-1:
    
    3.3.2.4 Free form statement continuation:
    
    [...]
    
    If a character context is to be continued, an "&" shall be the last
    nonblank character on the line and shall not be followed by commentary.
    There shall be a later line that is not a comment; an "&" shall be the
    first nonblank character on the next such line and the statement
    continues with the next character following that "&".

Maybe it has changed in newer version of the standard.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#19809: 24.4; f90-beginning-of-subprogram wrong behavior with string continuation
  2015-02-11 19:09     ` Glenn Morris
@ 2015-02-11 19:33       ` Raul Laasner
  2015-02-24  7:18         ` Glenn Morris
  0 siblings, 1 reply; 6+ messages in thread
From: Raul Laasner @ 2015-02-11 19:33 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 19809

[-- Attachment #1: Type: text/plain, Size: 958 bytes --]

I stand corrected. Indeed, what I said before only applies to a
noncharacter context.

On Wed, Feb 11, 2015 at 9:09 PM, Glenn Morris <rgm@gnu.org> wrote:

> Raul Laasner wrote:
>
> > I don't think the standard requires the second '&', although it is
> > recommended.
>
> By my reading, it does require it.
> Quoting from FCD 1539-1:
>
>     3.3.2.4 Free form statement continuation:
>
>     [...]
>
>     If a character context is to be continued, an "&" shall be the last
>     nonblank character on the line and shall not be followed by commentary.
>     There shall be a later line that is not a comment; an "&" shall be the
>     first nonblank character on the next such line and the statement
>     continues with the next character following that "&".
>
> Maybe it has changed in newer version of the standard.
>



-- 
Raul Laasner
Institute of Physics
University of Tartu
Ravila 14c, 50411, Estonia
e-mail: raullaasner@gmail.com
cell: (+372)5182268

[-- Attachment #2: Type: text/html, Size: 1560 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#19809: 24.4; f90-beginning-of-subprogram wrong behavior with string continuation
  2015-02-11 19:33       ` Raul Laasner
@ 2015-02-24  7:18         ` Glenn Morris
  0 siblings, 0 replies; 6+ messages in thread
From: Glenn Morris @ 2015-02-24  7:18 UTC (permalink / raw)
  To: 19809-done

Version: 25.1

I added some support for this in e8a11db, but I suspect there are more
places where f90.el assumes strings are not continued in that way. It
doesn't seem especially important to me to track them all down.





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-02-24  7:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-07 20:25 bug#19809: 24.4; f90-beginning-of-subprogram wrong behavior with string continuation Raul Laasner
2015-02-11  1:27 ` Glenn Morris
2015-02-11  9:53   ` Raul Laasner
2015-02-11 19:09     ` Glenn Morris
2015-02-11 19:33       ` Raul Laasner
2015-02-24  7:18         ` Glenn Morris

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).