Merge pull request #59641 from hamishknight/no-skip-slash

This commit is contained in:
Hamish Knight
2022-06-23 15:09:26 +01:00
committed by GitHub
9 changed files with 472 additions and 93 deletions

View File

@@ -180,7 +180,7 @@ class Lexer {
/// Retrieve the underlying diagnostic engine we emit diagnostics to. Note
/// this should only be used for diagnostics not concerned with the current
/// token.
DiagnosticEngine *getUnderlyingDiags() {
DiagnosticEngine *getUnderlyingDiags() const {
return DiagQueue ? &DiagQueue->getUnderlyingDiags() : nullptr;
}
@@ -218,7 +218,10 @@ public:
/// \param Parent the parent lexer that scans the whole buffer
/// \param BeginState start of the subrange
/// \param EndState end of the subrange
Lexer(Lexer &Parent, State BeginState, State EndState);
/// \param EnableDiagnostics Whether to inherit the diagnostic engine of
/// \p Parent. If \c false, diagnostics will be disabled.
Lexer(const Lexer &Parent, State BeginState, State EndState,
bool EnableDiagnostics = true);
/// Returns true if this lexer will produce a code completion token.
bool isCodeCompletion() const {
@@ -577,6 +580,13 @@ public:
: LexerForwardSlashRegexMode::Tentative) {}
};
/// Checks whether a given token could potentially contain the start of an
/// unskippable `/.../` regex literal. Such tokens need to go through the
/// parser, as they may become regex literal tokens. This includes operator
/// tokens such as `!/` which could be split into prefix `!` on a regex
/// literal.
bool isPotentialUnskippableBareSlashRegexLiteral(const Token &Tok) const;
private:
/// Nul character meaning kind.
enum class NulCharacterKind {
@@ -641,6 +651,12 @@ private:
void lexStringLiteral(unsigned CustomDelimiterLen = 0);
void lexEscapedIdentifier();
/// Attempt to scan a regex literal, returning the end pointer, or `nullptr`
/// if a regex literal cannot be scanned.
const char *tryScanRegexLiteral(const char *TokStart, bool MustBeRegex,
DiagnosticEngine *Diags,
bool &CompletelyErroneous) const;
/// Attempt to lex a regex literal, returning true if lexing should continue,
/// false if this is not a regex literal.
bool tryLexRegexLiteral(const char *TokStart);

View File

@@ -718,13 +718,6 @@ public:
/// plain Tok.is(T1) check).
bool skipUntilTokenOrEndOfLine(tok T1, tok T2 = tok::NUM_TOKENS);
/// Skip a braced block (e.g. function body). The current token must be '{'.
/// Returns \c true if the parser hit the eof before finding matched '}'.
///
/// Set \c HasNestedTypeDeclarations to true if a token for a type
/// declaration is detected in the skipped block.
bool skipBracedBlock(bool &HasNestedTypeDeclarations);
/// Skip over SIL decls until we encounter the start of a Swift decl or eof.
void skipSILUntilSwiftDecl();
@@ -1001,6 +994,8 @@ public:
bool canDelayMemberDeclParsing(bool &HasOperatorDeclarations,
bool &HasNestedClassDeclarations);
bool canDelayFunctionBodyParsing(bool &HasNestedTypeDeclarations);
bool delayParsingDeclList(SourceLoc LBLoc, SourceLoc &RBLoc,
IterableDeclContext *IDC);
@@ -1211,9 +1206,7 @@ public:
bool &hasEffectfulGet,
AccessorKind currentKind,
SourceLoc const& currentLoc);
void consumeAbstractFunctionBody(AbstractFunctionDecl *AFD,
const DeclAttributes &Attrs);
ParserResult<FuncDecl> parseDeclFunc(SourceLoc StaticLoc,
StaticSpellingKind StaticSpelling,
ParseDeclOptions Flags,