diff --git a/mlir/lib/Tools/PDLL/Parser/Parser.cpp b/mlir/lib/Tools/PDLL/Parser/Parser.cpp index 9ce4cb30fb2b9a..1dc3b8694c11a7 100644 --- a/mlir/lib/Tools/PDLL/Parser/Parser.cpp +++ b/mlir/lib/Tools/PDLL/Parser/Parser.cpp @@ -326,6 +326,7 @@ class Parser { FailureOr parseMemberAccessExpr(ast::Expr *parentExpr); FailureOr parseNegatedExpr(); FailureOr parseIntegerExpr(); + FailureOr parseStringExpr(); FailureOr parseOperationName(bool allowEmptyName = false); FailureOr parseWrappedOperationName(bool allowEmptyName); FailureOr @@ -1838,6 +1839,9 @@ FailureOr Parser::parseExpr() { case Token::integer: lhsExpr = parseIntegerExpr(); break; + case Token::string: + lhsExpr = parseStringExpr(); + break; case Token::string_block: return emitError("expected expression. If you are trying to create an " "ArrayAttr, use a space between `[` and `{`."); @@ -2100,6 +2104,13 @@ FailureOr Parser::parseIntegerExpr() { return ast::AttributeExpr::create(ctx, loc, allocated); } +FailureOr Parser::parseStringExpr() { + SMRange loc = curToken.getLoc(); + StringRef value = curToken.getSpelling(); + consumeToken(); + return ast::AttributeExpr::create(ctx, loc, value); +} + FailureOr Parser::parseOperationName(bool allowEmptyName) { SMRange loc = curToken.getLoc(); diff --git a/mlir/test/mlir-pdll/Parser/expr.pdll b/mlir/test/mlir-pdll/Parser/expr.pdll index 0ad283c7446f33..42db134a31d5ff 100644 --- a/mlir/test/mlir-pdll/Parser/expr.pdll +++ b/mlir/test/mlir-pdll/Parser/expr.pdll @@ -23,6 +23,15 @@ Pattern { // ----- +// CHECK: Module +// CHECK: `-AttributeExpr {{.*}} Value<""value""> +Pattern { + let attr = "value"; + erase _: Op; +} + +// ----- + // CHECK: |-NamedAttributeDecl {{.*}} Name // CHECK: `-UserRewriteDecl {{.*}} Name ResultType // CHECK: `Arguments`