| 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". |
| 11 |
// |
| 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. |
| 15 |
// |
| 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. |
| 20 |
// |
| 21 |
// This interpretation then guides the parse: a rule containing a bracket pair |
| 22 |
// must match against paired bracket tokens. |
| 23 |
// |
| 24 |
//===----------------------------------------------------------------------===// |
| 25 |
|
| 26 |
#ifndef CLANG_PSEUDO_BRACKET_H |
| 27 |
#define CLANG_PSEUDO_BRACKET_H |
| 28 |
|
| 29 |
#include "clang-pseudo/Token.h" |
| 30 |
|
| 31 |
namespace clang { |
| 32 |
namespace pseudo { |
| 33 |
|
| 34 |
/// Identifies bracket token in the stream which should be paired. |
| 35 |
/// Sets Token::Pair accordingly. |
| 36 |
void pairBrackets(TokenStream &); |
| 37 |
|
| 38 |
} // namespace pseudo |
| 39 |
} // namespace clang |
| 40 |
|
| 41 |
#endif |