#ifndef LLVM_CLANG_LIB_FORMAT_FORMATTOKENLEXER_H
#define LLVM_CLANG_LIB_FORMAT_FORMATTOKENLEXER_H
#include "Encoding.h"
#include "FormatToken.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/StringSet.h"
#include <stack>
namespace clang {
namespace format {
enum LexerState {
NORMAL,
TEMPLATE_STRING,
TOKEN_STASHED,
};
class FormatTokenLexer {
public:
FormatTokenLexer(const SourceManager &SourceMgr, FileID ID, unsigned Column,
const FormatStyle &Style, encoding::Encoding Encoding,
llvm::SpecificBumpPtrAllocator<FormatToken> &Allocator,
IdentifierTable &IdentTable);
ArrayRef<FormatToken *> lex();
const AdditionalKeywords &getKeywords() { return Keywords; }
private:
void tryMergePreviousTokens();
bool tryMergeLessLess();
bool tryMergeGreaterGreater();
bool tryMergeNSStringLiteral();
bool tryMergeJSPrivateIdentifier();
bool tryMergeCSharpStringLiteral();
bool tryMergeCSharpKeywordVariables();
bool tryMergeNullishCoalescingEqual();
bool tryTransformCSharpForEach();
bool tryMergeForEach();
bool tryTransformTryUsageForC();
bool tryMergeTokens(ArrayRef<tok::TokenKind> Kinds, TokenType NewType);
bool tryMergeTokens(size_t Count, TokenType NewType);
bool tryMergeTokensAny(ArrayRef<ArrayRef<tok::TokenKind>> Kinds,
TokenType NewType);
bool precedesOperand(FormatToken *Tok);
bool canPrecedeRegexLiteral(FormatToken *Prev);
void tryParseJSRegexLiteral();
void handleTemplateStrings();
void handleCSharpVerbatimAndInterpolatedStrings();
void handleTableGenMultilineString();
void handleTableGenNumericLikeIdentifier();
void tryParsePythonComment();
bool tryMerge_TMacro();
bool tryMergeConflictMarkers();
void truncateToken(size_t NewLen);
FormatToken *getStashedToken();
FormatToken *getNextToken();
FormatToken *FormatTok;
bool IsFirstToken;
std::stack<LexerState> StateStack;
unsigned Column;
unsigned TrailingWhitespace;
std::unique_ptr<Lexer> Lex;
LangOptions LangOpts;
const SourceManager &SourceMgr;
FileID ID;
const FormatStyle &Style;
IdentifierTable &IdentTable;
AdditionalKeywords Keywords;
encoding::Encoding Encoding;
llvm::SpecificBumpPtrAllocator<FormatToken> &Allocator;
unsigned FirstInLineIndex;
SmallVector<FormatToken *, 16> Tokens;
llvm::SmallMapVector<IdentifierInfo *, TokenType, 8> Macros;
llvm::SmallPtrSet<IdentifierInfo *, 8> TypeNames;
bool FormattingDisabled;
llvm::Regex MacroBlockBeginRegex;
llvm::Regex MacroBlockEndRegex;
static const llvm::StringSet<> CSharpAttributeTargets;
bool readRawTokenVerilogSpecific(Token &Tok);
void readRawToken(FormatToken &Tok);
void resetLexer(unsigned Offset);
};
}
}
#endif