HOME

TheInfoList



OR:

Bracket matching, also known as brace matching or parentheses matching, is a
syntax highlighting Syntax highlighting is a feature of text editors that are used for programming, scripting, or markup languages, such as HTML. The feature displays text, especially source code, in different colours and fonts according to the category of terms ...
feature of certain
text editor A text editor is a type of computer program that edits plain text. Such programs are sometimes known as "notepad" software (e.g. Windows Notepad). Text editors are provided with operating systems and software development packages, and can be us ...
s and
integrated development environment An integrated development environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of at least a source code editor, build automation tools a ...
s that highlights matching sets of
brackets A bracket is either of two tall fore- or back-facing punctuation marks commonly used to isolate a segment of text or data from its surroundings. Typically deployed in symmetric pairs, an individual bracket may be identified as a 'left' or 'r ...
(square brackets, curly brackets, or parentheses) in languages such as
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
,
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
, and
C++ C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
that use them. The purpose is to help the programmer navigate through the code and also spot any improper matching, which would cause the program to not compile or malfunction. If a closing bracket is left out, for instance, the compiler will not know that the end of a block of code has been reached. Bracket matching is particularly useful when many nested ''if'' statements,
program loop In computer science, control flow (or flow of control) is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated. The emphasis on explicit control flow distinguishes an ''im ...
s, etc. are involved.


Implementations

Vim's % command does bracket matching, and
NetBeans NetBeans is an integrated development environment (IDE) for Java (programming language), Java. NetBeans allows applications to be developed from a set of modular software components called ''modules''. NetBeans runs on Microsoft Windows, Windows, ...
has bracket matching built-in. Bracket matching can also be a tool for code navigation. In
Visual Studio Visual Studio is an integrated development environment (IDE) from Microsoft. It is used to develop computer programs including web site, websites, web apps, web services and mobile apps. Visual Studio uses Microsoft software development platfor ...
C++ 6.0, bracket matching behavior was set to ignore brackets found in comments. In VSC 7.0, its behavior was changed to compute commented brackets. IntelliJ IDEA's
Ruby on Rails Ruby on Rails (simplified as Rails) is a server-side web application framework written in Ruby under the MIT License. Rails is a model–view–controller (MVC) framework, providing default structures for a database, a web service, and web p ...
plugin also enables bracket matching. It has been proposed that
Perl Perl is a family of two high-level, general-purpose, interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the latter's name was offici ...
5 be modified to facilitate bracket matching.Brace-matching for Perl Regular Expressions - perl6
/ref> The Microsoft Excel 2003 formula bar has parentheses matching. Its implementation shows all the pairs of parentheses as different colors, so it is possible to easily analyze them all at once.


Example

In this example, the user has just typed the closing curly brace '}' defining a code block, and that brace and its corresponding opening brace are both highlighted. for (int i = 0; i < 10; i++)


References

{{compsci-stub User interface techniques Text editor features pt:Realce de sintaxe#Parênteses correspondentes