9 #ifndef MLIR_LIB_PARSER_TOKEN_H
10 #define MLIR_LIB_PARSER_TOKEN_H
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Support/SMLoc.h"
23 #define TOK_MARKER(NAME) NAME,
24 #define TOK_IDENTIFIER(NAME) NAME,
25 #define TOK_LITERAL(NAME) NAME,
26 #define TOK_PUNCTUATION(NAME, SPELLING) NAME,
27 #define TOK_KEYWORD(SPELLING) kw_##SPELLING,
28 #include "TokenKinds.def"
31 Token(
Kind kind, StringRef spelling) : kind(kind), spelling(spelling) {}
38 bool is(
Kind k)
const {
return kind == k; }
43 template <
typename... T>
47 return isAny(k2, k3, others...);
53 template <
typename... T>
55 return !
isAny(k1, k2, others...);
This represents a token in the MLIR syntax.
bool isCodeCompletionFor(Kind kind) const
Returns true if the current token represents a code completion for the "normal" token type.
SMRange getLocRange() const
bool isKeyword() const
Return true if this is one of the keyword token kinds (e.g. kw_if).
static StringRef getTokenSpelling(Kind kind)
Given a punctuation or keyword token kind, return the spelling of the token as a string.
bool isAny(Kind k1, Kind k2, Kind k3, T... others) const
Return true if this token is one of the specified kinds.
bool isNot(Kind k1, Kind k2, T... others) const
Return true if this token isn't one of the specified kinds.
std::string getStringValue() const
Given a token containing a string literal, return its value, including removing the quote characters ...
std::string getSymbolReference() const
Given a token containing a symbol reference, return the unescaped string value.
std::optional< unsigned > getUnsignedIntegerValue() const
For an integer token, return its value as an unsigned.
std::optional< uint64_t > getUInt64IntegerValue() const
std::optional< double > getFloatingPointValue() const
For a floatliteral token, return its value as a double.
Token(Kind kind, StringRef spelling)
bool isAny(Kind k1, Kind k2) const
std::optional< unsigned > getHashIdentifierNumber() const
Given a hash_identifier token like #123, try to parse the number out of the identifier,...
bool isCodeCompletion() const
Returns true if the current token represents a code completion.
StringRef getSpelling() const
std::optional< bool > getIntTypeSignedness() const
For an inttype token, return its signedness semantics: std::nullopt means no signedness semantics; tr...
bool isOrIsCodeCompletionFor(Kind kind) const
Returns true if the current token is the given type, or represents a code completion for that type.
std::optional< unsigned > getIntTypeBitwidth() const
For an inttype token, return its bitwidth.
std::optional< std::string > getHexStringValue() const
Given a token containing a hex string literal, return its value or std::nullopt if the token does not...
Include the generated interface declarations.