forked from OSchip/llvm-project
[mlir] Add plus, star and optional less/greater parsing
The tokens are already handled by the lexer. This revision exposes them through the parser interface. This revision also adds missing functions for question mark parsing and completes the list of valid punctuation tokens in the documentation. Differential Revision: https://reviews.llvm.org/D90907
This commit is contained in:
parent
b9d36540a8
commit
e47805c995
|
@ -768,7 +768,7 @@ A literal is either a keyword or punctuation surrounded by \`\`.
|
||||||
|
|
||||||
The following are the set of valid punctuation:
|
The following are the set of valid punctuation:
|
||||||
|
|
||||||
`:`, `,`, `=`, `<`, `>`, `(`, `)`, `{`, `}`, `[`, `]`, `->`
|
`:`, `,`, `=`, `<`, `>`, `(`, `)`, `{`, `}`, `[`, `]`, `->`, `?`, `+`, `*`
|
||||||
|
|
||||||
#### Variables
|
#### Variables
|
||||||
|
|
||||||
|
|
|
@ -326,9 +326,33 @@ public:
|
||||||
/// Parse a '<' token.
|
/// Parse a '<' token.
|
||||||
virtual ParseResult parseLess() = 0;
|
virtual ParseResult parseLess() = 0;
|
||||||
|
|
||||||
|
/// Parse a '<' token if present.
|
||||||
|
virtual ParseResult parseOptionalLess() = 0;
|
||||||
|
|
||||||
/// Parse a '>' token.
|
/// Parse a '>' token.
|
||||||
virtual ParseResult parseGreater() = 0;
|
virtual ParseResult parseGreater() = 0;
|
||||||
|
|
||||||
|
/// Parse a '>' token if present.
|
||||||
|
virtual ParseResult parseOptionalGreater() = 0;
|
||||||
|
|
||||||
|
/// Parse a '?' token.
|
||||||
|
virtual ParseResult parseQuestion() = 0;
|
||||||
|
|
||||||
|
/// Parse a '?' token if present.
|
||||||
|
virtual ParseResult parseOptionalQuestion() = 0;
|
||||||
|
|
||||||
|
/// Parse a '+' token.
|
||||||
|
virtual ParseResult parsePlus() = 0;
|
||||||
|
|
||||||
|
/// Parse a '+' token if present.
|
||||||
|
virtual ParseResult parseOptionalPlus() = 0;
|
||||||
|
|
||||||
|
/// Parse a '*' token.
|
||||||
|
virtual ParseResult parseStar() = 0;
|
||||||
|
|
||||||
|
/// Parse a '*' token if present.
|
||||||
|
virtual ParseResult parseOptionalStar() = 0;
|
||||||
|
|
||||||
/// Parse a given keyword.
|
/// Parse a given keyword.
|
||||||
ParseResult parseKeyword(StringRef keyword, const Twine &msg = "") {
|
ParseResult parseKeyword(StringRef keyword, const Twine &msg = "") {
|
||||||
auto loc = getCurrentLocation();
|
auto loc = getCurrentLocation();
|
||||||
|
@ -369,9 +393,6 @@ public:
|
||||||
/// Parse a `)` token if present.
|
/// Parse a `)` token if present.
|
||||||
virtual ParseResult parseOptionalRParen() = 0;
|
virtual ParseResult parseOptionalRParen() = 0;
|
||||||
|
|
||||||
/// Parses a '?' if present.
|
|
||||||
virtual ParseResult parseOptionalQuestion() = 0;
|
|
||||||
|
|
||||||
/// Parse a `[` token.
|
/// Parse a `[` token.
|
||||||
virtual ParseResult parseLSquare() = 0;
|
virtual ParseResult parseLSquare() = 0;
|
||||||
|
|
||||||
|
|
|
@ -994,11 +994,21 @@ public:
|
||||||
return parser.parseToken(Token::less, "expected '<'");
|
return parser.parseToken(Token::less, "expected '<'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Parse a '<' token if present.
|
||||||
|
ParseResult parseOptionalLess() override {
|
||||||
|
return success(parser.consumeIf(Token::less));
|
||||||
|
}
|
||||||
|
|
||||||
/// Parse a '>' token.
|
/// Parse a '>' token.
|
||||||
ParseResult parseGreater() override {
|
ParseResult parseGreater() override {
|
||||||
return parser.parseToken(Token::greater, "expected '>'");
|
return parser.parseToken(Token::greater, "expected '>'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Parse a '>' token if present.
|
||||||
|
ParseResult parseOptionalGreater() override {
|
||||||
|
return success(parser.consumeIf(Token::greater));
|
||||||
|
}
|
||||||
|
|
||||||
/// Parse a `(` token.
|
/// Parse a `(` token.
|
||||||
ParseResult parseLParen() override {
|
ParseResult parseLParen() override {
|
||||||
return parser.parseToken(Token::l_paren, "expected '('");
|
return parser.parseToken(Token::l_paren, "expected '('");
|
||||||
|
@ -1019,11 +1029,6 @@ public:
|
||||||
return success(parser.consumeIf(Token::r_paren));
|
return success(parser.consumeIf(Token::r_paren));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses a '?' if present.
|
|
||||||
ParseResult parseOptionalQuestion() override {
|
|
||||||
return success(parser.consumeIf(Token::question));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parse a `[` token.
|
/// Parse a `[` token.
|
||||||
ParseResult parseLSquare() override {
|
ParseResult parseLSquare() override {
|
||||||
return parser.parseToken(Token::l_square, "expected '['");
|
return parser.parseToken(Token::l_square, "expected '['");
|
||||||
|
@ -1044,6 +1049,36 @@ public:
|
||||||
return success(parser.consumeIf(Token::r_square));
|
return success(parser.consumeIf(Token::r_square));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Parses a '?' token.
|
||||||
|
ParseResult parseQuestion() override {
|
||||||
|
return parser.parseToken(Token::question, "expected '?'");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parses a '?' token if present.
|
||||||
|
ParseResult parseOptionalQuestion() override {
|
||||||
|
return success(parser.consumeIf(Token::question));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parses a '+' token.
|
||||||
|
ParseResult parsePlus() override {
|
||||||
|
return parser.parseToken(Token::plus, "expected '+'");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parses a '+' token if present.
|
||||||
|
ParseResult parseOptionalPlus() override {
|
||||||
|
return success(parser.consumeIf(Token::plus));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parses a '*' token.
|
||||||
|
ParseResult parseStar() override {
|
||||||
|
return parser.parseToken(Token::star, "expected '*'");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parses a '*' token if present.
|
||||||
|
ParseResult parseOptionalStar() override {
|
||||||
|
return success(parser.consumeIf(Token::star));
|
||||||
|
}
|
||||||
|
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
// Attribute Parsing
|
// Attribute Parsing
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
|
|
|
@ -1380,7 +1380,7 @@ def AsmDialectInterfaceOp : TEST_Op<"asm_dialect_interface_op"> {
|
||||||
|
|
||||||
def FormatLiteralOp : TEST_Op<"format_literal_op"> {
|
def FormatLiteralOp : TEST_Op<"format_literal_op"> {
|
||||||
let assemblyFormat = [{
|
let assemblyFormat = [{
|
||||||
`keyword_$.` `->` `:` `,` `=` `<` `>` `(` `)` `[` `]` `` `(` ` ` `)` attr-dict
|
`keyword_$.` `->` `:` `,` `=` `<` `>` `(` `)` `[` `]` `` `(` ` ` `)` `?` `+` `*` attr-dict
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -309,7 +309,7 @@ def LiteralInvalidB : TestFormat_Op<"literal_invalid_b", [{
|
||||||
}]>;
|
}]>;
|
||||||
// CHECK-NOT: error
|
// CHECK-NOT: error
|
||||||
def LiteralValid : TestFormat_Op<"literal_valid", [{
|
def LiteralValid : TestFormat_Op<"literal_valid", [{
|
||||||
`_` `:` `,` `=` `<` `>` `(` `)` `[` `]` ` ` `` `->` `abc$._`
|
`_` `:` `,` `=` `<` `>` `(` `)` `[` `]` `?` `+` `*` ` ` `` `->` `abc$._`
|
||||||
attr-dict
|
attr-dict
|
||||||
}]>;
|
}]>;
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
// CHECK: %[[MEMREF:.*]] =
|
// CHECK: %[[MEMREF:.*]] =
|
||||||
%memref = "foo.op"() : () -> (memref<1xf64>)
|
%memref = "foo.op"() : () -> (memref<1xf64>)
|
||||||
|
|
||||||
// CHECK: test.format_literal_op keyword_$. -> :, = <> () []( ) {foo.some_attr}
|
// CHECK: test.format_literal_op keyword_$. -> :, = <> () []( ) ? + * {foo.some_attr}
|
||||||
test.format_literal_op keyword_$. -> :, = <> () []( ) {foo.some_attr}
|
test.format_literal_op keyword_$. -> :, = <> () []( ) ? + * {foo.some_attr}
|
||||||
|
|
||||||
// CHECK: test.format_attr_op 10
|
// CHECK: test.format_attr_op 10
|
||||||
// CHECK-NOT: {attr
|
// CHECK-NOT: {attr
|
||||||
|
|
|
@ -281,7 +281,7 @@ bool LiteralElement::isValidLiteral(StringRef value) {
|
||||||
// If there is only one character, this must either be punctuation or a
|
// If there is only one character, this must either be punctuation or a
|
||||||
// single character bare identifier.
|
// single character bare identifier.
|
||||||
if (value.size() == 1)
|
if (value.size() == 1)
|
||||||
return isalpha(front) || StringRef("_:,=<>()[]{}?").contains(front);
|
return isalpha(front) || StringRef("_:,=<>()[]{}?+*").contains(front);
|
||||||
|
|
||||||
// Check the punctuation that are larger than a single character.
|
// Check the punctuation that are larger than a single character.
|
||||||
if (value == "->")
|
if (value == "->")
|
||||||
|
@ -762,7 +762,9 @@ static void genLiteralParser(StringRef value, OpMethodBody &body) {
|
||||||
.Case(")", "RParen()")
|
.Case(")", "RParen()")
|
||||||
.Case("[", "LSquare()")
|
.Case("[", "LSquare()")
|
||||||
.Case("]", "RSquare()")
|
.Case("]", "RSquare()")
|
||||||
.Case("?", "Question()");
|
.Case("?", "Question()")
|
||||||
|
.Case("+", "Plus()")
|
||||||
|
.Case("*", "Star()");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate the storage code required for parsing the given element.
|
/// Generate the storage code required for parsing the given element.
|
||||||
|
|
Loading…
Reference in New Issue