[PATCH] D95743: [flang] Fix parsing of WRITE(I+J) with more accurate look-ahead

Peter Klausler via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 30 10:13:00 PST 2021


klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
klausler requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The parsing of I/O units uses look-ahead to discriminate between
keywords, variables and expressions as part of distinguishing internal
from external I/O.  The look-ahead was inaccurate for variables that
appear as the initial parts of expressions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95743

Files:
  flang/lib/Parser/Fortran-parsers.cpp
  flang/lib/Parser/io-parsers.cpp


Index: flang/lib/Parser/io-parsers.cpp
===================================================================
--- flang/lib/Parser/io-parsers.cpp
+++ flang/lib/Parser/io-parsers.cpp
@@ -24,7 +24,7 @@
 // R905 char-variable -> variable
 // "char-variable" is attempted first since it's not type constrained but
 // syntactically ambiguous with "file-unit-number", which is constrained.
-TYPE_PARSER(construct<IoUnit>(variable / !"="_tok) ||
+TYPE_PARSER(construct<IoUnit>(variable / lookAhead(space / ",);\n"_ch)) ||
     construct<IoUnit>(fileUnitNumber) || construct<IoUnit>(star))
 
 // R1202 file-unit-number -> scalar-int-expr
Index: flang/lib/Parser/Fortran-parsers.cpp
===================================================================
--- flang/lib/Parser/Fortran-parsers.cpp
+++ flang/lib/Parser/Fortran-parsers.cpp
@@ -1084,7 +1084,8 @@
 // R924 image-selector ->
 //        lbracket cosubscript-list [, image-selector-spec-list] rbracket
 TYPE_CONTEXT_PARSER("image selector"_en_US,
-    construct<ImageSelector>("[" >> nonemptyList(cosubscript / !"="_tok),
+    construct<ImageSelector>(
+        "[" >> nonemptyList(cosubscript / lookAhead(space / ",]"_ch)),
         defaulted("," >> nonemptyList(Parser<ImageSelectorSpec>{})) / "]"))
 
 // R926 image-selector-spec ->


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95743.320311.patch
Type: text/x-patch
Size: 1280 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210130/b45c87e7/attachment.bin>


More information about the llvm-commits mailing list