42 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8//9// Bracket structure (particularly braces) is key to isolating broken regions10// of code and preventing parsing from going "off the rails".11//12// For correct C++ code, brackets are well-nested and identifying pairs and13// 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.15//16// Rather than have the grammar-based parser make these choices, we pair17// brackets up-front based on textual features like indentation.18// This mirrors the way humans read code, and so is likely to produce the19// "correct" interpretation of broken code.20//21// This interpretation then guides the parse: a rule containing a bracket pair22// must match against paired bracket tokens.23//24//===----------------------------------------------------------------------===//25 26#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_BRACKET_H27#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_BRACKET_H28 29#include "Token.h"30 31namespace clang {32namespace clangd {33 34/// Identifies bracket token in the stream which should be paired.35/// Sets Token::Pair accordingly.36void pairBrackets(TokenStream &);37 38} // namespace clangd39} // namespace clang40 41#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_BRACKET_H42