Tweak to the pretty type parser to recognize that -> is a special token.

Tweak to the pretty type parser to recognize that `->` is a special token that
shouldn't be split into two characters.  This change allows dialect
types to wrap function types as in `!my.ptr_type<(i32) -> i32>`.

Closes #105

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/105 from schweitzpgi:parse-arrow 8b2d768053f419daae5a1a864121a44c4319acbe
PiperOrigin-RevId: 265986240
This commit is contained in:
Eric Schweitz 2019-08-28 13:55:11 -07:00 committed by TensorFlower Gardener
parent 92fbb834c5
commit fee62e2186
2 changed files with 13 additions and 0 deletions

View File

@ -544,6 +544,13 @@ static bool isDialectSymbolSimpleEnoughForPrettyForm(StringRef symName) {
case '{':
nestedPunctuation.push_back(c);
continue;
case '-':
// Treat `->` as a special token.
if (!symName.empty() && symName.front() == '>') {
symName = symName.drop_front();
continue;
}
break;
// Reject types with mismatched brackets.
case '>':
if (nestedPunctuation.pop_back_val() != '<')

View File

@ -379,6 +379,12 @@ ParseResult Parser::parsePrettyDialectSymbolName(StringRef &prettyName) {
nestedPunctuation.push_back(c);
continue;
case '-':
// The sequence `->` is treated as special token.
if (*curPtr == '>')
++curPtr;
continue;
case '>':
if (nestedPunctuation.pop_back_val() != '<')
return emitError("unbalanced '>' character in pretty dialect name");