Brace matching

Last updated

Brace matching, also known as bracket matching or parentheses matching, is a syntax highlighting feature of certain text editors and integrated development environments that highlights matching sets of braces (square brackets, curly brackets, or parentheses) in languages such as Java and C++ 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 brace is left out, for instance, the compiler will not know that the end of a block of code has been reached. Brace matching is particularly useful when many nested if statements, program loops, etc. are involved.

Syntax highlighting Tool of editors for programming, scripting and markup

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 colors and fonts according to the category of terms. This feature facilitates writing in a structured language such as a programming language or a markup language as both structures and syntax errors are visually distinct. Highlighting does not affect the meaning of the text itself; it is intended only for human readers.

Text editor software to modify text documents

A text editor is a type of computer program that edits plain text. Such programs are sometimes known as "notepad" software, following the naming of Microsoft Notepad. Text editors are provided with operating systems and software development packages, and can be used to change files such as configuration files, documentation files and programming language source code.

Integrated development environment software application used to develop software

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, and a debugger. Some IDEs, such as NetBeans and Eclipse, contain the necessary compiler, interpreter, or both; others, such as SharpDevelop and Lazarus, do not. IDEs are sometimes called Program Development Environments (PDEs).

Contents

Implementations

Vim's % command does brace matching, [1] and NetBeans has brace matching built-in. [2] Brace matching can also be a tool for code navigation. In Visual Studio [3] C++ 6.0, brace matching behavior was set to ignore braces found in comments. In VSC 7.0, its behavior was changed to compute commented braces. [4] IntelliJ IDEA's Ruby on Rails plugin also enables braces matching. [5] It has been proposed that Perl 5 be modified to facilitate braces matching. [6] 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.

Vim (text editor) Improved version of the Vi keyboard-oriented text editor

Vim is a clone, with additions, of Bill Joy's vi text editor program for Unix. Vim's author, Bram Moolenaar, based it upon the source code for a port of the Stevie editor to the Amiga and released a version to the public in 1991. Vim is designed for use both from a command-line interface and as a standalone application in a graphical user interface. Vim is free and open-source software and is released under a license that includes some charityware clauses, encouraging users who enjoy the software to consider donating to children in Uganda. The license is compatible with the GNU General Public License through a special clause allowing distribution of modified copies "under the GNU GPL version 2 or any later version".

NetBeans An Integrated development environment software for software development.

NetBeans is an integrated development environment (IDE) for Java. NetBeans allows applications to be developed from a set of modular software components called modules. NetBeans runs on Windows, macOS, Linux and Solaris. In addition to Java development, it has extensions for other languages like PHP, C, C++, HTML5, and JavaScript. Applications based on NetBeans, including the NetBeans IDE, can be extended by third party developers.

Ruby on Rails open source web application framework

Ruby on Rails, or 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 pages. It encourages and facilitates the use of web standards such as JSON or XML for data transfer, HTML, CSS and JavaScript for user interfacing. In addition to MVC, Rails emphasizes the use of other well-known software engineering patterns and paradigms, including convention over configuration (CoC), don't repeat yourself (DRY), and the active record pattern.

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++) {     System.out.println(i); }

Related Research Articles

Regular expression Sequence of characters that forms a search pattern

A regular expression, regex or regexp is a sequence of characters that define a search pattern. Usually such patterns are used by string searching algorithms for "find" or "find and replace" operations on strings, or for input validation. It is a technique developed in theoretical computer science and formal language theory.

Ruby is an interpreted, high-level, general-purpose programming language. It was designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan.

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 right bracket or, alternatively, an opening paired bracket or closing paired bracket, respectively, depending on the directionality of the context.

In computer science, lexical analysis, lexing or tokenization is the process of converting a sequence of characters into a sequence of tokens. A program that performs lexical analysis may be termed a lexer, tokenizer, or scanner, though scanner is also a term for the first stage of a lexer. A lexer is generally combined with a parser, which together analyze the syntax of programming languages, web pages, and so forth.

Programming style, also known as code style, is a set of rules or guidelines used when writing the source code for a computer program. It is often claimed that following a particular programming style will help programmers read and understand source code conforming to the style, and help to avoid introducing errors.

A string literal or anonymous string is a type of literal in programming for the representation of a string value within the source code of a computer program. Most often in modern languages this is a quoted sequence of characters, as in x = "foo", where "foo" is a string literal with value foo – the quotes are not part of the value, and one must use a method such as escape sequences to avoid the problem of delimiter collision and allow the delimiters themselves to be embedded in a string. However, there are numerous alternate notations for specifying string literals, particularly more complicated cases, and the exact notation depends on the individual programming language in question. Nevertheless, there are some general guidelines that most modern programming languages follow.

In computer programming, an indentation style is a convention governing the indentation of blocks of code to convey program structure. This article largely addresses the free-form languages, such as C and its descendants, but can be applied to most other programming languages, where whitespace is otherwise insignificant. Indentation style is only one aspect of programming style.

In computer programming, a free-form language is a programming language in which the positioning of characters on the page in program text is insignificant. Program text does not need to be placed in specific columns as on old punched card systems, and frequently ends of lines are insignificant. Whitespace characters are used only to delimit tokens, and have no other significance.

Delimiter Characters that specify the boundary between regions in a data stream

A delimiter is a sequence of one or more characters for specifying the boundary between separate, independent regions in plain text or other data streams. An example of a delimiter is the comma character, which acts as a field delimiter in a sequence of comma-separated values. Another example of a delimiter is the time gap used to separate letters and words in the transmission of Morse code.

A computer programming language is said to adhere to the off-side rule if blocks in that language are expressed by their indentation. The term was coined by Peter J. Landin, after the offside rule in football. This is contrasted with free-form languages, notably curly-bracket programming languages, where indentation is not meaningful and indent style is only a matter of convention and code formatting.

IntelliJ IDEA integrated development environment

IntelliJ IDEA is a Java integrated development environment (IDE) for developing computer software. It is developed by JetBrains, and is available as an Apache 2 Licensed community edition, and in a proprietary commercial edition. Both can be used for commercial development.

Notepad2 open-source text editor for Microsoft Windows

Notepad2 is a free and open-source text editor for Microsoft Windows, released under a BSD software license. It was written by Florian Balmer using the Scintilla editor component, and it was first publicly released in April 2004. Balmer based Notepad2 on the principles of Notepad: small, fast, and usable.

This comparison of programming languages compares the features of language syntax (format) for over 50 computer programming languages.

Coding conventions are a set of guidelines for a specific programming language that recommend programming style, practices, and methods for each aspect of a program written in that language. These conventions usually cover file organization, indentation, comments, declarations, statements, white space, naming conventions, programming practices, programming principles, programming rules of thumb, architectural best practices, etc. These are guidelines for software structural quality. Software programmers are highly recommended to follow these guidelines to help improve the readability of their source code and make software maintenance easier. Coding conventions are only applicable to the human maintainers and peer reviewers of a software project. Conventions may be formalized in a documented set of rules that an entire team or company follows, or may be as informal as the habitual coding practices of an individual. Coding conventions are not enforced by compilers.

Comment (computer programming) a programmer-readable explanation or annotation in the source code of a computer program

In computer programming, a comment is a programmer-readable explanation or annotation in the source code of a computer program. They are added with the purpose of making the source code easier for humans to understand, and are generally ignored by compilers and interpreters. The syntax of comments in various programming languages varies considerably.

CoffeeScript is a programming language that compiles to JavaScript. It adds syntactic sugar inspired by Ruby, Python and Haskell in an effort to enhance JavaScript's brevity and readability. Specific additional features include list comprehension and destructuring assignment.

JetBrains Czech software company

JetBrains s.r.o. is a software development company whose tools are targeted towards software developers and project managers.

References

  1. Norm Matloff's Text-Editor Web Page for Programming Students
  2. "Overview (Editor Braces Matching)". Archived from the original on 2012-05-25. Retrieved 2008-03-09.
  3. Automatic Brace Matching in Visual Studio
  4. Feedback: braces matching behavior
  5. "IntelliJ IDEA supports Ruby and Ruby on Rails | AjaxLine". Archived from the original on 2010-09-22. Retrieved 2008-03-09.
  6. Brace-matching for Perl Regular Expressions - perl6