[flang] Allow $ and @ in defined operator names.
authorpeter klausler <pklausler@nvidia.com>
Tue, 1 May 2018 21:59:10 +0000 (14:59 -0700)
committerpeter klausler <pklausler@nvidia.com>
Fri, 4 May 2018 16:35:03 +0000 (09:35 -0700)
Original-commit: flang-compiler/f18@3cf7533a3bfe35b5dcb4396f35339ee34d34c272
Reviewed-on: https://github.com/flang-compiler/f18/pull/81
Tree-same-pre-rewrite: false

flang/lib/parser/grammar.h
flang/lib/parser/token-parsers.h

index 562d845..600d993 100644 (file)
@@ -1345,15 +1345,6 @@ TYPE_PARSER(construct<CharLiteralConstantSubstring>(
 TYPE_PARSER(construct<SubstringRange>(
     maybe(scalarIntExpr), ":" >> maybe(scalarIntExpr)))
 
-// R1003 defined-unary-op -> . letter [letter]... .
-// R1023 defined-binary-op -> . letter [letter]... .
-// R1414 local-defined-operator -> defined-unary-op | defined-binary-op
-// R1415 use-defined-operator -> defined-unary-op | defined-binary-op
-// N.B. The name of the operator is captured without the periods around it.
-TYPE_PARSER(space >> "."_ch >>
-    construct<DefinedOpName>(sourced(some(letter) >> construct<Name>())) /
-        "."_ch)
-
 // R911 data-ref -> part-ref [% part-ref]...
 // R914 coindexed-named-object -> data-ref
 // R917 array-element -> data-ref
index 5b65135..160e88e 100644 (file)
@@ -647,8 +647,19 @@ constexpr auto underscore = "_"_ch;
 constexpr auto otherIdChar = underscore / !"'\""_ch || extension("$@"_ch);
 constexpr auto nonDigitIdChar = letter || otherIdChar;
 constexpr auto rawName = nonDigitIdChar >> many(nonDigitIdChar || digit);
-TYPE_PARSER(space >> sourced(attempt(rawName) >> construct<Name>()))
+TYPE_PARSER(space >> sourced(rawName >> construct<Name>()))
 constexpr auto keyword = construct<Keyword>(name);
 
+// R1003 defined-unary-op -> . letter [letter]... .
+// R1023 defined-binary-op -> . letter [letter]... .
+// R1414 local-defined-operator -> defined-unary-op | defined-binary-op
+// R1415 use-defined-operator -> defined-unary-op | defined-binary-op
+// N.B. The name of the operator is captured without the periods around it.
+constexpr auto definedOpNameChar = letter || extension("$@"_ch);
+TYPE_PARSER(space >> "."_ch >>
+    construct<DefinedOpName>(
+        sourced(some(definedOpNameChar) >> construct<Name>())) /
+        "."_ch)
+
 }  // namespace Fortran::parser
 #endif  // FORTRAN_PARSER_TOKEN_PARSERS_H_