[flang-commits] [PATCH] D120747: [flang] Extension: don't require commas between most edit descriptors in formats

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Tue Mar 1 09:58:01 PST 2022


klausler created this revision.
klausler added a reviewer: vdonaldson.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
klausler requested review of this revision.

The standard explicitly allows a comma to be omitted between a 'P'
edit descriptor and a following numeric edit descriptor (e.g., 1PE10.1),
and before and after a '/' edit descriptor, but otherwise requires them
between edit descriptors.  Most implementations, however, only require
commas where they prevent ambiguity, and accept things like 1XI10.
This extension is already assumed by the static FORMAT checker in
semantics.  Patch the runtime to behave accordingly.


https://reviews.llvm.org/D120747

Files:
  flang/docs/Extensions.md
  flang/runtime/format-implementation.h


Index: flang/runtime/format-implementation.h
===================================================================
--- flang/runtime/format-implementation.h
+++ flang/runtime/format-implementation.h
@@ -301,8 +301,14 @@
       if (ch != 'P') { // 1PE5.2 - comma not required (C1302)
         CharType peek{Capitalize(PeekNext())};
         if (peek >= 'A' && peek <= 'Z') {
-          next = peek;
-          ++offset_;
+          if (ch == 'A' /* anticipate F'202X AT editing */ || ch == 'B' ||
+              ch == 'D' || ch == 'E' || ch == 'R' || ch == 'S' || ch == 'T') {
+            // Assume a two-letter edit descriptor
+            next = peek;
+            ++offset_;
+          } else {
+            // extension: assume a comma between 'ch' and 'peek'
+          }
         }
       }
       if ((!next &&
Index: flang/docs/Extensions.md
===================================================================
--- flang/docs/Extensions.md
+++ flang/docs/Extensions.md
@@ -217,6 +217,8 @@
 * At runtime, `NAMELIST` input will skip over `NAMELIST` groups
   with other names, and will treat text before and between groups
   as if they were comment lines, even if not begun with `!`.
+* Commas are required in FORMAT statements and character variables
+  only when they prevent ambiguity.
 
 ### Extensions supported when enabled by options
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120747.412147.patch
Type: text/x-patch
Size: 1347 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220301/582874dc/attachment-0001.bin>


More information about the flang-commits mailing list