[Reland][Runtimes] Merge 'compile_commands.json' files from runtimes build (#116303)
[llvm-project.git] / clang-tools-extra / clangd / support / Bracket.h
blobb43c22cea06d0638788e335e08a8200a89949b3c
1 //===--- Bracket.h - Analyze bracket structure --------------------*-C++-*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Bracket structure (particularly braces) is key to isolating broken regions
10 // of code and preventing parsing from going "off the rails".
12 // For correct C++ code, brackets are well-nested and identifying pairs and
13 // therefore blocks is simple. In broken code, brackets are not properly nested.
14 // We cannot match them all and must choose which pairs to form.
16 // Rather than have the grammar-based parser make these choices, we pair
17 // brackets up-front based on textual features like indentation.
18 // This mirrors the way humans read code, and so is likely to produce the
19 // "correct" interpretation of broken code.
21 // This interpretation then guides the parse: a rule containing a bracket pair
22 // must match against paired bracket tokens.
24 //===----------------------------------------------------------------------===//
26 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_BRACKET_H
27 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_BRACKET_H
29 #include "Token.h"
31 namespace clang {
32 namespace clangd {
34 /// Identifies bracket token in the stream which should be paired.
35 /// Sets Token::Pair accordingly.
36 void pairBrackets(TokenStream &);
38 } // namespace clangd
39 } // namespace clang
41 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_BRACKET_H