@@ -412,15 +412,32 @@ ParseResult Parser::parseOptionalKeyword(StringRef *keyword) {
412412 return success ();
413413}
414414
415+ ParseResult Parser::parseOptionalKeywordOrString (std::string *result) {
416+ StringRef keyword;
417+ if (succeeded (parseOptionalKeyword (&keyword))) {
418+ *result = keyword.str ();
419+ return success ();
420+ }
421+
422+ // Parse a quoted string token if present.
423+ if (!getToken ().is (Token::string))
424+ return failure ();
425+
426+ if (result)
427+ *result = getToken ().getStringValue ();
428+ consumeToken ();
429+ return success ();
430+ }
431+
415432// ===----------------------------------------------------------------------===//
416433// Resource Parsing
417434
418435FailureOr<AsmDialectResourceHandle>
419436Parser::parseResourceHandle (const OpAsmDialectInterface *dialect,
420- StringRef &name) {
437+ std::string &name) {
421438 assert (dialect && " expected valid dialect interface" );
422439 SMLoc nameLoc = getToken ().getLoc ();
423- if (failed (parseOptionalKeyword (&name)))
440+ if (failed (parseOptionalKeywordOrString (&name)))
424441 return emitError (" expected identifier key for 'resource' entry" );
425442 auto &resources = getState ().symbols .dialectResources ;
426443
@@ -451,7 +468,7 @@ Parser::parseResourceHandle(Dialect *dialect) {
451468 return emitError () << " dialect '" << dialect->getNamespace ()
452469 << " ' does not expect resource handles" ;
453470 }
454- StringRef resourceName;
471+ std::string resourceName;
455472 return parseResourceHandle (interface, resourceName);
456473}
457474
@@ -2530,8 +2547,8 @@ class TopLevelOperationParser : public Parser {
25302547// / textual format.
25312548class ParsedResourceEntry : public AsmParsedResourceEntry {
25322549public:
2533- ParsedResourceEntry (StringRef key, SMLoc keyLoc, Token value, Parser &p)
2534- : key(key), keyLoc(keyLoc), value(value), p(p) {}
2550+ ParsedResourceEntry (std::string key, SMLoc keyLoc, Token value, Parser &p)
2551+ : key(std::move( key) ), keyLoc(keyLoc), value(value), p(p) {}
25352552 ~ParsedResourceEntry () override = default ;
25362553
25372554 StringRef getKey () const final { return key; }
@@ -2607,7 +2624,7 @@ class ParsedResourceEntry : public AsmParsedResourceEntry {
26072624 }
26082625
26092626private:
2610- StringRef key;
2627+ std::string key;
26112628 SMLoc keyLoc;
26122629 Token value;
26132630 Parser &p;
@@ -2736,7 +2753,7 @@ ParseResult TopLevelOperationParser::parseDialectResourceFileMetadata() {
27362753 return parseCommaSeparatedListUntil (Token::r_brace, [&]() -> ParseResult {
27372754 // Parse the name of the resource entry.
27382755 SMLoc keyLoc = getToken ().getLoc ();
2739- StringRef key;
2756+ std::string key;
27402757 if (failed (parseResourceHandle (handler, key)) ||
27412758 parseToken (Token::colon, " expected ':'" ))
27422759 return failure ();
@@ -2763,8 +2780,8 @@ ParseResult TopLevelOperationParser::parseExternalResourceFileMetadata() {
27632780 return parseCommaSeparatedListUntil (Token::r_brace, [&]() -> ParseResult {
27642781 // Parse the name of the resource entry.
27652782 SMLoc keyLoc = getToken ().getLoc ();
2766- StringRef key;
2767- if (failed (parseOptionalKeyword (&key)))
2783+ std::string key;
2784+ if (failed (parseOptionalKeywordOrString (&key)))
27682785 return emitError (
27692786 " expected identifier key for 'external_resources' entry" );
27702787 if (parseToken (Token::colon, " expected ':'" ))
0 commit comments