[Mlir-commits] [mlir] Add AsmParser::parseDecimalInteger. (PR #96255)

Jacques Pienaar llvmlistbot at llvm.org
Mon Jul 1 07:56:08 PDT 2024


================
@@ -308,6 +309,51 @@ OptionalParseResult Parser::parseOptionalInteger(APInt &result) {
   return success();
 }
 
+namespace {
+bool isBinOrHexOrOctIndicator(char c) {
+  return (llvm::toLower(c) == 'x' || llvm::toLower(c) == 'b' ||
+          llvm::isDigit(c));
+}
+} // namespace
+
+/// Parse an optional integer value only in decimal format from the stream.
+OptionalParseResult Parser::parseOptionalDecimalInteger(APInt &result) {
+  Token curToken = getToken();
+  if (curToken.isNot(Token::integer, Token::minus)) {
+    return std::nullopt;
+  }
+
+  bool negative = consumeIf(Token::minus);
+  Token curTok = getToken();
+  if (parseToken(Token::integer, "expected integer value")) {
+    return failure();
+  }
+
+  StringRef spelling = curTok.getSpelling();
+  // If the integer is in bin, hex, or oct format, return only the 0 and reset
+  // the lex pointer.
----------------
jpienaar wrote:

Could you expand this to explain the resetPointer below? (it follows if one looks at the implementation of the lexer, but in isolation here not so much)

https://github.com/llvm/llvm-project/pull/96255


More information about the Mlir-commits mailing list